Submission #13115

#TimeUsernameProblemLanguageResultExecution timeMemory
13115dohyun0324Trading (IZhO13_trading)C++98
100 / 100
629 ms24088 KiB
#include<stdio.h> #include<algorithm> #include<set> #include<map> using namespace std; set<int>q; map<int,int>ch; int n,m; struct data{ int l,r,x; bool operator<(const data&r)const{ return l<r.l; } }a[300010]; struct data2{ int l,r,x; bool operator<(const data2&p)const{ return r<p.r; } }b[300010]; int main() { int i,j,p1=1,p2=1; set<int>::iterator p; scanf("%d %d",&n,&m); for(i=1;i<=m;i++) { scanf("%d %d %d",&a[i].l,&a[i].r,&a[i].x); b[i].l=a[i].l; b[i].r=a[i].r; b[i].x=a[i].x; } sort(a+1,a+m+1); sort(b+1,b+m+1); for(i=1;i<=n;i++){ for(j=p1;j<=m;j++){ if(a[j].l>i) break; ch[a[j].x-a[j].l]++; q.insert(a[j].x-a[j].l); } p1=j; for(j=p2;j<=m;j++){ if(b[j].r>=i) break; ch[b[j].x-b[j].l]--; if(ch[b[j].x-b[j].l]==0) q.erase(b[j].x-b[j].l); } p2=j; if(q.empty()){printf("0 "); continue;} p=q.end(); p--; printf("%d ",(*p)+i); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...