-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSalaryQueries.cpp
More file actions
62 lines (51 loc) · 1.24 KB
/
SalaryQueries.cpp
File metadata and controls
62 lines (51 loc) · 1.24 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
//Salary Queries - https://cses.fi/problemset/task/1144
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less_equal<>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
void solve() {
int n, q;
cin >> n >> q;
vector<int> p(n);
indexed_set st;
map<int, int> mp; //emp -> salary
for (int i = 0; i < n; i++) {
cin >> p[i];
mp[i] = p[i];
st.insert(p[i]);
}
for (int i = 0; i < q; i++) {
char op;
cin >> op;
if (op == '!') {
int k, x;
cin >> k >> x;
k--;
int prev_salary = mp[k];
st.erase(st.lower_bound(prev_salary - 1));
st.insert(x);
mp[k] = x;
} else if (op == '?') {
int a, b;
cin >> a >> b;
cout << st.order_of_key(b + 1) - st.order_of_key(a) << '\n';
} else {
assert(false);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}