結果
問題 | No.879 Range Mod 2 Query |
ユーザー | tjake |
提出日時 | 2019-09-07 11:07:47 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,355 bytes |
コンパイル時間 | 1,215 ms |
コンパイル使用メモリ | 89,700 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-26 06:21:14 |
合計ジャッジ時間 | 5,193 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | RE | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | RE | - |
testcase_05 | WA | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
ソースコード
#include<iostream> #include<string> #include<vector> #include<queue> #include<stack> #include<map> #include<set> #include<algorithm> #include<functional> #include<cstdio> #include<cstdlib> #include<cmath> #include<cassert> #include<ctime> using namespace std; #define mind(a,b) (a>b?b:a) #define maxd(a,b) (a>b?a:b) #define absd(x) (x<0?-(x):x) #define pow2(x) ((x)*(x)) #define rep(i,n) for(int i=0; i<n; ++i) #define repr(i,n) for(int i=n-1; i>=0; --i) #define repl(i,s,n) for(int i=s; i<=n; ++i) #define replr(i,s,n) for(int i=n; i>=s; --i) #define repf(i,s,n,j) for(int i=s; i<=n; i+=j) #define repe(e,obj) for(auto e : obj) #define SP << " " << #define COL << " : " << #define COM << ", " << #define ARR << " -> " << #define PNT(STR) cout << STR << endl #define POS(X,Y) "(" << X << ", " << Y << ")" #define DEB(A) " (" << #A << ") " << A #define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl #define ALL(V) (V).begin(), (V).end() #define INF 1000000007 #define INFLL 1000000000000000007LL #define EPS 1e-9 typedef unsigned int uint; typedef unsigned long ulong; typedef unsigned long long ull; typedef long long ll; typedef long double ld; #define P_TYPE ll typedef pair<P_TYPE, P_TYPE> P; typedef pair<P, P_TYPE> PI; typedef pair<P_TYPE, P> IP; typedef pair<P, P> PP; typedef priority_queue<P, vector<P>, greater<P> > pvqueue; #define N (1 << 10) class SegmentTree { ll data[2*N], lazy[2*N], cnt0[2*N], cnt1[2*N]; bool flag[2*N], sw[2*N]; int n0, n; void propagate(int k) { if(sw[k]) { swap(cnt0[2*k+1], cnt1[2*k+1]); swap(cnt0[2*k+2], cnt1[2*k+2]); sw[2*k+1] = sw[2*k+2] = true; sw[k] = false; } if(flag[k]) { data[2*k+1] = cnt1[2*k+1]; data[2*k+2] = cnt1[2*k+2]; lazy[2*k+1] = lazy[2*k+2] = 0; flag[2*k+1] = flag[2*k+2] = true; flag[k] = false; } if(lazy[k] != 0) { data[2*k+1] += lazy[k] * (cnt0[2*k+1] + cnt1[2*k+1]); data[2*k+2] += lazy[k] * (cnt0[2*k+2] + cnt1[2*k+2]); lazy[2*k+1] += lazy[k]; lazy[2*k+2] += lazy[k]; lazy[k] = 0; } } void build(int k) { cnt0[k] = cnt0[2*k+1] + cnt0[2*k+2]; cnt1[k] = cnt1[2*k+1] + cnt1[2*k+2]; data[k] = data[2*k+1] + data[2*k+2]; } void _set(int a, int b, int k, int l, int r) { propagate(k); if(b <= l || r <= a) { return; } if(a <= l && r <= b) { flag[k] = true; data[k] = cnt1[k]; lazy[k] = 0; return; } _set(a, b, 2*k+1, l, (l+r)/2); _set(a, b, 2*k+2, (l+r)/2, r); build(k); } void _add(ll x, int a, int b, int k, int l, int r) { propagate(k); if(b <= l || r <= a) { return; } if(a <= l && r <= b) { if(x % 2) { swap(cnt0[k], cnt1[k]); sw[k] ^= true; } data[k] += x * (cnt0[k] + cnt1[k]); lazy[k] += x; return; } _add(x, a, b, 2*k+1, l, (l+r)/2); _add(x, a, b, 2*k+2, (l+r)/2, r); build(k); } ll _query(int a, int b, int k, int l, int r) { propagate(k); if(b <= l || r <= a) { return 0; } if(a <= l && r <= b) { return data[k]; } ll lv = _query(a, b, 2*k+1, l, (l+r)/2); ll rv = _query(a, b, 2*k+2, (l+r)/2, r); build(k); return lv + rv; } public: SegmentTree(int n, ll *a) { n0 = 1; while(n0 < n) n0 <<= 1; for(int i=0; i<n; ++i) { data[n0-1+i] = a[i]; if(a[i] % 2) { cnt1[n0-1+i] = 1; cnt0[n0-1+i] = 0; } else { cnt1[n0-1+i] = 0; cnt0[n0-1+i] = 1; } } for(int i=n; i<n0; ++i) { data[n0-1+i] = 0; cnt0[n0-1+i] = cnt1[n0-1+i] = 0; } for(int i=0; i<2*n0-1; ++i) lazy[i] = 0, flag[i] = sw[i] = false; for(int i=n0-2; i>=0; --i) build(i); } void set(int l, int r) { _set(l, r, 0, 0, n0); } void add(int l, int r, ll x) { _add(x, l, r, 0, 0, n0); } ll query(int l, int r) { return _query(l, r, 0, 0, n0); } }; ll a[N]; int main() { int n, q; cin >> n >> q; rep(i, n) cin >> a[i]; SegmentTree st(n, a); while(q--) { int t, l, r; ll x; cin >> t >> l >> r; switch(t) { case 1: st.set(l-1, r); break; case 2: cin >> x; st.add(l-1, r, x); break; case 3: cout << st.query(l-1, r) << endl; break; } } return 0; }