File tree Expand file tree Collapse file tree 1 file changed +35
-6
lines changed Expand file tree Collapse file tree 1 file changed +35
-6
lines changed Original file line number Diff line number Diff line change 1
- // Authored by : BaaaaaaaaaaarkingDog
2
- // Co-authored by : -
3
- // http://boj.kr/****************
1
+ // Authored by : 0000000000
2
+ // Co-authored by : BaaaaaaaaaaarkingDog
3
+ // http://boj.kr/deab7ddf836140578b02643f3f13afb1
4
4
#include < bits/stdc++.h>
5
5
using namespace std ;
6
+ using ll = long long ;
6
7
7
- int main (void ){
8
+ int h[250005 ];
9
+ set<int > s;
10
+ ll res;
11
+ int main () {
8
12
ios::sync_with_stdio (0 );
9
13
cin.tie (0 );
10
-
11
- }
14
+
15
+ int n; cin >> n;
16
+ h[0 ] = 0 ; s.insert (0 );
17
+ h[n + 1 ] = 0 ; s.insert (n + 1 );
18
+
19
+ n--;
20
+ int a; cin >> a; a++;
21
+ h[a] = 1 ; s.insert (a);
22
+ res = 1 ;
23
+
24
+ while (n--) {
25
+ cin >> a; a++;
26
+ auto it = s.lower_bound (a);
27
+ h[a] = max (h[*prev (it)], h[*it]) + 1 ;
28
+ s.insert (a);
29
+
30
+ res += h[a];
31
+ }
32
+
33
+ cout << res;
34
+ }
35
+
36
+ /*
37
+ A의 높이를 H[A]라 하면, H[A]는
38
+ max(H[(A보다 작은 수들 중 최댓값)], H[(A보다 큰 수들 중 최솟값)]) + 1이 됩니다.
39
+ Set이 비어 있을 때 처리를 편하게 하기 위해 값에 +1을 해 줬습니다.
40
+ */
You can’t perform that action at this time.
0 commit comments