Submission #62011


ソースコード

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
#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 Monoid >
struct SegmentTree {
using F = function< Monoid(Monoid, Monoid) >;
int sz;
vector< Monoid > seg;
const F f;
const Monoid M1;
SegmentTree(int n, const Monoid &M1, const F f) : f(f), M1(M1) {
sz = 1;
while(sz < n) sz <<= 1;
seg.assign(2 * sz, M1);
}
void set(int k, const Monoid &x) {
seg[k + sz] = x;
}
void build() {
for(int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while(k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if(a & 1) L = f(L, seg[a++]);
if(b & 1) R = f(seg[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const {
return seg[k + sz];
}
};
signed main() {
int n, q;
cin >> n >> q;
SegmentTree<int64_t> seg(n, 0, [](int64_t a, int64_t b){return a + b;});
while(q--) {
int a, b, c;
cin >> a >> b >> c;
if(a) {
cout << seg.query(b-1, c) << endl;
}
else {
seg.update(b-1, seg[b-1] + c);
}
}
return 0;
}

ステータス

項目 データ
問題 0649 - 区間和(セグ木、BIT練習)
ユーザー名 ei1821
投稿日時 2020-08-13 09:40:06
言語 C++17
状態 Accepted
得点 5
ソースコード長 2236 Byte
最大実行時間 1117 ms
最大メモリ使用量 105024 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
input100-1 AC 86 ms 988 KB
1
input100-2 AC 183 ms 2092 KB
1
input100-3 AC 361 ms 4348 KB
1
input100-4 AC 715 ms 8904 KB
1
input100-5 AC 1117 ms 16024 KB
1
input1000-1 AC 355 ms 18276 KB
1
input1000-2 AC 797 ms 23200 KB
1
input1000-3 AC 372 ms 25444 KB
1
input1000-4 AC 1015 ms 31776 KB
1
input1000-5 AC 321 ms 33632 KB
1
input10000-1 AC 924 ms 39588 KB
1
input10000-2 AC 1014 ms 45804 KB
1
input10000-3 AC 795 ms 50872 KB
1
input10000-4 AC 903 ms 56456 KB
1
input10000-5 AC 481 ms 59220 KB
1
input100000-1 AC 1074 ms 67488 KB
1
input100000-2 AC 177 ms 68456 KB
1
input100000-3 AC 191 ms 69420 KB
1
input100000-4 AC 558 ms 72696 KB
1
input100000-5 AC 946 ms 78408 KB
1
input1000000-1 AC 136 ms 93332 KB
1
input1000000-2 AC 409 ms 95456 KB
1
input1000000-3 AC 468 ms 97964 KB
1
input1000000-4 AC 901 ms 103032 KB
1
input1000000-5 AC 405 ms 105024 KB
1
input1001000-1 AC 19 ms 88584 KB
1
input1001000-2 AC 21 ms 88536 KB
1
input1001000-3 AC 17 ms 88608 KB
1
input1001000-4 AC 19 ms 88688 KB
1
input1001000-5 AC 21 ms 88760 KB
1