Skip to content

Commit cd2066f

Browse files
authored
Merge pull request #628 from AlgorithmWithGod/khj20006
[20250808] BOJ / P3 / 일기예보 / 권혁준
2 parents e0d2271 + db965ce commit cd2066f

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
```cpp
2+
#include <bits/stdc++.h>
3+
#include <ext/pb_ds/assoc_container.hpp>
4+
#include <ext/pb_ds/tree_policy.hpp>
5+
using namespace std;
6+
using namespace __gnu_pbds;
7+
8+
using ll = long long;
9+
using pbds = tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>;
10+
11+
pbds os;
12+
ll a[100001]{};
13+
int N, M;
14+
15+
void remove(ll v) {
16+
os.erase(os.find_by_order(os.order_of_key(v)));
17+
}
18+
19+
int main(){
20+
cin.tie(0)->sync_with_stdio(0);
21+
22+
cin>>N>>M;
23+
for(int i=1;i<=N;i++) {
24+
cin>>a[i];
25+
os.insert(a[i]);
26+
}
27+
28+
for(;M--;) {
29+
int o;
30+
cin>>o;
31+
if(o <= 2) {
32+
int i;
33+
ll x;
34+
cin>>i>>x;
35+
x *= o == 1 ? 1 : -1;
36+
remove(a[i]);
37+
a[i] += x;
38+
os.insert(a[i]);
39+
}
40+
else if(o == 3) {
41+
ll l, r;
42+
cin>>l>>r;
43+
cout<<os.order_of_key(r+1) - os.order_of_key(l)<<'\n';
44+
}
45+
else {
46+
int t;
47+
cin>>t;
48+
t = N-t+1;
49+
ll s = 0, e = 2e15, m = (s+e+1)>>1;
50+
while(s<e) {
51+
if(os.order_of_key(m) < t) s = m;
52+
else e = m-1;
53+
m = (s+e+1)>>1;
54+
}
55+
cout<<m<<'\n';
56+
}
57+
}
58+
59+
}
60+
```

0 commit comments

Comments
 (0)