結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー | sak |
提出日時 | 2020-09-26 01:36:24 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 192 ms / 5,000 ms |
コード長 | 4,370 bytes |
コンパイル時間 | 2,385 ms |
コンパイル使用メモリ | 212,328 KB |
実行使用メモリ | 11,528 KB |
最終ジャッジ日時 | 2024-06-28 09:45:44 |
合計ジャッジ時間 | 4,541 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 3 ms
6,944 KB |
testcase_06 | AC | 11 ms
6,940 KB |
testcase_07 | AC | 3 ms
6,940 KB |
testcase_08 | AC | 5 ms
6,940 KB |
testcase_09 | AC | 93 ms
7,296 KB |
testcase_10 | AC | 97 ms
6,944 KB |
testcase_11 | AC | 48 ms
6,940 KB |
testcase_12 | AC | 90 ms
7,300 KB |
testcase_13 | AC | 15 ms
6,940 KB |
testcase_14 | AC | 124 ms
11,376 KB |
testcase_15 | AC | 139 ms
11,376 KB |
testcase_16 | AC | 175 ms
11,480 KB |
testcase_17 | AC | 192 ms
11,436 KB |
testcase_18 | AC | 133 ms
11,528 KB |
testcase_19 | AC | 107 ms
11,452 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (int i=(int)N-1; i>=0; i--) const ll MOD = pow(10,9)+7; const ll LLINF = pow(2,61)-1; const int INF = pow(2,30)-1; vector<ll> fac; void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; } ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; } ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; } ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- struct color { ll z, a, b; color operator+ (const color &x) const { return {z+x.z, a+x.a, b+x.b}; }; }; struct LazySegTree { ll size, depth; color val_e = {1,0,0}; ll ope_e = -1; vector<color> val; vector<ll> ope; LazySegTree(ll N) { size = 1; depth = 0; while(size<N) { size<<=1; depth++; } val.resize(2*size,val_e); ope.resize(2*size,ope_e); for (ll i=size-1; i>=1; i--) val[i] = f_back(i*2, i*2+1); } color operator[](ll x) { return query(x,x+1); } void propagation(ll x, ll y) { vector<ll> order; for (x+=size, y+=size-1; x&&y; x>>=1, y>>=1) { order.push_back(x); if (x!=y) order.push_back(y); } for (auto itr=rbegin(order); itr!=rend(order); ++itr) { if (*itr>=size) break; ope[*itr*2] = g(ope[*itr*2] , ope[*itr]); ope[*itr*2+1] = g(ope[*itr*2+1], ope[*itr]); ope[*itr] = ope_e; } } void update_operator(ll x, ll y, ll v) { for (x+=size, y+=size; x<y; x>>=1, y>>=1) { if (x&1) { ope[x] = g(ope[x],v); x++; } if (y&1) { y--; ope[y] = g(ope[y],v); } } } void back_propagation(ll x, ll y) { for (x+=size, y+=size-1; x&&y; x>>=1, y>>=1) { if (x<size) val[x] = f_back(x*2, x*2+1); if (y<size) val[y] = f_back(y*2, y*2+1); } } void set_operator(ll x, ll y, ll v) { propagation(x,y); update_operator(x,y,v); back_propagation(x,y); // output(); } void set_value(ll x, color v) { propagation(x,x+1); val[x+size] = v; ope[x+size] = ope_e; back_propagation(x,x+1); } color query(ll x, ll y) { propagation(x,y); back_propagation(x,y); color L = {0,0,0}, R = {0,0,0}; for (x+=size, y+=size; x<y; x>>=1, y>>=1) { if (x&1) { L = f(L,h(val[x],ope[x])); x++; } if (y&1) { y--; R = f(h(val[y],ope[y]),R); } } return f(L,R); } void operate(ll i) { val[i] = f(val[i*2], val[i*2+1]); } color f(color x, color y) { return x + y; } color f_back(ll x, ll y) { return f(h(val[x],ope[x]),h(val[y],ope[y])); } // 要素同士の演算 ll g(ll x, ll y) { return y==-1 ? x : y; } // 作用素同士の演算 color h(color x, ll y) { ll sum = x.z+x.a+x.b; if (y==-1) return x; else if (y==0) return {sum,0,0}; else if (y==1) return {0,sum,0}; else if (y==2) return {0,0,sum}; return val_e; } // 要素に作用素を書ける void output() { rep(i,size*2) cout << i << ": " << val[i].z << "," << val[i].a << "," << val[i].b << " " << ope[i] << endl; // rep(i,size) { // color c = query(i,i+1); // cout << c.z << "," << c.a << "," << c.b << " "; cout << endl; // } } }; // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- int main() { ll N, Q; cin >> N >> Q; ll ra = 0, rb = 0; LazySegTree lst(N); rep(_,Q) { ll x, l, r; cin >> x >> l >> r; if (x==0) { color now = lst.query(l,r+1); if (now.a>now.b) ra += now.a; else if (now.a<now.b) rb += now.b; // cout << "now:" << now.a << " " << now.b << endl; } else lst.set_operator(l,r+1,x); // lst.output(); } color last = lst.query(0,N); ra += last.a; rb += last.b; cout << ra << " " << rb << endl; return 0; }