-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbee1301.cpp
More file actions
81 lines (64 loc) · 1.52 KB
/
Copy pathbee1301.cpp
File metadata and controls
81 lines (64 loc) · 1.52 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
/*
* Contest : Beecrowd
* Problem : 1301 - Produto do Intervalo
* Link : https://judge.beecrowd.com/pt/problems/view/1301
*/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
vector<ll> bit, vet;
ll n, k;
void upd(ll i, ll v) {
for (; i <= n; i += (i & -i)) bit[i] += v;
}
pair<ll, ll> product(ll i) {
ll ans = 1, cnt = 0;
for (; i > 0; i -= (i & -i)) {
if (!bit[i]) cnt++;
}
return {ans, cnt};
}
int main() {
fastio
while (cin >> n >> k) {
vet.assign(n + 1, 0);
bit.assign(n + 1, 1);
for (int i = 1; i <= n; ++i) {
cin >> vet[i];
upd(i, vet[i]);
}
cerr << "\nbit: \n";
for (int i = 1; i <= n; ++i) { cerr << bit[i] << " "; }
cerr << "\n\n";
string ans = "";
while (k--) {
char op;
ll a, b;
cin >> op >> a >> b;
if (op == 'C') {
upd(a, b - vet[a]);
vet[a] = b;
cerr << "\nbit: \n";
for (int i = 1; i <= n; ++i) { cerr << bit[i] << " "; }
cerr << "\n\n";
}
else {
pair<ll, ll> retB = product(b),
retA = product(a - 1);
ll qntdZero = retB.S - retA.S;
cerr << "0 em B: " << retB.S << "; 0 em A: " << retA.S << endl;
ll ret = retB.F / retA.F;
cerr << "ret = " << ret << "\n";
if (qntdZero) ans += "0";
else {
ans += (ret > 0 ? "+" : "-");
}
}
}
cout << ans << "\n";
}
return 0;
}