Submission #384120

#TimeUsernameProblemLanguageResultExecution timeMemory
384120i_am_noobBitaro, who Leaps through Time (JOI19_timeleap)C++17
100 / 100
832 ms76396 KiB
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma") #include<bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") using namespace std; #define ll long long #define int ll #define ull unsigned long long #define ld long double #define rep(a) rep1(i,a) #define rep1(i,a) rep2(i,0,a) #define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++) #define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--) #define all(a) a.begin(),a.end() #define pii pair<int,int> #define pb push_back //#define inf 1010000000 #define inf 4000000000000000000 #define eps 1e-9 #define sz(a) ((int)a.size()) #define pow2(x) (1ll<<(x)) #define ceiling(a,b) (((a)+(b)-1)/(b)) #ifdef i_am_noob #define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__) template<typename T> void _do(T && x) {cerr << x << endl;} template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);} #else #define bug(...) 826 #endif inline char readchar(){ const int maxn=1000000; static char buf[maxn],*p=buf,*q=buf; if(p==q&&(q=(p=buf)+fread(buf,1,maxn,stdin))==buf) return EOF; else return *p++; } inline int readint(){ int c=readchar(),x=0,neg=0; while((c<'0'||c>'9')&&c!='-'&&c!=EOF) c=readchar(); if(c=='-') neg=1,c=readchar(); while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^'0'),c=readchar(); return neg?-x:x; } const int Mod=1000000007,Mod2=998244353; const int MOD=Mod; const int maxn=300005; //i_am_noob int n,q,l[maxn],r[maxn]; #define event array<int,4> event Merge(event x, event y){ event res; res[0]=min(x[1],x[0]+max(0ll,y[0]-x[2])); res[1]=max(x[0],x[1]-max(0ll,x[2]+x[1]-x[0]-y[1])); res[2]=min(max(y[2]+x[2]-y[0],y[2]),y[2]+y[1]-y[0]); res[3]=x[3]+y[3]+max(0ll,x[2]-y[1]); return res; } struct segtree{ event val[4*maxn],e; void pull(int k){val[k]=Merge(val[k<<1],val[k<<1|1]);} void build(int k, int l, int r){ if(l==r){ val[k]=e; return; } int mid=l+r>>1; build(k<<1,l,mid),build(k<<1|1,mid+1,r); pull(k); } segtree(){ e={-inf,inf,-inf,0}; build(1,0,maxn-1); } void modify(int k, int l, int r, int p, event x){ if(l==r){ val[k]=x; return; } int mid=l+r>>1; if(p<=mid) modify(k<<1,l,mid,p,x); else modify(k<<1|1,mid+1,r,p,x); pull(k); } event query(int k, int l, int r, int ql, int qr){ if(ql>r||qr<l) return e; if(ql<=l&&qr>=r) return val[k]; int mid=l+r>>1; return Merge(query(k<<1,l,mid,ql,qr),query(k<<1|1,mid+1,r,ql,qr)); } inline void mo(int p, event x){modify(1,0,maxn-1,p,x);} inline event qu(int ql, int qr){return query(1,0,maxn-1,ql,qr);} }tree1,tree2; signed main(){ ios_base::sync_with_stdio(0),cin.tie(0); #ifdef i_am_noob freopen("input1.txt","r",stdin); freopen("output1.txt","w",stdout); freopen("output2.txt","w",stderr); #endif cin >> n >> q; rep(n-1) cin >> l[i] >> r[i]; rep(n-1){ r[i]--; tree1.mo(i,{l[i]-i,r[i]-i,l[i]-i,0}); tree2.mo(n-2-i,{l[i]-(n-2-i),r[i]-(n-2-i),l[i]-(n-2-i),0}); } while(q--){ int op; cin >> op; if(op==1){ int p,s,e; cin >> p >> s >> e; p--,e--; tree1.mo(p,{s-p,e-p,s-p,0}); tree2.mo(n-2-p,{s-(n-2-p),e-(n-2-p),s-(n-2-p),0}); } else{ int a,b,c,d; cin >> a >> b >> c >> d; a--,c--; event s,e,tmp; if(c>a){ b-=a,d-=c; tmp=tree1.qu(a,c-1); } else{ b-=n-1-a,d-=n-1-c; tmp=tree2.qu(n-1-a,n-2-c); } s={b,b,b,0},e={d,d,d,0}; tmp=Merge(s,tmp); tmp=Merge(tmp,e); cout << tmp[3] << "\n"; } } return 0; }

Compilation message (stderr)

timeleap.cpp: In member function 'void segtree::build(long long int, long long int, long long int)':
timeleap.cpp:70:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   70 |         int mid=l+r>>1;
      |                 ~^~
timeleap.cpp: In member function 'void segtree::modify(long long int, long long int, long long int, long long int, std::array<long long int, 4>)':
timeleap.cpp:83:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   83 |         int mid=l+r>>1;
      |                 ~^~
timeleap.cpp: In member function 'std::array<long long int, 4> segtree::query(long long int, long long int, long long int, long long int, long long int)':
timeleap.cpp:91:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   91 |         int mid=l+r>>1;
      |                 ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...