Submission #54464
ソースコード
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 | #include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) #define reps(i,n) for(int i=1;i<=(n);++i) #define all(x) (x).begin(),(x).end() //#define int long long #define mk_p(a,b) make_pair((a),(b)) #define fixed(n) fixed<<setprecision((n)) //using pii = pair<int,int>; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr long long MOD = 1000000007; int gcd( int a, int b){ return b ? gcd(b,a%b) : a;} int lcm( int a, int b){ return a/gcd(a,b)*b;} vector< long long > value; int N; void update( int i, long long x){ i += N - 1; value[i] = x; while (i > 0){ i = (i - 1) / 2; value[i] = value[i * 2 + 1] + value[i * 2 + 2]; } } long long getsum( int a, int b, int k, int l, int r){ if (r <= a || b <= l) return 0; if (a <= l && r <= b) return value[k]; else { long long c1 = getsum(a,b,2 * k + 1,l,(l + r) / 2); long long c2 = getsum(a,b,2 * k + 2,(l + r) / 2,r); return c1 + c2; } } signed main(){ cin.tie(0); ios::sync_with_stdio( false ); int n,q; cin >> n >> q; N = 1; while (N < n) N *= 2; value.resize(2 * N - 1,0); rep(i,q){ int a,b,s; cin >> s >> a >> b; if (s == 0) update(a-1,value[a-1 + N-1] + b); else cout << getsum(a-1,b,0,0,N) << '\n' ; } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0649 - 区間和(セグ木、BIT練習) |
ユーザー名 | ei1903 |
投稿日時 | 2019-09-08 11:13:48 |
言語 | C++14 |
状態 | Accepted |
得点 | 5 |
ソースコード長 | 1316 Byte |
最大実行時間 | 305 ms |
最大メモリ使用量 | 119000 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 5 / 5 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input100-1 | AC | 62 ms | 1500 KB |
1
|
input100-2 | AC | 66 ms | 4260 KB |
1
|
input100-3 | AC | 112 ms | 10096 KB |
1
|
input100-4 | AC | 198 ms | 22076 KB |
1
|
input100-5 | AC | 269 ms | 30084 KB |
1
|
input1000-1 | AC | 90 ms | 32204 KB |
1
|
input1000-2 | AC | 195 ms | 37256 KB |
1
|
input1000-3 | AC | 98 ms | 39492 KB |
1
|
input1000-4 | AC | 239 ms | 45688 KB |
1
|
input1000-5 | AC | 80 ms | 47540 KB |
1
|
input10000-1 | AC | 237 ms | 53484 KB |
1
|
input10000-2 | AC | 263 ms | 59832 KB |
1
|
input10000-3 | AC | 216 ms | 64640 KB |
1
|
input10000-4 | AC | 243 ms | 70340 KB |
1
|
input10000-5 | AC | 125 ms | 73220 KB |
1
|
input100000-1 | AC | 286 ms | 81480 KB |
1
|
input100000-2 | AC | 64 ms | 82448 KB |
1
|
input100000-3 | AC | 63 ms | 83416 KB |
1
|
input100000-4 | AC | 163 ms | 86560 KB |
1
|
input100000-5 | AC | 277 ms | 92392 KB |
1
|
input1000000-1 | AC | 59 ms | 107188 KB |
1
|
input1000000-2 | AC | 149 ms | 109432 KB |
1
|
input1000000-3 | AC | 171 ms | 111940 KB |
1
|
input1000000-4 | AC | 305 ms | 116880 KB |
1
|
input1000000-5 | AC | 158 ms | 119000 KB |
1
|
input1001000-1 | AC | 22 ms | 102560 KB |
1
|
input1001000-2 | AC | 17 ms | 102632 KB |
1
|
input1001000-3 | AC | 31 ms | 102576 KB |
1
|
input1001000-4 | AC | 18 ms | 102648 KB |
1
|
input1001000-5 | AC | 21 ms | 102724 KB |
1
|