Skip to content

Commit eaf55e5

Browse files
authored
[20251125] BOJ / P4 / 쓰담쓰담 / 권혁준
1 parent 42836d3 commit eaf55e5

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
```cpp
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
int N, Q;
6+
int seg[262144]{}, height[100001]{};
7+
8+
void upt(int s, int e, int i, int n) {
9+
if(s == e) {
10+
if(s == N || height[s] <= height[s+1]) seg[n] = 0;
11+
else seg[n] = 1;
12+
return;
13+
}
14+
int m = (s+e)>>1;
15+
if(i <= m) upt(s,m,i,n<<1);
16+
else upt(m+1,e,i,n<<1|1);
17+
seg[n] = seg[n<<1] + seg[n<<1|1];
18+
}
19+
20+
int find(int s, int e, int l, int r, int n) {
21+
if(l>r || l>e || r<s) return 0;
22+
if(l<=s && e<=r) return seg[n];
23+
int m = (s+e)>>1;
24+
return find(s,m,l,r,n<<1) + find(m+1,e,l,r,n<<1|1);
25+
}
26+
27+
int main(){
28+
cin.tie(0)->sync_with_stdio(0);
29+
30+
cin>>N>>Q;
31+
for(int i=1;i<=N;i++) cin>>height[i];
32+
for(int i=1;i<=N;i++) upt(1,N,i,1);
33+
34+
for(int o,l,r;Q--;) {
35+
cin>>o>>l>>r;
36+
if(o == 1) cout<<(find(1,N,l,r-1,1) ? "HSS090\n": "CS204\n");
37+
else {
38+
swap(height[l], height[r]);
39+
if(l>1) upt(1,N,l-1,1);
40+
upt(1,N,l,1);
41+
if(r>1) upt(1,N,r-1,1);
42+
upt(1,N,r,1);
43+
}
44+
}
45+
46+
}
47+
```

0 commit comments

Comments
 (0)