Submission #62014
ソースコード
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | #include <bits/stdc++.h> using namespace std; #define __ <<" "<< #define ___ <<" " #define bash push_back #define ALL(x) x.begin(),x.end() // #define int long long using Int = int ; using ll = long long ; using pii = pair< int , int >; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr int SMOD = 1000000007; constexpr int NMOD = 998244353; constexpr int dx[]={1,0,-1,0,1,1,-1,-1}; constexpr int dy[]={0,-1,0,1,-1,1,-1,1}; inline bool inside( int x, int y, int w, int h){ return (x>=0 && y>=0 && x<w && y<h);} template < class T> bool chmax(T &a, const T&b){ if (a<b) return (a=b,1); return 0;} template < class T> bool chmin(T &a, const T&b){ if (b<a) return (a=b,1); return 0;} template < typename T> struct BIT { int n; vector<T> bit; BIT( int _n, T d = T(0)):n(_n+1), bit(_n+1, d) {} BIT( const BIT& b):n(b.n), bit(b.bit) {} T sum( int i) { //sum[1, i] T s = 0; for ( int x = i; x > 0; x -= x&-x) s += bit[x]; return s; } T sum( int l, int r) { // sum[l, r] return sum(r) - sum(l-1); } const int operator [] ( int pos) const { T sum = 0; for ( int i = pos; i > 0; i -= i & -i) sum += bit[i]; return sum; } void add( int i, T a) { if (!i) return ; for ( int x = i; x <= n; x += x&-x) bit[x] += a; } int lower_bound( int w) { if (w <= 0) return 0; int x = 0, r = 1; while (r < n) r <<= 1; for ( int k = r; k > 0; k >>= 1) { if (x + k <= n and bit[x + k] < w) { w -= bit[x + k]; x += k; } } return x + 1; } T sum0( int i) { return sum(i + 1);} T sum0( int l, int r) { return sum(l + 1, r + 1);} // sum[l, r] void add0( int i, T a) {add(i+1, a);} }; signed main() { int n, q; scanf ( "%d %d" , &n, &q); int a, b, c; BIT<int64_t> bit(n); while (q--) { scanf ( "%d %d %d" , &a, &b, &c); if (a) { printf ( "%lld\n" , bit.sum(b, c)); } else { bit.add(b, c); } } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0649 - 区間和(セグ木、BIT練習) |
ユーザー名 | ei1821 |
投稿日時 | 2020-08-13 09:50:52 |
言語 | C++17 |
状態 | Accepted |
得点 | 5 |
ソースコード長 | 2248 Byte |
最大実行時間 | 235 ms |
最大メモリ使用量 | 96268 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 5 / 5 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input100-1 | AC | 32 ms | 984 KB |
1
|
input100-2 | AC | 45 ms | 1848 KB |
1
|
input100-3 | AC | 77 ms | 4256 KB |
1
|
input100-4 | AC | 146 ms | 8836 KB |
1
|
input100-5 | AC | 208 ms | 16108 KB |
1
|
input1000-1 | AC | 89 ms | 18252 KB |
1
|
input1000-2 | AC | 161 ms | 23204 KB |
1
|
input1000-3 | AC | 77 ms | 25344 KB |
1
|
input1000-4 | AC | 194 ms | 31836 KB |
1
|
input1000-5 | AC | 86 ms | 33464 KB |
1
|
input10000-1 | AC | 194 ms | 39440 KB |
1
|
input10000-2 | AC | 201 ms | 45604 KB |
1
|
input10000-3 | AC | 167 ms | 50492 KB |
1
|
input10000-4 | AC | 179 ms | 56144 KB |
1
|
input10000-5 | AC | 102 ms | 58980 KB |
1
|
input100000-1 | AC | 235 ms | 66292 KB |
1
|
input100000-2 | AC | 52 ms | 67016 KB |
1
|
input100000-3 | AC | 48 ms | 68124 KB |
1
|
input100000-4 | AC | 125 ms | 71408 KB |
1
|
input100000-5 | AC | 194 ms | 77124 KB |
1
|
input1000000-1 | AC | 45 ms | 84632 KB |
1
|
input1000000-2 | AC | 105 ms | 87028 KB |
1
|
input1000000-3 | AC | 115 ms | 89424 KB |
1
|
input1000000-4 | AC | 196 ms | 94384 KB |
1
|
input1000000-5 | AC | 105 ms | 96268 KB |
1
|
input1001000-1 | AC | 26 ms | 88548 KB |
1
|
input1001000-2 | AC | 19 ms | 88524 KB |
1
|
input1001000-3 | AC | 18 ms | 88496 KB |
1
|
input1001000-4 | AC | 19 ms | 88592 KB |
1
|
input1001000-5 | AC | 20 ms | 88692 KB |
1
|