結果
問題 | No.789 範囲の合計 |
ユーザー |
![]() |
提出日時 | 2019-02-08 22:07:44 |
言語 | C++11 (gcc 8.5.0) |
結果 |
AC
|
実行時間 | 188 ms / 1,000 ms |
コード長 | 2,096 bytes |
コンパイル時間 | 838 ms |
使用メモリ | 34,652 KB |
最終ジャッジ日時 | 2023-02-01 16:42:46 |
合計ジャッジ時間 | 3,535 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,904 KB |
testcase_01 | AC | 2 ms
4,904 KB |
testcase_02 | AC | 177 ms
28,608 KB |
testcase_03 | AC | 83 ms
6,948 KB |
testcase_04 | AC | 188 ms
31,896 KB |
testcase_05 | AC | 158 ms
27,456 KB |
testcase_06 | AC | 162 ms
28,708 KB |
testcase_07 | AC | 79 ms
6,948 KB |
testcase_08 | AC | 171 ms
34,652 KB |
testcase_09 | AC | 156 ms
31,948 KB |
testcase_10 | AC | 156 ms
20,204 KB |
testcase_11 | AC | 142 ms
28,320 KB |
testcase_12 | AC | 144 ms
28,264 KB |
testcase_13 | AC | 2 ms
4,900 KB |
testcase_14 | AC | 1 ms
6,948 KB |
ソースコード
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> #include<functional> using namespace std; #define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i ) #define rep(i,n) REP(i,0,n) typedef long long ll; typedef pair<int,int> pint; typedef pair<ll,int> pli; const int inf=1e9+7; const ll longinf=1LL<<60 ; const ll mod=1e9+7 ; template<typename T> struct SegmentTree{ struct Node{ T val; Node *lch,*rch; Node(T val):val(val),lch(nullptr),rch(nullptr){} }; Node *root; ll sz; T id; T f(T x,T y){ //return max(x,y); //return min(x,y); return x+y; //return {x.first*y.first, y.first*x.second + y.second}; } T g(T x,T y){ //return x; return x+y; } T val(Node* t){return t ? t->val : id;} SegmentTree(ll sz_,T id_=0):root(nullptr),id(id_){ sz=1; while(sz<sz_)sz*=2; } Node* update(Node* t,ll k, ll l, ll r, T x){ //assert(l<=k&&k<r); if(!t)t=new Node(id); if(r-l==1){ t->val=g(x,t->val); return t; } if(k<(l+r)/2)t->lch=update(t->lch,k, l, (l+r)>>1, x); else t->rch=update(t->rch,k, (l+r)>>1, r, x); t->val=f(val(t->lch), val(t->rch)); return t; } T get(Node* t, ll a,ll b,ll l, ll r){ if(!t)return id; if(b<=l||r<=a)return id; if(a<=l&&r<=b)return t->val; T lx=get(t->lch, a, b, l, (l+r)>>1); T rx=get(t->rch, a, b, (l+r)>>1, r); return f(lx,rx); } void update(ll k,T x){ root = update(root, k, 0, sz, x); } T get(ll a, ll b){ return get(root, a, b, 0, sz); } }; typedef pair<double,double> P; int main(){ int n; cin>>n; SegmentTree<ll> sg(inf); ll ans=0; rep(i,n){ int a,b,c; cin>>a>>b>>c; if(a){ ans+=sg.get(b,c+1); } else { sg.update(b,c); } } cout<<ans<<endl; return 0; }