結果
問題 |
No.1000 Point Add and Array Add
|
ユーザー |
![]() |
提出日時 | 2020-07-19 01:55:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 148 ms / 2,000 ms |
コード長 | 1,020 bytes |
コンパイル時間 | 3,161 ms |
コンパイル使用メモリ | 201,276 KB |
最終ジャッジ日時 | 2025-01-12 00:40:51 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> using namespace std; template<typename T> class FenwickTree { private: int n; vector<T> bit; public: FenwickTree(int sz) : n(sz + 1), bit(n, 0) {} void add(int i, T x) { i++; while (i < n) bit.at(i) += x, i += i & -i; } T sum(int i) { i++; T ret = 0; while (i > 0) ret += bit.at(i), i -= i & -i; return ret; } }; 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) { x--; if (c == 'A') ans.at(x) += (long) y * FT.sum(x); else FT.add(x, 1), FT.add(y, -1); } for (int i = 0; i < N; i++) { cout << ans.at(i) + (long) A.at(i) * FT.sum(i) << ((i == N - 1) ? "\n" : " "); } }