Submission #40661
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #include<bits/stdc++.h> using namespace std; #define ll long long #define FOR(i,n,m) for(int i=(n);i<(m);i++) #define REP(i,n) FOR(i,0,n) #define REPR(i,n) for(int i=(n);i>=0;i--) #define all(vec) vec.begin(),vec.end() using vi=vector< int >; using vvi=vector<vi>; using vl=vector<ll>; using vvl=vector<vl>; using P=pair<ll,ll>; using PP=pair<ll,P>; using vp=vector<P>; using vpp=vector<PP>; using vs=vector<string>; #define fi first #define se second #define pb push_back template < class T> bool chmax(T &a, const T &b){ if (a<b){a=b; return true ;} return false ;} template < class T> bool chmin(T &a, const T &b){ if (a>b){a=b; return true ;} return false ;} const ll MOD=1000000007LL; const int INF=1<<30; const ll LINF=1LL<<60; template < class T> struct BIT{ //0-indexed vector<T> data; BIT( int size){ data.assign(size+1,0); } T sum( int k){ //[0,k] T res=0; for (++k;k>0;k-=k&-k){ res+=data[k]; } return res; } T sum( int l, int r){ //[l,r]; return sum(r)-sum(l-1); } void add( int k,T x){ for (++k;k<data.size();k+=k&-k){ data[k]+=x; } } }; int main(){ int n,q; cin>>n>>q; BIT<ll> tree(n); REP(i,q){ int s; ll a,b; cin>>s>>a>>b; if (s){ a--;b--; cout<<tree.sum(a,b)<<endl; } else { a--; tree.add(a,b); } } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0649 - 区間和(セグ木、BIT練習) |
ユーザー名 | SugarDragon5 |
投稿日時 | 2018-08-04 20:46:24 |
言語 | C++17 |
状態 | Accepted |
得点 | 5 |
ソースコード長 | 1523 Byte |
最大実行時間 | 1370 ms |
最大メモリ使用量 | 96368 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 5 / 5 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input100-1 | AC | 96 ms | 864 KB |
1
|
input100-2 | AC | 237 ms | 1996 KB |
1
|
input100-3 | AC | 470 ms | 4276 KB |
1
|
input100-4 | AC | 947 ms | 8988 KB |
1
|
input100-5 | AC | 1370 ms | 16132 KB |
1
|
input1000-1 | AC | 455 ms | 18284 KB |
1
|
input1000-2 | AC | 1005 ms | 23240 KB |
1
|
input1000-3 | AC | 473 ms | 25380 KB |
1
|
input1000-4 | AC | 1275 ms | 31876 KB |
1
|
input1000-5 | AC | 398 ms | 33636 KB |
1
|
input10000-1 | AC | 1221 ms | 39488 KB |
1
|
input10000-2 | AC | 1292 ms | 45788 KB |
1
|
input10000-3 | AC | 1039 ms | 50676 KB |
1
|
input10000-4 | AC | 1204 ms | 56332 KB |
1
|
input10000-5 | AC | 600 ms | 59048 KB |
1
|
input100000-1 | AC | 1346 ms | 66236 KB |
1
|
input100000-2 | AC | 234 ms | 66968 KB |
1
|
input100000-3 | AC | 240 ms | 67952 KB |
1
|
input100000-4 | AC | 732 ms | 71368 KB |
1
|
input100000-5 | AC | 1205 ms | 77092 KB |
1
|
input1000000-1 | AC | 152 ms | 84728 KB |
1
|
input1000000-2 | AC | 516 ms | 86868 KB |
1
|
input1000000-3 | AC | 587 ms | 89396 KB |
1
|
input1000000-4 | AC | 1137 ms | 94224 KB |
1
|
input1000000-5 | AC | 513 ms | 96368 KB |
1
|
input1001000-1 | AC | 23 ms | 88532 KB |
1
|
input1001000-2 | AC | 23 ms | 88512 KB |
1
|
input1001000-3 | AC | 24 ms | 88488 KB |
1
|
input1001000-4 | AC | 22 ms | 88592 KB |
1
|
input1001000-5 | AC | 24 ms | 88440 KB |
1
|