結果

問題 No.3284 Picnic with Friends
ユーザー areik
提出日時 2025-09-26 22:08:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,922 bytes
コンパイル時間 4,410 ms
コンパイル使用メモリ 259,956 KB
実行使用メモリ 814,528 KB
最終ジャッジ日時 2025-09-26 22:09:09
合計ジャッジ時間 10,008 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 MLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;

using isize = size_t;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
using f64 = long double;
using p2 = pair<i64, i64>;
using el = tuple<i64, i64, i64>;
using mint = atcoder::modint998244353;

void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  _main();
}

i64 pow(i64 x, i64 n) {
  i64 res = 1;
  i64 t = x;
  while (n > 0) {
    if (n & 1) res *= t;
    t *= t;
    n >>= 1;
  }
  return res;
}
i64 pow(i64 x, i64 n, i64 m) {
  i64 res = 1;
  i64 t = x % m;
  while (n > 0) {
    if (n & 1) res = res * t % m;
    t = t * t % m;
    n >>= 1;
  }
  return res;
}

void _main() {
  i64 n;
  cin >> n;
  vector<p2> s(n);
  for (i64 i = 0; i < n; i++) {
    cin >> s[i].first;
    s[i].second = i;
  }
  sort(s.begin(), s.end());
  i64 q;
  cin >> q;
  vector<i64> v;
  i64 now = 0, sum = 0;
  for (;q--;) {
    i64 t, f;
    cin >> t >> f;
    if (now >= t) now += f, sum += f;
    else {
      v.push_back(sum);
      now = t + f;
      sum = f;
    }
  }
  if (sum > 0) v.push_back(sum);
  vector<p2> p;
  for (i64 x : v) {
    i64 b, l;
    for (i64 i = 1; true; i++) {
      if (x / i < i) {
        b = x / i;
        l = i;
        break;
      }
      p.push_back({i, x / i});
      p.push_back({i + 1, -(x / i)});
    }
    for (i64 i = b; i >= 1; i--) {
      i64 l = x / (i + 1) + 1, r = x / i + 1;
      assert(x / l <= i);
      assert(x / r < i);
      p.push_back({l, i});
      p.push_back({r, -i});
    }
  }
  sort(p.begin(), p.end());
  i64 idx = 0;
  i64 ss = 0;
  vector<i64> ans(n, 0);
  for (auto [x, i] : s) {
    while (idx < p.size() && p[idx].first <= x) {
      ss += p[idx].second;
      idx++;
    }
    ans[i] = ss;
  }
  for (i64 x : ans) cout << x << "\n";
}
0