結果
問題 | No.833 かっこいい電車 |
ユーザー | risujiroh |
提出日時 | 2019-05-24 21:54:00 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 84 ms / 2,000 ms |
コード長 | 3,124 bytes |
コンパイル時間 | 1,882 ms |
コンパイル使用メモリ | 171,080 KB |
実行使用メモリ | 6,180 KB |
最終ジャッジ日時 | 2023-09-14 20:50:44 |
合計ジャッジ時間 | 4,260 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 64 ms
4,580 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 49 ms
4,904 KB |
testcase_11 | AC | 67 ms
5,684 KB |
testcase_12 | AC | 21 ms
4,376 KB |
testcase_13 | AC | 14 ms
4,376 KB |
testcase_14 | AC | 57 ms
5,712 KB |
testcase_15 | AC | 28 ms
4,664 KB |
testcase_16 | AC | 26 ms
5,188 KB |
testcase_17 | AC | 17 ms
4,376 KB |
testcase_18 | AC | 58 ms
4,920 KB |
testcase_19 | AC | 24 ms
4,860 KB |
testcase_20 | AC | 8 ms
4,380 KB |
testcase_21 | AC | 45 ms
4,376 KB |
testcase_22 | AC | 41 ms
5,972 KB |
testcase_23 | AC | 27 ms
4,904 KB |
testcase_24 | AC | 41 ms
5,700 KB |
testcase_25 | AC | 54 ms
4,560 KB |
testcase_26 | AC | 29 ms
5,108 KB |
testcase_27 | AC | 42 ms
4,712 KB |
testcase_28 | AC | 28 ms
4,376 KB |
testcase_29 | AC | 35 ms
4,472 KB |
testcase_30 | AC | 84 ms
6,180 KB |
testcase_31 | AC | 63 ms
4,856 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using lint = long long; template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; template<class T> struct FenwickTree { const int n; V<T> t; FenwickTree(int n) : n(n), t(n + 1) {} void add(int i, T x) { for (++i; i <= n; i += i & -i) t[i] += x; } T sum(int i) const { T s = 0; for (; i; i -= i & -i) s += t[i]; return s; } T sum(int l, int r) const { return sum(r) - sum(l); } }; struct SegmentTree { using T = int; static T op(const T& x, const T& y) { return max(x, y); } static constexpr T e() { return -1; } using U = int; static void ap(const U& f, T& x) { if (f != id()) x = f; } static void cp(const U& g, U& f) { if (g != id()) f = g; } static constexpr U id() { return -1; } const int n; V<T> t; V<U> u; SegmentTree(int n) : n(n), t(2 * n, e()), u(n, id()) {} T& operator[](int i) { return t[i + n]; } void build() { for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]); } void push() { for (int i = 1; i < n; ++i) push(i); } void apply(const U& f, int i) { ap(f, t[i]); if (i < n) cp(f, u[i]); } void push(int i) { if (u[i] == id()) return; apply(u[i], 2 * i); apply(u[i], 2 * i + 1); u[i] = id(); } void push(int l, int r) { for (int hl = __lg(l + n), hr = __lg(r - 1 + n); hr > 0; --hl, --hr) { int al = l + n >> hl, ar = r - 1 + n >> hr; if (al < n) push(al); if (ar != al) push(ar); } } T acc(int l, int r) { push(l, r); T resl = e(), resr = e(); for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) resl = op(resl, t[l++]); if (r & 1) resr = op(t[--r], resr); } return op(resl, resr); } T get(int i) { return acc(i, i + 1); } void act(int l, int r, const U& f) { push(l, r); for (int i = l + n, j = r + n; i < j; i >>= 1, j >>= 1) { if (i & 1) apply(f, i++); if (j & 1) apply(f, --j); } l = l + n >> __builtin_ctz(l + n); while (l >>= 1) t[l] = op(t[2 * l], t[2 * l + 1]); r = r + n >> __builtin_ctz(r + n); while (r >>= 1) t[r] = op(t[2 * r], t[2 * r + 1]); } void set(int i, const T& x) { push(i, i + 1); t[i += n] = x; while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]); } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, q; cin >> n >> q; FenwickTree<lint> ft(n); for (int i = 0; i < n; ++i) { int a; cin >> a; ft.add(i, a); } SegmentTree l(n), r(n); for (int i = 0; i < n; ++i) { l.set(i, i); r.set(i, i); } while (q--) { int tp, x; cin >> tp >> x, --x; if (tp == 1) { if (l.get(x) == l.get(x + 1)) continue; int a = l.get(x), b = r.get(x + 1); r.act(a, x + 1, b); l.act(x + 1, b + 1, a); } else if (tp == 2) { if (l.get(x) != l.get(x + 1)) continue; int a = l.get(x), b = r.get(x); r.act(a, x + 1, x); l.act(x + 1, b + 1, x + 1); } else if (tp == 3) { ft.add(x, 1); } else { lint res = ft.sum(l.get(x), r.get(x) + 1); cout << res << '\n'; } } }