Skip to content

Commit 96e65a2

Browse files
committed
Alhamdulillah
1 parent db718d7 commit 96e65a2

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

Salary Queries.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#include <ext/pb_ds/assoc_container.hpp>
4+
using namespace __gnu_pbds;
5+
6+
// template <typename Key, typename Mapped, typename Compare, typename Tag,
7+
// typename Policy>
8+
// class tree;
9+
10+
#define ll long long
11+
typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag,
12+
tree_order_statistics_node_update>
13+
indexed_multiset;
14+
15+
int main() {
16+
ios::sync_with_stdio(false);
17+
cin.tie(0);
18+
ll n, ans, k, ind = 0;
19+
cin >> n >> k;
20+
ll x, y;
21+
22+
indexed_multiset ms;
23+
vector<ll> v(n);
24+
25+
for (ll i = 0; i < n; i++) {
26+
cin >> x;
27+
v[i] = x;
28+
ms.insert({x, i});
29+
}
30+
31+
vector<ll> vans;
32+
char ch;
33+
34+
for (ll i = 1; i <= k; i++) {
35+
cin >> ch;
36+
cin >> x >> y;
37+
if (ch == '!') {
38+
x--;
39+
ms.erase(ms.find({v[x], x}));
40+
ms.insert({y, x});
41+
v[x] = y;
42+
}
43+
if (ch == '?') {
44+
auto h = ms.upper_bound({y, LONG_LONG_MAX});
45+
auto l = ms.lower_bound({x, -1});
46+
ll high = h == ms.end() ? n : ms.order_of_key(*h);
47+
ll low = l == ms.end() ? n : ms.order_of_key(*l);
48+
ll ans = high - low;
49+
cout << ans << endl;
50+
}
51+
}
52+
53+
return 0;
54+
}

0 commit comments

Comments
 (0)