結果
| 問題 |
No.833 かっこいい電車
|
| コンテスト | |
| ユーザー |
merom686
|
| 提出日時 | 2019-05-24 22:18:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 68 ms / 2,000 ms |
| コード長 | 1,684 bytes |
| コンパイル時間 | 847 ms |
| コンパイル使用メモリ | 88,776 KB |
| 実行使用メモリ | 8,576 KB |
| 最終ジャッジ日時 | 2024-07-02 03:42:30 |
| 合計ジャッジ時間 | 2,982 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
struct BIT {
BIT(int n) : b(n + 1), n(n) {}
void add(int i, int v) {
for (int k = i + 1; k <= n; k += k & -k) b[k] += v;
}
ll sum(int k) {
ll s = 0;
for (; k > 0; k -= k & -k) s += b[k];
return s;
}
vector<ll> b;
int n;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
BIT bt(n);
map<int, int> mp;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
bt.add(i, a);
mp.insert(mp.end(), make_pair(i, i + 1));
}
for (int h = 0; h < q; h++) {
int t, x;
cin >> t >> x;
x--;
if (t == 1) {
auto it = mp.upper_bound(x); it--;
if (x + 1 < it->second) continue;
int i0 = it->first;
it = mp.erase(it);
int i1 = it->second;
it = mp.erase(it);
mp.insert(it, make_pair(i0, i1));
} else if (t == 2) {
auto it = mp.upper_bound(x); it--;
if (x + 1 >= it->second) continue;
int i0 = it->first;
int i1 = it->second;
it = mp.erase(it);
mp.insert(it, make_pair(i0, x + 1));
mp.insert(it, make_pair(x + 1, i1));
} else if (t == 3) {
bt.add(x, 1);
} else if (t == 4) {
auto it = mp.upper_bound(x); it--;
cout << bt.sum(it->second) - bt.sum(it->first) << '\n';
}
}
return 0;
}
merom686