Submission #673785

#TimeUsernameProblemLanguageResultExecution timeMemory
673785BaytoroMonkey and Apple-trees (IZhO12_apple)C++17
100 / 100
497 ms188568 KiB
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second //#define int long long #define endl '\n' void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const int INF=1e18,mod=998244353; int n,m,k; const int N=123456; struct node{ int sum,lazy,lx,rx,l,r; node(): sum(0),lazy(0),l(-1),r(-1) {} } st[64*N]; int cnt=2; void push(int x){ int md=(st[x].rx+st[x].lx)/2; if(st[x].l==-1){ st[x].l=cnt++; st[st[x].l].lx=st[x].lx; st[st[x].l].rx=md; } if(st[x].r==-1){ st[x].r=cnt++; st[st[x].r].lx=md+1; st[st[x].r].rx=st[x].rx; } if(st[x].lazy){ st[x].sum=st[x].rx-st[x].lx+1; st[st[x].l].lazy=st[st[x].r].lazy=1; st[x].lazy=0; } } void update(int x, int l, int r){ push(x); if(l==st[x].lx && r==st[x].rx){ st[x].lazy=1; push(x); return; } int md=(st[x].lx+st[x].rx)/2; if(l>md) update(st[x].r,l,r); else if(r<=md) update(st[x].l,l,r); else{ update(st[x].l,l,md); update(st[x].r,md+1,r); } push(st[x].l); push(st[x].r); st[x].sum=st[st[x].l].sum+st[st[x].r].sum; } int query(int x, int l, int r){ push(x); if(l==st[x].lx && r==st[x].rx) return st[x].sum; int md=(st[x].lx+st[x].rx)/2; if(l>md) return query(st[x].r,l,r); else if(r<=md) return query(st[x].l,l,r); else return query(st[x].l,l,md)+query(st[x].r,md+1,r); } void solve(){ int m; cin>>m; int c=0; st[1].sum=0,st[1].lazy=0; st[1].lx=1,st[1].rx=2e9; for(int i=0;i<m;i++){ int d, x, y; cin>>d>>x>>y; if(d==1){ c=query(1,x+c,y+c); cout<<c<<endl; } else{ update(1,x+c,y+c); } } } main(){ //fopn("newbarn"); //ios; int T=1; //cin>>T; while(T--){ solve(); } } /* 3 2 1 1000000000 1 1 1000000000 1 1 1000000000 */

Compilation message (stderr)

apple.cpp:15:15: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   15 | const int INF=1e18,mod=998244353;
      |               ^~~~
apple.cpp:91:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   91 | main(){
      | ^~~~
apple.cpp: In function 'void fopn(std::string)':
apple.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...