結果

問題 No.789 範囲の合計
ユーザー mint6421mint6421
提出日時 2019-09-06 16:33:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 268 ms / 1,000 ms
コード長 2,151 bytes
コンパイル時間 2,139 ms
コンパイル使用メモリ 213,176 KB
実行使用メモリ 19,852 KB
最終ジャッジ日時 2023-09-06 05:37:03
合計ジャッジ時間 5,617 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 233 ms
18,580 KB
testcase_03 AC 45 ms
6,312 KB
testcase_04 AC 217 ms
18,072 KB
testcase_05 AC 142 ms
19,656 KB
testcase_06 AC 161 ms
18,704 KB
testcase_07 AC 36 ms
6,276 KB
testcase_08 AC 106 ms
11,772 KB
testcase_09 AC 95 ms
9,988 KB
testcase_10 AC 268 ms
19,852 KB
testcase_11 AC 176 ms
18,400 KB
testcase_12 AC 173 ms
18,400 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define PP pair<int,P>



template< typename Monoid >
struct segTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  segTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] += x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid get(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};

int n;
map<int,int> mp;
vector<PP> v;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin>>n;
  rep(i,n){
    int a,b,c;
    cin>>a>>b>>c;
    v.PB(PP(a,P(b,c)));
    mp[b]=0;
    if(a==1) mp[c]=0;
  }

  int c=0;
  for(P p:mp){
    mp[p.F]=c++;
  }

  int ans=0;
  segTree<int> seg(c,[](int a,int b){return a+b;},0);
  rep(i,n){
    int x=mp[v[i].S.F];
    //cout<<x<<' '<<y<<endl;
    if(v[i].F==0){
      seg.update(x,v[i].S.S);
    }else{
      int y=mp[v[i].S.S];
      ans+=seg.get(x,y+1);
      //cout<<ans<<endl;
   }
  }

  cout<<ans<<endl;


}
0