제출 #1349951

#제출 시각아이디문제언어결과실행 시간메모리
1349951avighnaAnts and Sugar (JOI22_sugar)C++20
0 / 100
4091 ms1764 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);

  int q, l;
  cin >> q >> l;

  map<int, int64_t> ants, sugar;

  auto solve = [&]() {
    auto _ants = ants, _sugar = sugar;
    int64_t ans = 0;
    for (auto &[x, num] : sugar) {
      for (auto it = ants.lower_bound(x); num > 0 && it != ants.end() && it->first - x <= l; it = ants.lower_bound(x)) {
        int64_t cur = min(num, it->second);
        it->second -= cur, num -= cur, ans += cur;
        if (it->second == 0) {
          ants.erase(it->first);
        }
      }
      for (auto it = ants.upper_bound(x); num > 0 && it != ants.begin() && x - prev(it)->first <= l; it = ants.upper_bound(x)) {
        --it;
        int64_t cur = min(num, it->second);
        it->second -= cur, num -= cur, ans += cur;
        if (it->second == 0) {
          ants.erase(it->first);
        }
      }
    }
    ants = _ants, sugar = _sugar;
    return ans;
  };

  while (q--) {
    int t, x, a;
    cin >> t >> x >> a;
    if (t == 1) {
      ants[x] += a;
    } else {
      sugar[x] += a;
    }
    cout << solve() << '\n';
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...