結果
| 問題 |
No.1000 Point Add and Array Add
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2020-02-29 23:59:06 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 112 ms / 2,000 ms |
| コード長 | 1,540 bytes |
| コンパイル時間 | 719 ms |
| コンパイル使用メモリ | 93,580 KB |
| 実行使用メモリ | 7,628 KB |
| 最終ジャッジ日時 | 2024-10-13 20:22:34 |
| 合計ジャッジ時間 | 3,480 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 1000.cc: No.1000 Point Add and Array Add - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 200000;
/* typedef */
typedef long long ll;
template <typename T, const int MAX_N>
struct BIT {
int n;
T bits[MAX_N + 1];
BIT() {}
BIT(int _n) { init(_n); }
void init(int _n) {
n = _n;
memset(bits, 0, sizeof(bits));
}
T sum(int x) {
T s = 0;
while (x > 0) {
s += bits[x];
x -= (x & -x);
}
return s;
}
void add(int x, T v) {
while (x <= n) {
bits[x] += v;
x += (x & -x);
}
}
};
/* global variables */
ll as[MAX_N], sbs[MAX_N];
BIT<int,MAX_N+1> bit;
/* subroutines */
/* main */
int main() {
int n, q;
scanf("%d%d", &n, &q);
for (int i = 0; i < n; i++) scanf("%lld", as + i);
bit.init(n + 1);
while (q--) {
char s[4];
int x, y;
scanf("%s%d%d", s, &x, &y);
if (s[0] == 'A') {
x--;
as[x] += y;
sbs[x] += (ll)y * bit.sum(x + 1);
}
else {
bit.add(x, 1);
bit.add(y + 1, -1);
}
}
for (int i = 0; i < n; i++) {
if (i) putchar(' ');
printf("%lld", as[i] * bit.sum(i + 1) - sbs[i]);
}
putchar('\n');
return 0;
}
tnakao0123