結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー | sak |
提出日時 | 2020-09-26 00:38:44 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,454 bytes |
コンパイル時間 | 2,402 ms |
コンパイル使用メモリ | 211,920 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2024-06-28 08:42:13 |
合計ジャッジ時間 | 4,932 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 93 ms
11,392 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 119 ms
11,388 KB |
testcase_19 | WA | - |
ソースコード
#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) { bool px = false, py = false; vector<ll> order; for (x+=size, y+=size; x||y; x>>=1, y>>=1) { px |= x&1; py |= y&1; if (px) order.push_back(x); if (py&&!(px&&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) { bool px = false, py = false; vector<ll> order; for (x+=size, y+=size; x||y; x>>=1, y>>=1) { if (x<size) { val[x] = f_back(x*2, x*2+1); 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); } 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); 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) ra += now.b; } else lst.set_operator(l,r+1,x); // cout << lst.query(0,N).a << " " << lst.query(0,N).b << endl; } color last = lst.query(0,N); ra += last.a; rb += last.b; cout << ra << " " << rb << endl; return 0; }