結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー | Orisano |
提出日時 | 2016-11-19 03:39:53 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 126 ms / 5,000 ms |
コード長 | 4,861 bytes |
コンパイル時間 | 2,000 ms |
コンパイル使用メモリ | 178,112 KB |
実行使用メモリ | 7,296 KB |
最終ジャッジ日時 | 2024-05-04 20:42:57 |
合計ジャッジ時間 | 3,570 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 7 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 57 ms
5,376 KB |
testcase_10 | AC | 40 ms
5,376 KB |
testcase_11 | AC | 32 ms
5,376 KB |
testcase_12 | AC | 60 ms
5,376 KB |
testcase_13 | AC | 10 ms
5,376 KB |
testcase_14 | AC | 27 ms
7,296 KB |
testcase_15 | AC | 67 ms
7,296 KB |
testcase_16 | AC | 81 ms
7,296 KB |
testcase_17 | AC | 126 ms
7,296 KB |
testcase_18 | AC | 50 ms
7,296 KB |
testcase_19 | AC | 75 ms
7,296 KB |
ソースコード
#include <bits/stdc++.h> // {{{ // clang-format off #pragma GCC optimize "O3,omit-frame-pointer,inline" #pragma GCC target "tune=native" #define ARG4(_1, _2, _3, _4, ...) _4 #define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__) #define REP(i, a) FOR(i, 0, a) #define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i) #define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__) #define RREP(i, a) RFOR(i, 0, a) #define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i) #define ALL(c) (c).begin(), (c).end() #define TEN(n) ((ll)(1e##n)) #define pb emplace_back #define mp make_pair #define fi first #define se second #define USE1(T) template<typename T>inline #define USE2(T, U) template<typename T,typename U>inline #define mygc(c) (c)=getchar_unlocked() #define mypc(c) putchar_unlocked(c) template<typename T>using duo=std::pair<T,T>; template<typename T>using vec=std::vector<T>; using ll=long long; using pii=duo<int>; USE2(T,U)bool chmax(T&x,U a){return x<a&&(x=a,1);} USE2(T,U)bool chmin(T&x,U a){return a<x&&(x=a,1);} USE1(T=int)T in(){T x;std::cin>>x;return x;} USE1(T=int)vec<T>in(int n){vec<T>v;v.reserve(n);rep(i,n)v.pb(in<T>());return v;} USE1(T=int)vec<T>in(int n,T a){vec<T>v;v.reserve(n);rep(i,n)v.pb(in<T>()+a);return v;} USE1(T)vec<std::pair<T,int>>enume(const vec<T>&x,int s=0){int N=x.size();vec<std::pair<T,int>>v;v.reserve(N);rep(i,N)v.pb(x[i],s+i);return v;} USE1(T)vec<T>ndvec(T v,int n){return vec<T>(n,v);} USE2(T,...Ts)auto ndvec(T v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);} USE1(T)void pr(T x){std::cout<<x<<'\n';} USE2(T,...Ts)void pr(T x,Ts...xs){std::cout<<x<<' ';pr(xs...);} USE1(T=int)T rd(){T x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;} USE1(T=int)void wr(T x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);} // clang-format on // }}} #include <vector> namespace copr { namespace seg_util { constexpr int nextpow2(int x, int r = 1) { return r < x ? nextpow2(x, r + r) : r; } } // namespace seg_util template <typename Monoid, typename Lazy> struct LazySegTree { using data_type = typename Monoid::value_type; using lazy_type = typename Lazy::value_type; const int N; const data_type empty = Monoid::empty(); const lazy_type nil = Lazy::empty(); std::vector<data_type> data; std::vector<lazy_type> lazy; LazySegTree(int size) : N(seg_util::nextpow2(size)) { data.assign(N * 2, empty); lazy.assign(N * 2, nil); } inline void propagate(int x, int l, int r) { if (lazy[x] == nil) return; data[x] = Lazy::eval(data[x], lazy[x], l, r); if (x < N - 1) { lazy[x + x + 1] = Lazy::append(lazy[x + x + 1], lazy[x]); lazy[x + x + 2] = Lazy::append(lazy[x + x + 2], lazy[x]); } lazy[x] = nil; } void query(lazy_type v, int a, int b) { query(v, a, b, 0, 0, N); } void query(lazy_type v, int a, int b, int x, int l, int r) { propagate(x, l, r); if (r <= a || b <= l) return; if (a <= l && r <= b) { lazy[x] = Lazy::append(lazy[x], v); propagate(x, l, r); return; } int m = (l + r) / 2; query(v, a, b, x + x + 1, l, m); query(v, a, b, x + x + 2, m, r); data[x] = Monoid::append(data[x + x + 1], data[x + x + 2]); } data_type concat(int a, int b) { return concat(a, b, 0, 0, N); } data_type concat(int a, int b, int x, int l, int r) { propagate(x, l, r); if (r <= a || b <= l) return empty; if (a <= l && r <= b) return data[x]; int m = (l + r) / 2; return Monoid::append(concat(a, b, x + x + 1, l, m), concat(a, b, x + x + 2, m, r)); } }; } // namespace copr using namespace std; const int inf = 1001001001; const ll infl = 1001001001001001001ll; const int dd[] = {0, 1, 0, -1, 0}; struct Sum { using value_type = int; static value_type append(value_type a, value_type b) { return a + b; } static value_type empty() { return 0; } struct FillQuery { using value_type = int; static value_type append(value_type a, value_type b) { return b; } static value_type empty() { return -1; } template <typename T> static T eval(T v, value_type x, int l, int r) { return x * (r - l); } }; }; signed main() { // int N = rd(); int Q = rd(); copr::LazySegTree<Sum, Sum::FillQuery> A{N}, B{N}; ll a = 0, b = 0; rep(i, Q) { int x = rd(), l = rd(), r = rd() + 1; if (x == 0) { auto ac = A.concat(l, r); auto bc = B.concat(l, r); if (ac == bc) continue; if (ac < bc) { b += bc; } else { a += ac; } } else { A.query(x == 1, l, r); B.query(x == 2, l, r); } } a += A.concat(0, N); b += B.concat(0, N); wr(a, ' '); wr(b); return 0; }