結果
| 問題 |
No.789 範囲の合計
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-16 19:31:10 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,247 bytes |
| コンパイル時間 | 1,633 ms |
| コンパイル使用メモリ | 163,324 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 08:21:17 |
| 合計ジャッジ時間 | 4,340 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 15 |
ソースコード
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
class SegTree {
public:
vector<ll> dat;
ll n, h;
SegTree(ll _n) {
n=1;
h=1;
while(_n>n) {
n*=2;
h++;
}
dat=vector<ll>(n*2-1);
}
void update(ll i, ll x) {
i+=n-1;
dat[i]+=x;
while(i>0) {
i=(i-1)/2;
dat[i]+=x;
}
}
ll _query(ll a, ll b, ll k, ll l, ll r) {
if(r<=a||b<=l) return 0;
if(a<=l&&r<=b) return dat[k];
else {
ll s=_query(a, b, k*2+1, l, (l+r)/2);
ll t=_query(a, b, k*2+2, (l+r)/2, r);
return s+t;
}
}
ll query(ll a, ll b) {
return _query(a, b, 0, 0, n);
}
};
int main(void) {
ll N;
cin >> N;
SegTree st(1e9);
ll ans=0;
for(ll i=0; i<N; i++) {
ll q, x, y;
cin >> q >> x >> y;
if(q==0) st.update(x, y);
if(q==1) ans+=st.query(x, y+1);
}
pt(ans);
}