結果
| 問題 | No.789 範囲の合計 | 
| コンテスト | |
| ユーザー |  YDK1727 | 
| 提出日時 | 2019-03-03 12:02:43 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 82 ms / 1,000 ms | 
| コード長 | 1,904 bytes | 
| コンパイル時間 | 1,790 ms | 
| コンパイル使用メモリ | 180,368 KB | 
| 実行使用メモリ | 7,348 KB | 
| 最終ジャッジ日時 | 2024-06-23 13:10:11 | 
| 合計ジャッジ時間 | 3,389 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 15 | 
ソースコード
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr>void dump(Itr begin, Itr end) {
  for(;begin != end; ++begin) clog << ' ' << *begin;
  clog << LF;
}
struct FenwickTree {
  const int N;
  vector<i64> dat;
  explicit FenwickTree(int n): N(n), dat(N+1, 0) {}
  i64  sum(int l, int r) { return sum(r) - sum(l-1); }
  i64  sum(int i)        { return (i>0)? (sum(i - (i&-i)) + dat[i]) : 0; }
  void add(int i, i64 v) { for(; i <= N; i += i&-i) dat[i] += v; }
};
using P = tuple<int, int, int>;
int N;
P query[100100];
vector<int> points;
inline int index(int orgIndex) { return lower_bound(ALL(points), orgIndex) - points.begin(); }
signed main()
{
  iostreamBooster();
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int a, b, c; cin >> a >> b >> c;
    query[i] = make_tuple(a, b, c);
    if (a) {
      points.push_back(b);
      points.push_back(b-1);
    } else {
      points.push_back(b);
      points.push_back(c);
      points.push_back(b-1);
      points.push_back(c-1);
    }
  }
  points.push_back(0);
  points.push_back(-1);
  points.push_back(1'000'000'001);
  sort(ALL(points));
  points.erase(unique(ALL(points)), points.end());
  FenwickTree ft(points.size() + 5);
  i64 ans = 0;
  for (int i = 0; i < N; ++i) {
    int com, a, b;
    tie(com, a, b) = query[i];
    if (com == 0) {
      ft.add(index(a), b);
    } else {
      const i64 tmp = ft.sum(index(a), index(b));
      ans += tmp;
    }
  }
  cout << ans << endl;
  return 0;
}
            
            
            
        