結果
問題 | No.1000 Point Add and Array Add |
ユーザー | merom686 |
提出日時 | 2020-02-28 21:49:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 85 ms / 2,000 ms |
コード長 | 1,079 bytes |
コンパイル時間 | 778 ms |
コンパイル使用メモリ | 78,064 KB |
実行使用メモリ | 7,168 KB |
最終ジャッジ日時 | 2024-10-13 17:14:51 |
合計ジャッジ時間 | 3,322 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #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; } int sum(int k) { int s = 0; for (; k > 0; k -= k & -k) s += b[k]; return s; } vector<int> b; int n; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector<ll> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } BIT bt(n + 1); for (int h = 0; h < q; h++) { char c; int x, y; cin >> c >> x >> y; x--; if (c == 'A') { a[x] += y; b[x] += (ll)y * bt.sum(x + 1); } else { bt.add(x, +1); bt.add(y, -1); } } for (int i = 0; i < n; i++) { cout << a[i] * bt.sum(i + 1) - b[i] << " \n"[i == n - 1]; } return 0; }