Submission #168071

#TimeUsernameProblemLanguageResultExecution timeMemory
168071GioChkhaidzeMonkey and Apple-trees (IZhO12_apple)C++14
100 / 100
537 ms165496 KiB
#include <bits/stdc++.h> #define Tree int &h,int l,int r #define Left v[h][1],l,(l+r)/2 #define Right v[h][2],(l+r)/2+1,r using namespace std; const int N=5000006; int nodes=1,n,L,R,ANS,Root,type; int v[2*N][5]; inline void Shift(int h,int l,int r) { if (!v[h][4]) return ; v[h][0]=r-l+1; if (l!=r) { if (!v[h][1]) v[h][1]=++nodes; if (!v[h][2]) v[h][2]=++nodes; v[v[h][1]][4]=1,v[v[h][2]][4]=1; } v[h][4]=0; } inline int Get (Tree) { if (!h) h=++nodes; Shift(h,l,r); if (r<L || R<l) return 0; if (L<=l && r<=R) return v[h][0]; return Get(Left)+Get(Right); } inline void Upd (Tree) { if (!h) h=++nodes; Shift(h,l,r); if (r<L || R<l) return ; if (L<=l && r<=R) { v[h][4]=1; Shift(h,l,r); return ; } Upd(Left),Upd(Right); v[h][0]=v[v[h][1]][0]+v[v[h][2]][0]; } main () { scanf("%d",&n); for (int i=1; i<=n; i++) { scanf("%d %d %d",&type,&L,&R); L+=ANS,R+=ANS,Root=1; if (type==1) { ANS=Get(Root,1,1e9); printf("%d\n",ANS); } else Upd(Root,1,1e9); } }

Compilation message (stderr)

apple.cpp:37:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {  
       ^
apple.cpp: In function 'int main()':
apple.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
apple.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&type,&L,&R);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...