Submission #69052
ソースコード
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 | #include<iostream> #include<algorithm> #include<vector> using namespace std; typedef long long lol; struct segment{ vector<lol> value; int N; segment( int n){ N=1; while (N<n){ N*=2; } value.resize(N*2); for ( int i=0;i<N*2;i++){ value[i]=0; } } void updata( int i,lol x){ i+=N-1; value[i]+=x; while (i>0){ i=(i-1)/2; value[i]=(value[i*2+1]+value[i*2+2]); } } lol quety( int a,lol b, int k, int l, int r){ if (r<=a||b<=l){ return (0); } if (a<=l&&r<=b){ return (value[k]); } else { lol c1=quety(a,b,2*k+1,l,(l+r)/2); lol c2=quety(a,b,2*k+2,(l+r)/2,r); return (c1+c2); } } lol get( int a,lol b){ return (quety(a,b+1,0,0,N)); } }; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio( false ); int n,q; cin>>n>>q; segment st(n); for ( int i=0;i<q;i++){ int a,c; lol b; cin>>c>>a>>b; if (c==0){ st.updata(a-1,b); } else { cout<<st.get(a-1,b-1)<< "\n" ; } } return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 0649 - 区間和(セグ木、BIT練習) |
ユーザー名 | ei2007 |
投稿日時 | 2021-11-17 20:06:03 |
言語 | C++17 |
状態 | Accepted |
得点 | 5 |
ソースコード長 | 1283 Byte |
最大実行時間 | 341 ms |
最大メモリ使用量 | 118212 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 5 / 5 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input100-1 | AC | 58 ms | 1500 KB |
1
|
input100-2 | AC | 86 ms | 4128 KB |
1
|
input100-3 | AC | 112 ms | 10088 KB |
1
|
input100-4 | AC | 186 ms | 22064 KB |
1
|
input100-5 | AC | 267 ms | 29436 KB |
1
|
input1000-1 | AC | 97 ms | 31428 KB |
1
|
input1000-2 | AC | 204 ms | 36480 KB |
1
|
input1000-3 | AC | 101 ms | 38716 KB |
1
|
input1000-4 | AC | 240 ms | 45044 KB |
1
|
input1000-5 | AC | 90 ms | 46892 KB |
1
|
input10000-1 | AC | 253 ms | 52840 KB |
1
|
input10000-2 | AC | 270 ms | 59188 KB |
1
|
input10000-3 | AC | 218 ms | 64124 KB |
1
|
input10000-4 | AC | 253 ms | 69700 KB |
1
|
input10000-5 | AC | 141 ms | 72460 KB |
1
|
input100000-1 | AC | 308 ms | 80848 KB |
1
|
input100000-2 | AC | 68 ms | 81684 KB |
1
|
input100000-3 | AC | 82 ms | 82652 KB |
1
|
input100000-4 | AC | 176 ms | 85796 KB |
1
|
input100000-5 | AC | 276 ms | 91880 KB |
1
|
input1000000-1 | AC | 62 ms | 106796 KB |
1
|
input1000000-2 | AC | 160 ms | 108784 KB |
1
|
input1000000-3 | AC | 185 ms | 111160 KB |
1
|
input1000000-4 | AC | 341 ms | 116216 KB |
1
|
input1000000-5 | AC | 156 ms | 118212 KB |
1
|
input1001000-1 | AC | 20 ms | 102024 KB |
1
|
input1001000-2 | AC | 20 ms | 101972 KB |
1
|
input1001000-3 | AC | 21 ms | 101920 KB |
1
|
input1001000-4 | AC | 20 ms | 101988 KB |
1
|
input1001000-5 | AC | 22 ms | 101936 KB |
1
|