Submission #62007
ソースコード
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 93 94 95 96 97 98 99 100 101 | #include <bits/stdc++.h> using namespace std; #define __ <<" "<< #define ___ <<" " #define bash push_back #define ALL(x) x.begin(),x.end() // #define int long long struct IoSetup { IoSetup() { cin.tie(0); ios::sync_with_stdio( false ); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } }IoSetup; 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; cin >> n >> q; BIT<int64_t> bit(n); while (q--) { int a, b, c; cin >> a >> b >> c; if (a) { cout << bit.sum(b, c) << endl; } else { bit.add(b, c); } } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0649 - 区間和(セグ木、BIT練習) |
ユーザー名 | ei1821 |
投稿日時 | 2020-08-13 09:36:10 |
言語 | C++17 |
状態 | Accepted |
得点 | 5 |
ソースコード長 | 2418 Byte |
最大実行時間 | 1098 ms |
最大メモリ使用量 | 96272 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 5 / 5 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input100-1 | AC | 76 ms | 860 KB |
1
|
input100-2 | AC | 180 ms | 1840 KB |
1
|
input100-3 | AC | 375 ms | 4096 KB |
1
|
input100-4 | AC | 734 ms | 8908 KB |
1
|
input100-5 | AC | 1098 ms | 16024 KB |
1
|
input1000-1 | AC | 348 ms | 18148 KB |
1
|
input1000-2 | AC | 940 ms | 23212 KB |
1
|
input1000-3 | AC | 371 ms | 25584 KB |
1
|
input1000-4 | AC | 982 ms | 31928 KB |
1
|
input1000-5 | AC | 302 ms | 33784 KB |
1
|
input10000-1 | AC | 866 ms | 39484 KB |
1
|
input10000-2 | AC | 945 ms | 45756 KB |
1
|
input10000-3 | AC | 752 ms | 50616 KB |
1
|
input10000-4 | AC | 855 ms | 56120 KB |
1
|
input10000-5 | AC | 480 ms | 58936 KB |
1
|
input100000-1 | AC | 1010 ms | 66108 KB |
1
|
input100000-2 | AC | 168 ms | 67064 KB |
1
|
input100000-3 | AC | 176 ms | 68148 KB |
1
|
input100000-4 | AC | 516 ms | 71540 KB |
1
|
input100000-5 | AC | 864 ms | 77112 KB |
1
|
input1000000-1 | AC | 117 ms | 84728 KB |
1
|
input1000000-2 | AC | 373 ms | 86844 KB |
1
|
input1000000-3 | AC | 429 ms | 89348 KB |
1
|
input1000000-4 | AC | 795 ms | 94284 KB |
1
|
input1000000-5 | AC | 358 ms | 96272 KB |
1
|
input1001000-1 | AC | 22 ms | 88412 KB |
1
|
input1001000-2 | AC | 17 ms | 88488 KB |
1
|
input1001000-3 | AC | 24 ms | 88568 KB |
1
|
input1001000-4 | AC | 21 ms | 88648 KB |
1
|
input1001000-5 | AC | 17 ms | 88724 KB |
1
|