제출 #1128707

#제출 시각아이디문제언어결과실행 시간메모리
1128707Noproblem29Simple game (IZhO17_game)C++20
100 / 100
234 ms17816 KiB
#include<bits/stdc++.h> using namespace std; #ifndef BADGNU #pragma GCC target("sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #endif #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ll long long // #define int ll #define ld long double #define y1 cheza mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>; const int N=1e6+100; const int M=5001; const int B=447; const int mod=998244353; const ll INF=1e18; const int dx[]={1,-1,0,0}; const int dy[]={0,0,1,-1}; const double eps=1e-6; int n,q; int a[N]; int t[N*4]; int add[N*4]; void push(int v,int tl,int tr){ if(tl!=tr){ add[v*2]+=add[v]; add[v*2+1]+=add[v]; } t[v]+=(tr-tl+1)*add[v]; add[v]=0; } void upd(int v,int tl,int tr,int l,int r,int x){ push(v,tl,tr); if(tl>r||tr<l)return; if(l<=tl&&tr<=r){ add[v]=x; push(v,tl,tr); return; } int mid=(tl+tr)>>1ll; upd(v*2,tl,mid,l,r,x); upd(v*2+1,mid+1,tr,l,r,x); t[v]=t[v*2]+t[v*2+1]; } int get(int v,int tl,int tr,int l,int r){ push(v,tl,tr); if(tl>r||tr<l)return 0; if(l<=tl&&tr<=r){ return t[v]; } int mid=(tl+tr)>>1ll; return get(v*2,tl,mid,l,r)+get(v*2+1,mid+1,tr,l,r); } void test(){ cin>>n>>q; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<n;i++){ if(a[i]+1<=a[i+1]-1){ upd(1,1,1e6,a[i]+1,a[i+1]-1,1); } if(a[i]-1>=a[i+1]+1){ upd(1,1,1e6,a[i+1]+1,a[i]-1,1); } } for(int t,x,y;q--;){ cin>>t; if(t==1){ cin>>x>>y; if(x>1&&a[x-1]+1<=a[x]-1){ upd(1,1,1e6,a[x-1]+1,a[x]-1,-1); } if(x>1&&a[x-1]-1>=a[x]+1){ upd(1,1,1e6,a[x]+1,a[x-1]-1,-1); } if(x<n&&a[x]+1<=a[x+1]-1){ upd(1,1,1e6,a[x]+1,a[x+1]-1,-1); } if(x<n&&a[x]-1>=a[x+1]+1){ upd(1,1,1e6,a[x+1]+1,a[x]-1,-1); } a[x]=y; if(x>1&&a[x-1]+1<=a[x]-1){ upd(1,1,1e6,a[x-1]+1,a[x]-1,1); } if(x>1&&a[x-1]-1>=a[x]+1){ upd(1,1,1e6,a[x]+1,a[x-1]-1,1); } if(x<n&&a[x]+1<=a[x+1]-1){ upd(1,1,1e6,a[x]+1,a[x+1]-1,1); } if(x<n&&a[x]-1>=a[x+1]+1){ upd(1,1,1e6,a[x+1]+1,a[x]-1,1); } } if(t==2){ cin>>x; cout<<get(1,1,1e6,x,x)<<'\n'; } } } /* */ signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr); int t2=1; // cin>>t2; for(int i=1;i<=t2;i++){ test(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...