-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathllyaTheQ.cpp
More file actions
executable file
·114 lines (101 loc) · 2.65 KB
/
llyaTheQ.cpp
File metadata and controls
executable file
·114 lines (101 loc) · 2.65 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define endl '\n'
#define int long long int
using namespace std;
#define pii pair <int, int>
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define Loop(s, e, itr) for (int itr = s; itr < e; itr++)
#define loop(n) for(int i = 0; i < n; i++)
#define vin vector<int>
#define w(t) int tc; cin >> tc; for(int t = 1; t <= tc; t++)
#define vec vector
class fenwich{
private:
int parent(int a){
int b = (~a+1)&a;
return a-b;
}
int next(int a){
int b = (~a+1)&a;
return a+b;
}
void add_at(int val, int ind){
tree[++ind] += val;
ind = next(ind);
int m = tree.size();
while(ind < m){
tree[ind] += val;
ind = next(ind);
}
}
public:
vin tree;
vin arr;
fenwich(vin arr){
this->arr = arr;
int n = arr.size();
tree = vin(n + 1, 0);
int temp;
loop(n){
tree[i+1] += arr[i];
temp = next(i+1);
while(temp <= n){
tree[temp] += arr[i];
temp = next(temp);
}
}
}
void update(int val, int ind){
add_at(val-arr[ind], ind);
}
int sum(int a){
int ans = tree[++a];
a = parent(a);
while(a){
ans += tree[a];
a = parent(a);
}
return ans;
}
int sum(int a, int b){
return sum(b)-sum(a-1);
}
};
int32_t main1(){
int n;
cin >> n;
vin arr(n);
loop(n) cin >> arr[i];
fenwich f(arr);
for(auto i : f.tree) cout << i << " "; cout << endl;
int q;
cin >> q;
int a;
while(q--){
cin >> a;
cout << f.sum(a) << endl;
}
}
int32_t main(){
string str;
cin >> str;
int len = str.length();
vin arr(len);
loop(len-1) arr[i+1] = str[i] == str[i+1] ? 1 : 0;
// Loop(0, len, i) cout << arr[i] << " "; cout << endl;
fenwich f(arr);
// for(auto i : arr) cout << i << " "; cout << endl;
// for(auto i : f.tree) cout << i << " "; cout << endl;
int q;
cin >> q;
int a, b;
while(q--){
cin >> a >> b;
cout << f.sum(b-1) - f.sum(a-1) << endl;
}
}