結果
問題 | No.833 かっこいい電車 |
ユーザー |
![]() |
提出日時 | 2019-05-24 23:32:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 172 ms / 2,000 ms |
コード長 | 1,937 bytes |
コンパイル時間 | 1,258 ms |
コンパイル使用メモリ | 117,268 KB |
実行使用メモリ | 8,832 KB |
最終ジャッジ日時 | 2024-07-02 03:47:40 |
合計ジャッジ時間 | 4,823 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
/* ---------- STL Libraries ---------- */// IO library#include <cstdio>#include <fstream>#include <iomanip>#include <ios>#include <iostream>// algorithm library#include <algorithm>#include <cmath>#include <numeric>#include <random>#include <cstring>// container library#include <array>#include <bitset>#include <deque>#include <map>#include <unordered_map>#include <queue>#include <set>#include <string>#include <tuple>#include <vector>#include <stack>/* ---------- Namespace ---------- */using namespace std;/* ---------- Type ---------- */using ll = long long;#define int ll#define P pair<ll, ll>/* ---------- Constants */const double PI = 3.141592653589793238462643383279;const ll MOD = 1e9 + 7;const int INF = 1LL << 55;/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */const int MAX_N = 200000;int bit[MAX_N + 1], n;int sum(int i) {int s = 0;while (i > 0) {s += bit[i];i -= i & -i;}return s;}void add_to(int i, int x) {while (i <= n) {bit[i] += x;i += i & -i;}}signed main() {int q;cin >> n >> q;vector<int> S(n + 1, 0);for (int i = 0; i < n; i++) {cin >> S[i + 1];S[i + 1] += S[i];}set<int> st;for (int i = 0; i <= n - 1; i++) st.insert(i);for (int i = 0; i < q; i++) {int query, x;cin >> query >> x;if (query == 1) {auto it = st.find(x);if (it != st.end()) {st.erase(it);}} else if (query == 2) {st.insert(x);} else if (query == 3) {add_to(x, 1);} else {auto it = st.lower_bound(x);int upper = (it == st.end()) ? n : *it;it--;int lower = *it + 1;cout << S[upper] - S[lower - 1] + sum(upper) - sum(lower - 1) << endl;}}return 0;}