This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//#pragma pack(1)
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define int long long
#define pii pair<int,int>
#define x first
#define y second
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset;
//typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set;
int q,l;
set<pii>ant,cube;
int count(){
vector<pii>a,c;
for (auto i:ant)
a.push_back(i);
for (auto i:cube)
c.push_back(i);
int p=0,ans=0;
for (auto i:c){
while (p<a.size()&&(i.x-a[p].x>l||a[p].y==0)){
p++;
}
pii now=i;
while (p<a.size()&&now.y>0&&a[p].x-now.x<=l){
int take=min(now.y,a[p].y);
ans+=take;
a[p].y-=take;
now.y-=take;
if (a[p].y==0) p++;
}
}
return ans;
}
signed main(){
fast
cin>>q>>l;
for (int i=1;i<=q;i++){
int t,x,a; cin>>t>>x>>a;
if (t==1){
ant.insert({x,a});
}
else {
cube.insert({x,a});
}
cout<<count()<<'\n';
}
}
Compilation message (stderr)
sugar.cpp: In function 'long long int count()':
sugar.cpp:26:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | while (p<a.size()&&(i.x-a[p].x>l||a[p].y==0)){
| ~^~~~~~~~~
sugar.cpp:30:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | while (p<a.size()&&now.y>0&&a[p].x-now.x<=l){
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |