제출 #870950

#제출 시각아이디문제언어결과실행 시간메모리
870950HyojinMonkey and Apple-trees (IZhO12_apple)C++17
100 / 100
211 ms190288 KiB
#include <bits/stdc++.h> using namespace std; #define bit(n,i) ((n>>i)&1) #define all(a) (a).begin(),(a).end() #define pb push_back #define ep emplace_back #define pii pair<int,int> #define piii pair<int,pii> #define fi first #define se second #define ll long long #define debug(x) cerr << #x << ' ' << x << '\n' #define dbg(x) cerr<<#x<<' '<<x<<' ' const int base=31; const int MOD=1e9+7; const int N=1e5+5; struct segtree{ int idL,idR,sum,lazy; segtree():idL(0),idR(0),sum(0),lazy(0){} } st[N*4*30]; int cur; void update(int id,int x,int l,int r) { st[id].sum=r-l+1; st[id].lazy=x; } void down(int id,int l,int mid,int r) { if (st[id].idL==0) st[id].idL=++cur; if (st[id].idR==0) st[id].idR=++cur; if (st[id].lazy!=0) { update(st[id].idL,st[id].lazy,l,mid); update(st[id].idR,st[id].lazy,mid+1,r); st[id].lazy=0; } } void update(int id,int l,int r,int u,int v) { if (v<l||r<u) return; if (u<=l&&r<=v) { st[id].lazy++; st[id].sum=(r-l+1); return; } int mid=l+r>>1; down(id,l,mid,r); update(st[id].idL,l,mid,u,v); update(st[id].idR,mid+1,r,u,v); st[id].sum=st[st[id].idL].sum+st[st[id].idR].sum; } int get(int id,int l,int r,int u,int v) { if (u<=l&&r<=v) return st[id].sum; int mid=l+r>>1; down(id,l,mid,r); if (v<=mid) return get(st[id].idL,l,mid,u,v); if (mid+1<=u) return get(st[id].idR,mid+1,r,u,v); return get(st[id].idL,l,mid,u,v)+get(st[id].idR,mid+1,r,u,v); } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Shiho freopen("izumi_shiho_supremacy.in","r", stdin); freopen("izumi_shiho_supremacy.out","w", stdout); #endif cur=1; int q; cin>>q; int c=0; while (q--) { int type,u,v; cin>>type>>u>>v; if (type==1) { int x=get(1,1,1e9,u+c,v+c); c=x; cout<<x<<"\n"; } else { update(1,1,1e9,u+c,v+c); } } return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */

컴파일 시 표준 에러 (stderr) 메시지

apple.cpp: In function 'void update(int, int, int, int, int)':
apple.cpp:47:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |  int mid=l+r>>1;
      |          ~^~
apple.cpp: In function 'int get(int, int, int, int, int)':
apple.cpp:56:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |  int mid=l+r>>1;
      |          ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...