Submission #1230872

#TimeUsernameProblemLanguageResultExecution timeMemory
1230872vivkostovExamination (JOI19_examination)C++20
22 / 100
3014 ms614776 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 point { int st,ind; bool operator<(const point&a)const { if(st<a.st)return true; if(st>a.st)return false; return ind>a.ind; } }; struct cell { int l,r,in,st; }; int n,q,br=1,otg[100005]; stud a[100005]; query b[100005]; cell p[100000005]; void check(int h) { if(!p[h].l) { br++; p[h].l=br; br++; p[h].r=br; } } void update2(int l,int r,int q,int h) { if(l>q||r<q)return; if(l==r) { p[h].st++; return; } check(h); int mid=l/2+r/2+(l%2+r%2)/2; update2(l,mid,q,p[h].l); update2(mid+1,r,q,p[h].r); p[h].st=p[p[h].l].st+p[p[h].r].st; } void update1(int l,int r,int q,int h,int st) { if(l>q||r<q)return; if(!p[h].in) { br++; p[h].in=br; } check(h); update2(0,maxn,st,p[h].in); if(l==r)return; int mid=l/2+r/2+(l%2+r%2)/2; update1(l,mid,q,p[h].l,st); update1(mid+1,r,q,p[h].r,st); } int sum2(int l,int r,int ql,int qr,int h) { if(l>=ql&&r<=qr)return p[h].st; if(l>qr||r<ql||!p[h].l)return 0; int mid=l/2+r/2+(l%2+r%2)/2; return sum2(l,mid,ql,qr,p[h].l)+sum2(mid+1,r,ql,qr,p[h].r); } int sum1(int l,int r,int ql,int qr,int h,int st) { if(l>qr||r<ql||!p[h].l)return 0; if(l>=ql&&r<=qr)return sum2(0,maxn,st,maxn,p[h].in); int mid=l/2+r/2+(l%2+r%2)/2; return sum1(l,mid,ql,qr,p[h].l,st)+sum1(mid+1,r,ql,qr,p[h].r,st); } void resh() { int pos=1; for(int i=1;i<=n;i++) { while(pos<=n&&a[pos].a>=b[i].x) { update1(0,maxn/2,a[pos].b,1,a[pos].a+a[pos].b); pos++; } otg[b[i].ind]=sum1(0,maxn/2,b[i].y,maxn,1,b[i].z); } 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...