結果
問題 | No.879 Range Mod 2 Query |
ユーザー | maroon_kuri |
提出日時 | 2019-09-06 22:31:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 160 ms / 3,000 ms |
コード長 | 6,206 bytes |
コンパイル時間 | 1,975 ms |
コンパイル使用メモリ | 177,604 KB |
実行使用メモリ | 16,256 KB |
最終ジャッジ日時 | 2024-06-24 22:12:05 |
合計ジャッジ時間 | 4,700 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 3 ms
5,376 KB |
testcase_11 | AC | 157 ms
16,128 KB |
testcase_12 | AC | 96 ms
16,128 KB |
testcase_13 | AC | 120 ms
16,128 KB |
testcase_14 | AC | 109 ms
16,256 KB |
testcase_15 | AC | 102 ms
9,856 KB |
testcase_16 | AC | 150 ms
16,256 KB |
testcase_17 | AC | 154 ms
16,256 KB |
testcase_18 | AC | 160 ms
16,256 KB |
testcase_19 | AC | 135 ms
16,128 KB |
testcase_20 | AC | 135 ms
16,256 KB |
testcase_21 | AC | 143 ms
16,256 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; #define int ll #define rng(i,a,b) for(int i=int(a);i<int(b);i++) #define rep(i,b) rng(i,0,b) #define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--) #define per(i,b) gnr(i,0,b) #define pb push_back #define eb emplace_back #define a first #define b second #define bg begin() #define ed end() #define all(x) x.bg,x.ed #ifdef LOCAL #define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl #else #define dmp(x) void(0) #endif template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;} template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;} template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; using pi=pair<int,int>; using vi=vc<int>; template<class t,class u> ostream& operator<<(ostream& os,const pair<t,u>& p){ return os<<"{"<<p.a<<","<<p.b<<"}"; } template<class t> ostream& operator<<(ostream& os,const vc<t>& v){ os<<"{"; for(auto e:v)os<<e<<","; return os<<"}"; } #define mp make_pair #define mt make_tuple #define one(x) memset(x,-1,sizeof(x)) #define zero(x) memset(x,0,sizeof(x)) using uint=unsigned; using ull=unsigned long long; template<int i,class T> void print_tuple(ostream&,const T&){ } template<int i,class T,class H,class ...Args> void print_tuple(ostream&os,const T&t){ if(i)os<<","; os<<get<i>(t); print_tuple<i+1,T,Args...>(os,t); } template<class ...Args> ostream& operator<<(ostream&os,const tuple<Args...>&t){ os<<"{"; print_tuple<0,tuple<Args...>,Args...>(os,t); return os<<"}"; } void print(ll x,int suc=1){ cout<<x; if(suc==1) cout<<"\n"; if(suc==2) cout<<" "; } ll read(){ ll i; cin>>i; return i; } vi readvi(int n,int off=0){ vi v(n); rep(i,n)v[i]=read()+off; return v; } template<class T> void print(const vector<T>&v,int suc=1){ rep(i,v.size()) print(v[i],i==int(v.size())-1?suc:2); } string readString(){ string s; cin>>s; return s; } template<class T> T sq(const T& t){ return t*t; } //#define CAPITAL void yes(bool ex=true){ #ifdef CAPITAL cout<<"YES"<<endl; #else cout<<"Yes"<<endl; #endif if(ex)exit(0); } void no(bool ex=true){ #ifdef CAPITAL cout<<"NO"<<endl; #else cout<<"No"<<endl; #endif if(ex)exit(0); } constexpr ll ten(int n){ return n==0?1:ten(n-1)*10; } const ll infLL=LLONG_MAX/3; #ifdef int const int inf=infLL; #else const int inf=INT_MAX/2-100; #endif int topbit(signed t){ return t==0?-1:31-__builtin_clz(t); } int topbit(ll t){ return t==0?-1:63-__builtin_clzll(t); } int popcount(signed t){ return __builtin_popcount(t); } int popcount(ll t){ return __builtin_popcountll(t); } bool ispow2(int i){ return i&&(i&-i)==i; } int mask(int i){ return (int(1)<<i)-1; } bool inc(int a,int b,int c){ return a<=b&&b<=c; } template<class t> void mkuni(vc<t>&v){ sort(all(v)); v.erase(unique(all(v)),v.ed); } ll rand_int(ll l, ll r) { //[l, r] static random_device rd; static mt19937_64 gen(rd()); return uniform_int_distribution<ll>(l, r)(gen); } //KUPC2017I //HDU 5306 Gorgeous Sequence template<class N> struct segbeats{ vc<N> x; int s; template<class T> segbeats(const vc<T>& a){ int n=a.size(); s=1; while(s<n)s*=2; x.resize(s*2); rep(i,n) x[s+i]=N(a[i]); gnr(i,1,s) upd(i); } void push(int i){ x[i].push(x[i*2],x[i*2+1]); } void upd(int i){ x[i]=N::merge(x[i*2],x[i*2+1]); } template<class F,class... Args> void chr(int l,int r,int i,int b,int e,F f,Args... args){ if(e<=l||r<=b) return; if(b<=l&&r<=e&&(x[i].*f)(args...)) return; push(i); int m=(l+r)/2; chr(l,m,i*2,b,e,f,args...); chr(m,r,i*2+1,b,e,f,args...); upd(i); } template<class F,class... Args> void ch(int b,int e,F f,Args... args){ assert(b<e); chr(0,s,1,b,e,f,args...); } //use decltype((declval<N>().*F())()) for old-fashioned judges template<class F,class G,class H> auto getr(int l,int r,int i,int b,int e,F f,G g,H h){ if(e<=l||r<=b) return h; if(b<=l&&r<=e) return (x[i].*f)(); push(i); int m=(l+r)/2; return g(getr(l,m,i*2,b,e,f,g,h),getr(m,r,i*2+1,b,e,f,g,h)); } template<class F,class G,class H> auto get(int b,int e,F f,G g,H h){ assert(b<e); return getr(0,s,1,b,e,f,g,h); } //return minimum index template<class F,class...Args> pair<int,N> findr(int i,int l,int r,int b,int e,F f,Args&...args){ if(e<=l||r<=b)return {e,N()}; if(b<=l&&r<=e){ if(!(x[i].*f)(args...))return {e,N()}; if(r-l==1)return {l,x[i]}; } push(i); int m=(l+r)/2; auto a=findr(i*2,l,m,b,e,f,args...); if(a.a<e)return a; return findr(i*2+1,m,r,b,e,f,args...); } template<class F,class...Args> pair<int,N> find(int b,int e,F f,Args&...args){ assert(b<e); return findr(1,0,s,b,e,f,args...); } //NOT VERIFIED /* //return maximum index template<class F,class...Args> pair<int,N> findr(int i,int l,int r,int b,int e,F f,Args&&...args){ if(e<=l||r<=b)return {b-1,N()}; if(b<=l&&r<=e){ if(!(x[i].*f)(args...))return {b-1,N()}; if(r-l==1)return {l,x[i]}; } push(i); int m=(l+r)/2; auto a=findr(i*2+1,m,r,b,e,f,forward<Args>(args)...); if(a.a>=b)return a; return findr(i*2,l,m,b,e,f,forward<Args>(args)...); } template<class F,class...Args> pair<int,N> find(int b,int e,F f,Args&&...args){ assert(b<e); return findr(1,0,s,b,e,f,forward<Args>(args)...); } */ }; //usage struct N{ int l1,l2,a,b,num,sum; N(int v=0):l1(-1),l2(0),a(!(v%2)),b(v%2),num(1),sum(v){} bool add(int v){ l2+=v; if(v%2)swap(a,b); sum+=num*v; return true; } bool mod(){ l1=(l2+(l1==-1?0:l1))%2; l2=0; sum=b; return true; } void push(N& x,N& y){ if(l1!=-1){ x.add(l1); x.mod(); y.add(l1); y.mod(); l1=-1; } x.add(l2); y.add(l2); l2=0; } static N merge(N x,N y){ N res; res.a=x.a+y.a; res.b=x.b+y.b; res.num=x.num+y.num; res.sum=x.sum+y.sum; return res; } int gets(){ return sum; } }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); int n,q;cin>>n>>q; vi a=readvi(n); segbeats<N> seg(a); rep(_,q){ int t,l,r;cin>>t>>l>>r; l--; if(t==1){ seg.ch(l,r,&N::mod); }else if(t==2){ int x;cin>>x; seg.ch(l,r,&N::add,x); }else{ print(seg.get(l,r,&N::gets,[](int x,int y){return x+y;},int(0))); } } }