結果

問題 No.833 かっこいい電車
ユーザー cotton_fn_
提出日時 2019-05-24 23:51:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 1,989 bytes
コンパイル時間 1,280 ms
コンパイル使用メモリ 118,124 KB
最終ジャッジ日時 2025-01-07 04:03:28
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>
using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x)
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0)
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs
template<class T, class F = plus<T>>
struct Fenwick {
i64 n;
vector<T> c;
F f;
Fenwick(i64 n, F f = plus<T>(), T init = T())
: n(n), c(n + 1, init), f(f) {}
T sum(i64 i) {
return i > 0 ? f(sum(i - (i & -i)), c[i]) : T();
}
void add(i64 i, i64 x) {
if (i <= n) {
c[i] = f(c[i], x);
add(i + (i & -i), x);
}
}
};
template<class T, class F>
Fenwick<T, F> make_fenwick(i64 n, F f, T init = T()) {
return Fenwick<T, F>(n, f, init);
}
i64 n, q;
vector<i64> a;
int main() {
cin >> n >> q;
read_n(a, n);
Fenwick<i64> fen(n + 2);
set<i64> st;
for (i64 i = 1; i <= n; ++i) {
fen.add(i, a[i - 1]);
st.insert(i);
}
st.insert(n + 1);
while (q--) {
i64 c, x; cin >> c >> x;
if (c <= 2) {
auto r = st.find(x + 1);
if (c == 1 && r != end(st)) st.erase(x + 1);
if (c == 2 && r == end(st)) st.insert(x + 1);
} else if (c == 3) {
fen.add(x, 1);
} else {
auto r = st.lower_bound(x + 1), l = r;
--l;
// cout << *l << '\t' << *r << '\n';
cout << fen.sum(*r - 1) - fen.sum(*l - 1) << '\n';
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0