結果
問題 | No.833 かっこいい電車 |
ユーザー | FF256grhy |
提出日時 | 2019-05-24 23:22:12 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 167 ms / 2,000 ms |
コード長 | 4,318 bytes |
コンパイル時間 | 1,914 ms |
コンパイル使用メモリ | 180,552 KB |
実行使用メモリ | 9,600 KB |
最終ジャッジ日時 | 2024-07-02 03:47:23 |
合計ジャッジ時間 | 5,392 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 167 ms
6,528 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 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 112 ms
6,400 KB |
testcase_11 | AC | 148 ms
9,600 KB |
testcase_12 | AC | 46 ms
6,528 KB |
testcase_13 | AC | 33 ms
5,376 KB |
testcase_14 | AC | 112 ms
9,600 KB |
testcase_15 | AC | 57 ms
6,400 KB |
testcase_16 | AC | 40 ms
6,528 KB |
testcase_17 | AC | 46 ms
5,376 KB |
testcase_18 | AC | 138 ms
6,400 KB |
testcase_19 | AC | 41 ms
6,528 KB |
testcase_20 | AC | 12 ms
5,376 KB |
testcase_21 | AC | 121 ms
5,376 KB |
testcase_22 | AC | 72 ms
9,600 KB |
testcase_23 | AC | 49 ms
6,528 KB |
testcase_24 | AC | 73 ms
9,600 KB |
testcase_25 | AC | 135 ms
6,656 KB |
testcase_26 | AC | 52 ms
9,600 KB |
testcase_27 | AC | 91 ms
6,528 KB |
testcase_28 | AC | 68 ms
5,376 KB |
testcase_29 | AC | 79 ms
6,400 KB |
testcase_30 | AC | 85 ms
9,600 KB |
testcase_31 | AC | 151 ms
6,528 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long signed int LL; typedef long long unsigned int LU; #define incID(i, l, r) for(LL i = (l) ; i < (r); ++i) #define incII(i, l, r) for(LL i = (l) ; i <= (r); ++i) #define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i) #define decII(i, l, r) for(LL i = (r) ; i >= (l); --i) #define inc(i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec(i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() template<typename T> bool setmin (T & a, T b) { if(b < a) { a = b; return true; } else { return false; } } template<typename T> bool setmax (T & a, T b) { if(b > a) { a = b; return true; } else { return false; } } template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } } template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } } LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; } LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); } LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); } template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define bit(b, i) (((b) >> (i)) & 1) #define BC __builtin_popcountll #define SC static_cast #define SI(v) SC<int>(v.size()) #define SL(v) SC<LL >(v.size()) #define RF(e, v) for(auto & e: v) #define ef else if #define UR assert(false) // ---- ---- template<typename T> class SegmentTree { private: T * a = NULL; int N = -1, S; function<T(T, T)> F; T I; bool is_available = false; public: SegmentTree() { } SegmentTree(int n, function<T(T, T)> func, T id) { init(n, func, id); } void init(int size, function<T(T, T)> func, T id) { assert(size > 0); N = size; F = func; I = id; S = 1; while(S < size) { S *= 2; } delete[] a; a = new T[S * 2]; inc(i, S * 2) { a[i] = I; } is_available = true; } const T & operator[](int p) { assert(inID(p, 0, N)); p += S; return a[p]; } T & ref(int p) { is_available = false; assert(inID(p, 0, N)); p += S; return a[p]; } void calc() { decID(i, 1, S) { a[i] = F(a[i * 2], a[i * 2 + 1]); } is_available = true; } void apply(int p, function<void(T &)> op) { assert(inID(p, 0, N)); p += S; op(a[p]); while(p != 1) { p /= 2; a[p] = F(a[p * 2], a[p * 2 + 1]); } } T fold_ID(int l, int r, bool loop = false) { assert(is_available); assert(inII(l, 0, N)); assert(inII(r, 0, N)); if(loop && l >= r) { return F(fold_ID(l, N), fold_ID(0, r)); } assert(l <= r); l += S; r += S; T v = I, w = I; while(l < r) { if(l + 1 == r) { v = F(v, a[l]); break; } if(l % 2 == 1) { v = F(v, a[l]); } if(r % 2 == 1) { w = F(a[r - 1], w); } l = (l + 1) / 2; r = r / 2; } return F(v, w); } T fold_II(int l, int r, bool loop = false) { return fold_ID(l , r + 1, loop); } T fold_CD(int l, int r, bool loop = false) { return fold_ID(l + 1, r , loop); } T fold_CI(int l, int r, bool loop = false) { return fold_ID(l + 1, r + 1, loop); } }; #define OP(op) [&](auto A, auto B) { return op; } #define AP(op) [&](auto & A) { op; } // ---- ---- LL n, Q; int main() { cin >> n >> Q; SegmentTree<LL> stv(n, OP(A + B), 0); SegmentTree<pair<int, int>> stl(n + 1, OP(max(A, B)), MP(-1, 0)); SegmentTree<pair<int, int>> str(n + 1, OP(min(A, B)), MP(+1, 0)); inc(i, n) { LL a; cin >> a; stv.ref(i) = a; } incII(i, 0, n) { stl.ref(i) = MP(0, i); str.ref(i) = MP(0, i); } stv.calc(); stl.calc(); str.calc(); inc(q, Q) { LL t, x; cin >> t >> x; if(t == 1) { stl.apply(x, AP(A.FI = -1)); str.apply(x, AP(A.FI = +1)); } if(t == 2) { stl.apply(x, AP(A.FI = 0)); str.apply(x, AP(A.FI = 0)); } if(t == 3) { x--; stv.apply(x, AP(A++)); } if(t == 4) { x--; int L = stl.fold_II(0, x).SE; int R = str.fold_CI(x, n).SE; cout << stv.fold_ID(L, R) << "\n"; } } return 0; }