結果
問題 | No.833 かっこいい電車 |
ユーザー | けーむ |
提出日時 | 2020-05-13 14:13:35 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 178 ms / 2,000 ms |
コード長 | 5,318 bytes |
コンパイル時間 | 2,633 ms |
コンパイル使用メモリ | 194,128 KB |
実行使用メモリ | 15,872 KB |
最終ジャッジ日時 | 2024-09-14 15:34:58 |
合計ジャッジ時間 | 6,588 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 140 ms
9,472 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 | 123 ms
9,728 KB |
testcase_11 | AC | 158 ms
15,488 KB |
testcase_12 | AC | 46 ms
9,216 KB |
testcase_13 | AC | 35 ms
5,376 KB |
testcase_14 | AC | 116 ms
15,360 KB |
testcase_15 | AC | 56 ms
9,472 KB |
testcase_16 | AC | 28 ms
9,728 KB |
testcase_17 | AC | 50 ms
5,376 KB |
testcase_18 | AC | 148 ms
9,600 KB |
testcase_19 | AC | 31 ms
9,728 KB |
testcase_20 | AC | 8 ms
6,144 KB |
testcase_21 | AC | 134 ms
6,272 KB |
testcase_22 | AC | 59 ms
15,616 KB |
testcase_23 | AC | 37 ms
9,728 KB |
testcase_24 | AC | 60 ms
15,360 KB |
testcase_25 | AC | 147 ms
9,472 KB |
testcase_26 | AC | 41 ms
14,976 KB |
testcase_27 | AC | 93 ms
9,600 KB |
testcase_28 | AC | 75 ms
6,272 KB |
testcase_29 | AC | 82 ms
9,344 KB |
testcase_30 | AC | 178 ms
15,872 KB |
testcase_31 | AC | 133 ms
9,600 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++) #define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++) #define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--) #define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((ll)(x).size()) #define len(x) ((ll)(x).length()) #define endl "\n" template<class T, class E> struct LazySegmentTree { private: int n; vector<T> node; vector<E> lazy; vector<bool> updated; T def; function<T(T,T)> out; function<T(T,E,int)> app; function<E(E,E)> lop; void propagate(int k, E x) { if (updated[k]) { lazy[k] = lop(lazy[k], x); } else { lazy[k] = x; updated[k] = true; } } void evaluate(int k, int l, int r) { if (updated[k]) { node[k] = app(node[k], lazy[k], r - l); if ((r - l) > 1) { propagate(k * 2 + 1, lazy[k]); propagate(k * 2 + 2, lazy[k]); } updated[k] = false; } } public: LazySegmentTree() {} LazySegmentTree(const vector<T> &v, T _def, function<E(E,E)> _lop, function<T(T,E,int)> _app, function<T(T,T)> _out) { def = _def; out = _out; app = _app; lop = _lop; int vl = (int)v.size(); n = 1; while(n < vl) n *= 2; node.resize(2 * n - 1, def); lazy.resize(2 * n - 1); updated.resize(2 * n - 1, false); for(int i = 0; i < vl; i++) node[i + n - 1] = v[i]; for(int i = n - 2; i >= 0; i--) node[i] = out(node[i * 2 + 1], node[i * 2 + 2]); } void update(int a, int b, E x, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; evaluate(k, l, r); if((b <= l) || (r <= a)) return; if((a <= l) && (r <= b)) { propagate(k, x); evaluate(k, l, r); } else { update(a, b, x, 2 * k + 1, l, (l + r) / 2); update(a, b, x, 2 * k + 2, (l + r) / 2, r); node[k] = out(node[2 * k + 1], node[2 * k + 2]); } } T query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; evaluate(k, l, r); if ((b <= l) || (r <= a)) return def; if ((a <= l) && (r <= b)) return node[k]; T vl = query(a, b, 2 * k + 1, l, (l + r) / 2); T vr = query(a, b, 2 * k + 2, (l + r) / 2, r); return out(vl, vr); } }; template<class T> struct SegmentTree { private: int n; vector<T> node; T def; function<T(T,T)> lop; function<T(T,T)> out; public: SegmentTree() {} SegmentTree(const vector<T> &v, T _def, function<T(T,T)> _lop, function<T(T,T)> _out) { int vl = (int)v.size(); n = 1; while(n < vl) n *= 2; def = _def; lop = _lop; out = _out; node = vector<T>(2 * n - 1, def); for(int i = 0; i < vl; i++) node[i + n - 1] = v[i]; for(int i = n - 2; i >= 0; i--) node[i] = out(node[i * 2 + 1], node[i * 2 + 2]); } void update(int idx, T val) { idx += (n - 1); node[idx] = lop(node[idx], val); while(idx > 0) { idx = (idx - 1) / 2; node[idx] = out(node[idx * 2 + 1], node[idx * 2 + 2]); } } T query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if ((r <= a) || (b <= l)) return def; if ((a <= l) && (r <= b)) return node[k]; return out(query(a, b, 2 * k + 1, l, (l + r) / 2), query(a, b, 2 * k + 2, (l + r) / 2, r)); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); // ifstream in("input.txt"); // cin.rdbuf(in.rdbuf()); ll n, q; cin >> n >> q; vector<ll> a(n); rep(i, n) cin >> a[i]; vector<pair<ll, ll>> vp(n); rep(i, n) vp[i] = make_pair(i, i); auto lop1 = [](pair<ll, ll> a, pair<ll, ll> b){ return b; }; auto app1 = [](pair<ll, ll> a, pair<ll, ll> b, int c){ return b; }; auto out1 = [](pair<ll, ll> a, pair<ll, ll> b){ return make_pair(a.first + b.first, a.second + b.second); }; LazySegmentTree<pair<ll, ll>, pair<ll, ll>> range(vp, make_pair(0, 0), lop1, app1, out1); auto lop2 = [](ll a, ll b){ return a + b; }; auto out2 = [](ll a, ll b){ return a + b; }; SegmentTree<ll> val(a, 0, lop2, out2); rep(i, q) { ll t, x; cin >> t >> x; x--; if (t == 1) { pair<ll, ll> p1 = range.query(x, x + 1); pair<ll, ll> p2 = range.query(x + 1, x + 2); range.update(p1.first, p2.second + 1, make_pair(p1.first, p2.second)); } else if (t == 2) { pair<ll, ll> p1 = range.query(x, x + 1); pair<ll, ll> p2 = range.query(x + 1, x + 2); range.update(p1.first, x + 1, make_pair(p1.first, x)); range.update(x + 1, p2.second + 1, make_pair(x + 1, p2.second)); } else if (t == 3) { val.update(x, 1); } else { pair<ll, ll> p = range.query(x, x + 1); cout << val.query(p.first, p.second + 1) << endl; } } return 0; }