結果
| 問題 |
No.1000 Point Add and Array Add
|
| コンテスト | |
| ユーザー |
batsumaru
|
| 提出日時 | 2020-02-28 23:36:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 244 ms / 2,000 ms |
| コード長 | 1,423 bytes |
| コンパイル時間 | 1,495 ms |
| コンパイル使用メモリ | 173,020 KB |
| 実行使用メモリ | 17,280 KB |
| 最終ジャッジ日時 | 2024-10-13 19:20:16 |
| 合計ジャッジ時間 | 5,207 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())
// 1-indexed
class BIT {
public:
vector<ll> bit;
ll M;
BIT(ll M) : bit(vector<ll>(M + 1, 0)), M(M) {}
// a[1] + a[2] + ... + a[i]を求める
ll sum(ll i) {
if (i == 0) return 0;
return bit[i] + sum(i - (i & -i));
}
// a[i] += x
void add(ll i, ll x) {
if (i > M) return;
bit[i] += x;
add(i + (i & -i), x);
}
};
int main() {
ll n, q;
cin >> n >> q;
vector<ll> a(n);
REP(i, n) { cin >> a[i]; }
// 1-indexed
vector<ll> b(n + 1, 0);
vector<pair<string, P>> sxy(q);
REP(i, q) {
string s;
ll x, y;
cin >> sxy[i].first >> sxy[i].second.first >> sxy[i].second.second;
}
BIT bit(n);
IREP(i, q) {
string s = sxy[i].first;
ll x = sxy[i].second.first;
ll y = sxy[i].second.second;
if (s == "A") {
b[x] += y * (bit.sum(x));
} else {
bit.add(x, 1);
if (y + 1 <= n) bit.add(y + 1, -1);
}
}
REP(i, n) { b[i + 1] += a[i] * (bit.sum(i + 1)); }
REP(i, n) { cout << b[i + 1] << " \n"[i == n - 1]; }
}
batsumaru