Submission #1208415

#TimeUsernameProblemLanguageResultExecution timeMemory
1208415siewjhAnts and Sugar (JOI22_sugar)C++20
6 / 100
4093 ms7920 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int queries, rnge; cin >> queries >> rnge;
	map<ll, ll> am, sm;
	for (int i = 0; i < queries; i++){
		ll op, loc, amt; cin >> op >> loc >> amt;
		(op == 1 ? am : sm)[loc] += amt;
		auto it = sm.begin();
		ll ans = 0, tak = 0;
		for (auto [x, a] : am){
			while (it != sm.end() && it->first < x - rnge){
				it++; tak = 0;
			}
			if (it == sm.end()) break;
			while (it != sm.end() && it->first <= x + rnge){
				if (a <= it->second - tak){
					ans += a; tak += a; break;
				}
				else{
					ans += it->second - tak; a -= it->second - tak;
					it++; tak = 0;
				}
			}
		}
		cout << ans << '\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...