Submission #62008


ソースコード

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
#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;
int a, b, c;
BIT<int64_t> bit(n);
while(q--) {
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:37:53
言語 C++17
状態 Accepted
得点 5
ソースコード長 2412 Byte
最大実行時間 1072 ms
最大メモリ使用量 96528 KB

セット

セット 得点 Cases
1 ALL 5 / 5 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
input100-1 AC 85 ms 984 KB
1
input100-2 AC 183 ms 1828 KB
1
input100-3 AC 364 ms 4212 KB
1
input100-4 AC 697 ms 8896 KB
1
input100-5 AC 1072 ms 16144 KB
1
input1000-1 AC 335 ms 18140 KB
1
input1000-2 AC 764 ms 23072 KB
1
input1000-3 AC 365 ms 25452 KB
1
input1000-4 AC 946 ms 31796 KB
1
input1000-5 AC 296 ms 33656 KB
1
input10000-1 AC 868 ms 39488 KB
1
input10000-2 AC 951 ms 45636 KB
1
input10000-3 AC 755 ms 50504 KB
1
input10000-4 AC 848 ms 56140 KB
1
input10000-5 AC 443 ms 58952 KB
1
input100000-1 AC 986 ms 66120 KB
1
input100000-2 AC 172 ms 67080 KB
1
input100000-3 AC 177 ms 68040 KB
1
input100000-4 AC 516 ms 71428 KB
1
input100000-5 AC 879 ms 76992 KB
1
input1000000-1 AC 120 ms 84604 KB
1
input1000000-2 AC 373 ms 86972 KB
1
input1000000-3 AC 417 ms 89472 KB
1
input1000000-4 AC 787 ms 94408 KB
1
input1000000-5 AC 368 ms 96528 KB
1
input1001000-1 AC 21 ms 88532 KB
1
input1001000-2 AC 21 ms 88612 KB
1
input1001000-3 AC 22 ms 88564 KB
1
input1001000-4 AC 20 ms 88520 KB
1
input1001000-5 AC 18 ms 88600 KB
1