結果

問題 No.3284 Picnic with Friends
ユーザー hos.lyric
提出日時 2025-09-26 21:55:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,459 ms / 7,000 ms
コード長 2,584 bytes
コンパイル時間 1,191 ms
コンパイル使用メモリ 118,984 KB
実行使用メモリ 17,712 KB
最終ジャッジ日時 2025-09-26 21:55:40
合計ジャッジ時間 33,810 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:47:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |     for (int n = 0; n < N; ++n) scanf("%lld", &S[n]);
      |                                 ~~~~~^~~~~~~~~~~~~~~
main.cpp:48:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |     scanf("%d", &Q);
      |     ~~~~~^~~~~~~~~~
main.cpp:51:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |     for (int q = 0; q < Q; ++q) scanf("%lld%lld", &T[q], &F[q]);
      |                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


int N;
vector<Int> S;
int Q;
vector<Int> T, F;

int main() {
  for (; ~scanf("%d", &N); ) {
    S.resize(N);
    for (int n = 0; n < N; ++n) scanf("%lld", &S[n]);
    scanf("%d", &Q);
    T.resize(Q);
    F.resize(Q);
    for (int q = 0; q < Q; ++q) scanf("%lld%lld", &T[q], &F[q]);
    
    vector<pair<Int, Int>> ps;
    for (int q = 0; q < Q; ++q) {
      if (ps.size() && ps.back().second >= T[q]) {
        ps.back().second += F[q];
      } else {
        ps.emplace_back(T[q], T[q] + F[q]);
      }
    }
// cerr<<"ps = "<<ps<<endl;
    
    auto ss = S;
    sort(ss.begin(), ss.end());
    ss.erase(unique(ss.begin(), ss.end()), ss.end());
    const int ssLen = ss.size();
// cerr<<"ss = "<<ss<<endl;
    vector<Int> fs(ssLen + 1, 0);
    for (const auto &p : ps) {
      const Int x = p.second - p.first;
      for (int l = 0, r; l < ssLen; l = r) {
        const Int y = x / ss[l];
        if (!y) break;
        r = upper_bound(ss.begin() + l, ss.end(), x / y) - ss.begin();
// cerr<<"x = "<<x<<", y = "<<y<<", [l, r) = ["<<l<<", "<<r<<")"<<endl;
        fs[l] += y;
        fs[r] -= y;
      }
    }
    for (int j = 0; j < ssLen; ++j) fs[j + 1] += fs[j];
    
    for (int n = 0; n < N; ++n) {
      const int j = lower_bound(ss.begin(), ss.end(), S[n]) - ss.begin();
      printf("%lld\n", fs[j]);
    }
  }
  return 0;
}
0