Submission #375055

#TimeUsernameProblemLanguageResultExecution timeMemory
375055daniel920712Examination (JOI19_examination)C++14
41 / 100
1567 ms443468 KiB
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <vector> using namespace std; struct A { int l,r; int nxl,nxr,nxt; int sum; }Node[400*100005]; int ans[1000005]; vector < pair < pair < int , int > , int > > query[5][200005]; int now=1; void New(int l,int r,int t,int here) { Node[here].l=l; Node[here].r=r; Node[here].sum=0; Node[here].nxl=-1; Node[here].nxr=-1; Node[here].nxt=t; } void cha(int x,int y,int here) { Node[here].sum++; if(Node[here].nxt==-2) { if(y==Node[here].l&&y==Node[here].r) return; if(y<=(Node[here].l+Node[here].r)/2) { if(Node[here].nxl==-1) { Node[here].nxl=now++; New(Node[here].l,(Node[here].l+Node[here].r)/2,-2,Node[here].nxl); } cha(x,y,Node[here].nxl); } else { if(Node[here].nxr==-1) { Node[here].nxr=now++; New((Node[here].l+Node[here].r)/2+1,Node[here].r,-2,Node[here].nxr); } cha(x,y,Node[here].nxr); } } else { if(Node[here].nxt==-1) { Node[here].nxt=now++; New(0,200000,-2,Node[here].nxt); } cha(x,y,Node[here].nxt); if(x==Node[here].l&&x==Node[here].r) return; else if(x<=(Node[here].l+Node[here].r)/2) { if(Node[here].nxl==-1) { Node[here].nxl=now++; New(Node[here].l,(Node[here].l+Node[here].r)/2,-1,Node[here].nxl); } cha(x,y,Node[here].nxl); } else { if(Node[here].nxr==-1) { Node[here].nxr=now++; New((Node[here].l+Node[here].r)/2+1,Node[here].r,-1,Node[here].nxr); } cha(x,y,Node[here].nxr); } } } int Find(int l1,int r1,int l2,int r2,int here) { if(here==-1) return 0; if(Node[here].nxt==-2) { if(l2==Node[here].l&&r2==Node[here].r) return Node[here].sum; if(r2<=(Node[here].l+Node[here].r)/2) return Find(l1,r1,l2,r2,Node[here].nxl); else if(l2>(Node[here].l+Node[here].r)/2) return Find(l1,r1,l2,r2,Node[here].nxr); else return Find(l1,r1,l2,(Node[here].l+Node[here].r)/2,Node[here].nxl)+Find(l1,r1,(Node[here].l+Node[here].r)/2+1,r2,Node[here].nxr); } else { if(l1==Node[here].l&&r1==Node[here].r) return Find(l1,r1,l2,r2,Node[here].nxt); if(r1<=(Node[here].l+Node[here].r)/2) return Find(l1,r1,l2,r2,Node[here].nxl); else if(l1>(Node[here].l+Node[here].r)/2) return Find(l1,r1,l2,r2,Node[here].nxr); else return Find(l1,(Node[here].l+Node[here].r)/2,l2,r2,Node[here].nxl)+Find((Node[here].l+Node[here].r)/2+1,r1,l2,r2,Node[here].nxr); } } int main() { int N,M,i,j,x,y,z; scanf("%d %d",&N,&M); for(i=0;i<N;i++) { scanf("%d %d",&x,&y); query[0][x].push_back(make_pair(make_pair(y,0),0)); } for(i=0;i<M;i++) { scanf("%d %d %d",&x,&y,&z); query[1][x].push_back(make_pair(make_pair(y,z),i)); } New(0,200000,-1,0); for(i=100000;i>=0;i--) { for(auto j:query[0][i]) cha(j.first.first,i+j.first.first,0); for(auto j:query[1][i]) ans[j.second]=Find(j.first.first,200000,j.first.second,200000,0); } for(i=0;i<M;i++) printf("%d\n",ans[i]); return 0; }

Compilation message (stderr)

examination.cpp: In function 'int main()':
examination.cpp:101:15: warning: unused variable 'j' [-Wunused-variable]
  101 |     int N,M,i,j,x,y,z;
      |               ^
examination.cpp:102:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  102 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
examination.cpp:105:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  105 |         scanf("%d %d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~~
examination.cpp:110:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  110 |         scanf("%d %d %d",&x,&y,&z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...