結果

問題 No.789 範囲の合計
ユーザー eQeeQe
提出日時 2019-04-16 19:31:10
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,247 bytes
コンパイル時間 2,153 ms
コンパイル使用メモリ 163,916 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 07:10:38
合計ジャッジ時間 4,018 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
}
0