# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1010649 | tarpent | Trading (IZhO13_trading) | C++14 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3000007;
#define ll long long
ll n,m,k,a,b,c;
pair<ll,ll> val[maxn];
priority_queue<pair<ll,ll>> vre;
int main(){
cin>>n>>m;
for(int i = 0; i<m; i++){
cin>>a>>b>>c;
if(val[a].first==0) val[a]={b,c};
else{
while(true){
if(val[a].first!=0){
if(val[a].second<c){
int tr = val[a].first;
int tpc = val[a].second;
val[a] = {b,c};
a=b+1;
b=tr;
c=tpc;
}
else{
if(val[a].first<b){
c+=val[a].first+1-1;
a=val[a].first+1;
}
else break;
}
}
else{
val[a]={b,c};
break;
}
}
}
}
pair<ll,ll> tre;
for(int i = 1; i<n+1; i++){
bool ch = false;
if(!vre.empty()){
tre=vre.top();
vre.pop();
vre.push({tre.first+1,tre.second});
}
if(val[i].second!=0){
vre.push({val[i].second,i});
}
while(val[vre.top().second].first<i && !vre.empty()){
vre.pop();
ch=true;
}
if(ch && !vre.empty()){
tre=vre.top();
vre.pop();
vre.push({tre.first+(i-tre.second),tre.second});
}
if (!vre.empty()) cout<<vre.top().first<<' ';
else cout<<0<<' ';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |