結果
| 問題 |
No.1000 Point Add and Array Add
|
| コンテスト | |
| ユーザー |
ninoinui
|
| 提出日時 | 2020-07-19 01:47:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 104 ms / 2,000 ms |
| コード長 | 1,909 bytes |
| コンパイル時間 | 2,113 ms |
| コンパイル使用メモリ | 202,048 KB |
| 最終ジャッジ日時 | 2025-01-12 00:40:25 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<typename T> class FenwickTree {
private:
int n, mx;
vector<T> bit;
public:
FenwickTree(int sz) : n(sz + 1), mx(1), bit(n, 0) {
while (mx * 2 <= n) mx *= 2;
}
FenwickTree(const vector<T> &v) : n((int) v.size() + 1), mx(1), bit(n, 0) {
for (int i = 0; i < n - 1; i++) add(i, v.at(i));
while (mx * 2 <= n) mx *= 2;
}
void add(int i, T x) {
i++;
while (i < n) bit.at(i) += x, i += i & -i;
}
void add(int l, int r, T x) {
add(l, x);
add(r + 1 , -x);
}
T sum(int i) {
i++;
T ret = 0;
while (i > 0) ret += bit.at(i), i -= i & -i;
return ret;
}
T sum(int l, int r) {
return sum(r) - sum(l - 1);
}
int lower_bound(T w) {
if (w <= 0) return 0;
int x = 0;
for (int k = mx; k > 0; k /= 2) {
if (x + k <= n - 1 && bit.at(x + k) < w) {
w -= bit.at(x + k);
x += k;
}
}
return x;
}
int upper_bound(T w) {
if (w < 0) return 0;
int x = 0;
for (int k = mx; k > 0; k /= 2) {
if (x + k <= n - 1 && bit.at(x + k) <= w) {
w -= bit.at(x + k);
x += k;
}
}
return x;
}
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, Q;
cin >> N >> Q;
vector<int> A(N);
for (int i = 0; i < N; i++) cin >> A.at(i);
vector<tuple<char, int, int>> V(Q);
for (int i = 0; i < Q; i++) {
char c;
int x, y;
cin >> c >> x >> y;
V.at(i) = {c, x, y};
}
reverse(V.begin(), V.end());
vector<long> ans(N);
FenwickTree<long> FT(N);
for (auto [c, x, y] : V) {
if (c == 'A') {
x--;
ans.at(x) += (long) y * FT.sum(x);
} else {
x--, y--;
FT.add(x, y, 1);
}
}
for (int i = 0; i < N; i++) {
ans.at(i) += (long) A.at(i) * FT.sum(i);
}
for (int i = 0; i < N; i++) {
cout << ans.at(i) << ((i == N - 1) ? "\n" : " ");
}
}
ninoinui