結果
| 問題 | No.789 範囲の合計 |
| コンテスト | |
| ユーザー |
veqcc
|
| 提出日時 | 2019-02-13 14:50:23 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,063 bytes |
| 記録 | |
| コンパイル時間 | 517 ms |
| コンパイル使用メモリ | 104,852 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-04 04:35:17 |
| 合計ジャッジ時間 | 1,188 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 15 |
ソースコード
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;
const int MAX_N = 1000000000;
ll bit[MAX_N + 1];
// iが与えられた時に、a[1]+a[2]+...+a[i]を計算する
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i; // 最後の1ビット
}
return s;
}
// iとxが与えられた時に、a[i]にxを足す
void add(int i, int x) {
while (i <= MAX_N) {
bit[i] += x;
i += i & -i;
}
}
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
ll sm = 0LL;
for (int i = 0; i < n; i++) {
int a, x, y;
cin >> a >> x >> y;
if (a == 0) {
x++;
add(x, y);
} else {
x++; y++;
sm += (ll)(sum(y) - sum(x-1));
}
}
cout << sm << "\n";
return 0;
}
veqcc