Submission #1231016

#TimeUsernameProblemLanguageResultExecution timeMemory
1231016vivkostovExamination (JOI19_examination)C++20
20 / 100
1400 ms431532 KiB
#include <bits/stdc++.h> #define endl '\n' using namespace std; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int maxn=1e9*2; struct stud { int a,b; }; bool cmp(stud a1,stud a2) { return a1.a>a2.a; } struct query { int x,y,z,ind; }; bool cmp2(query a1,query a2) { return a1.x>a2.x; } struct cell { int l,r,in; }; struct cell2 { int l,r,st; }; int n,q,br=1,otg[100005],mid,q1,q2,ot,now,now2; stud a[100005]; query b[100005]; cell p[50000005]; cell2 p2[100000005]; map<int,int>ma; void update2(int l,int r) { mid=l/2+r/2+(l%2+r%2)/2; p2[now].st++; if(mid>=q2) { if(r-l==1) { ma[l]++; return; } if(!p2[now].l) { br++; p2[now].l=br; } now=p2[now].l; update2(l,mid); } else { if(r-l<=2) { ma[r]++; return; } if(!p2[now].r) { br++; p2[now].r=br; } now=p2[now].r; update2(mid+1,r); } } void update1(int l,int r) { if(!p[now2].in) { br++; p[now2].in=br; } now=p[now2].in; update2(0,maxn); if(l==r)return; mid=l/2+r/2+(l%2+r%2)/2; if(mid>=q1) { if(!p[now2].l) { br++; p[now2].l=br; } now2=p[now2].l; update1(l,mid); } else { if(!p[now2].r) { br++; p[now2].r=br; } now2=p[now2].r; update1(mid+1,r); } } void sum2(int l,int r,int h) { if(l>=q2) { ot+=p2[h].st; return; } mid=l/2+r/2+(l%2+r%2)/2; if(r-l<=2) { ot+=ma[r]; if(r-l==1)return; } if(p2[h].r)sum2(mid+1,r,p2[h].r); mid=l/2+r/2+(l%2+r%2)/2; if(p2[h].l&&mid>=q2) { sum2(l,mid,p2[h].l); } } void sum1(int l,int r,int h) { if(!p[h].in)return; if(l>=q1) { sum2(0,maxn,p[h].in); return; } mid=l/2+r/2+(l%2+r%2)/2; if(p[h].r)sum1(mid+1,r,p[h].r); mid=l/2+r/2+(l%2+r%2)/2; if(p[h].l&&mid>=q1)sum1(l,mid,p[h].l); } void resh() { int pos=1; for(int i=1;i<=n;i++) { while(pos<=n&&a[pos].a>=b[i].x) { q1=a[pos].b; q2=a[pos].a+a[pos].b; now2=1; update1(0,maxn/2); pos++; } q1=b[i].y; q2=b[i].z; ot=0; sum1(0,maxn/2,1); otg[b[i].ind]=ot; } for(int i=1;i<=q;i++) { cout<<otg[i]<<endl; } } void read() { cin>>n>>q; for(int i=1;i<=n;i++) { cin>>a[i].a>>a[i].b; } for(int i=1;i<=q;i++) { cin>>b[i].x>>b[i].y>>b[i].z; b[i].ind=i; } sort(a+1,a+n+1,cmp); sort(b+1,b+q+1,cmp2); resh(); } int main() { speed(); read(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...