#include<bits/stdc++.h>
#pragma optimize ("g",on)
#pragma GCC optimize ("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
//01001101 01100001 01101011 01101000 01100001 01100111 01100001 01111001
using namespace std;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define pb push_back
#define sz(a) a.size()
#define nl '\n'
#define popb pop_back()
#define ld double
#define ull unsigned long long
#define ff first
#define ss second
#define fix fixed << setprecision
#define pii pair<int, int>
#define E exit (0)
#define int long long
const int inf = 1e18, N = 1e6 + 1, mod = 998244353;
vector<pii> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
vector<int> t(4 * N, inf);
void update(int u, int tl, int tr, int l, int r, int val) {
if (tl > r || tr < l) return;
if (tl >= l && tr <= r) {
t[u] = min(t[u], val);
return;
}
int mid = (tl + tr) / 2;
update(u * 2, tl, mid, l, r, val);
update(u * 2 + 1, mid + 1, tr, l, r, val);
}
int get(int u, int tl, int tr, int pos) {
if (tl == tr) return t[u];
int mid = (tl + tr) / 2;
if (pos <= mid) {
return min(get(u * 2, tl, mid, pos), t[u]);
}
return min(get(u * 2 + 1, mid + 1, tr, pos), t[u]);
}
main() {
//freopen("cowrect.in", "r", stdin);
//freopen("cowrect.out", "w", stdout);
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
int n;
cin >> n;
int a[n + 1], r[n + 1];
for (int i = 1; i <= n; i++) cin >> a[i];
int l = 1;
for (int i = 2; i <= n; i++) {
if (a[i] < a[i - 1]) {
while (l < i) {
r[l++] = i - 1;
}
}
}
while (l <= n) {
r[l++] = n;
}
set<int> s;
update(1, 0, n, 0, 0, 0);
for (int i = 1; i <= n; i++) {
auto it = s.upper_bound(a[i]);
int val;
if (it == s.end()) val = inf;
else val = *it;
int tl = i, tr = r[i], pos;
while (tl <= tr) {
int mid = (tl + tr) / 2;
if (a[mid] <= val) {
tl = mid + 1;
pos = mid;
}else tr = mid - 1;
}
update(1, 0, n, i, pos, get(1, 0, n, i - 1) + 1);
s.insert(a[i]);
}
cout << get(1, 0, n, n);
}
Compilation message
money.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
3 | #pragma optimize ("g",on)
|
money.cpp:9: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
9 | #pragma comment(linker, "/stack:200000000")
|
money.cpp:57:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
57 | main() {
| ^~~~
money.cpp: In function 'int main()':
money.cpp:45:8: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
45 | update(u * 2 + 1, mid + 1, tr, l, r, val);
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
money.cpp:84:26: note: 'pos' was declared here
84 | int tl = i, tr = r[i], pos;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
31564 KB |
Output is correct |
2 |
Correct |
15 ms |
31564 KB |
Output is correct |
3 |
Correct |
13 ms |
31564 KB |
Output is correct |
4 |
Correct |
12 ms |
31564 KB |
Output is correct |
5 |
Correct |
12 ms |
31536 KB |
Output is correct |
6 |
Correct |
12 ms |
31564 KB |
Output is correct |
7 |
Correct |
13 ms |
31564 KB |
Output is correct |
8 |
Correct |
12 ms |
31608 KB |
Output is correct |
9 |
Correct |
13 ms |
31628 KB |
Output is correct |
10 |
Correct |
13 ms |
31624 KB |
Output is correct |
11 |
Correct |
13 ms |
31564 KB |
Output is correct |
12 |
Correct |
12 ms |
31564 KB |
Output is correct |
13 |
Correct |
13 ms |
31524 KB |
Output is correct |
14 |
Correct |
13 ms |
31564 KB |
Output is correct |
15 |
Correct |
12 ms |
31564 KB |
Output is correct |
16 |
Correct |
12 ms |
31616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
31564 KB |
Output is correct |
2 |
Correct |
15 ms |
31564 KB |
Output is correct |
3 |
Correct |
13 ms |
31564 KB |
Output is correct |
4 |
Correct |
12 ms |
31564 KB |
Output is correct |
5 |
Correct |
12 ms |
31536 KB |
Output is correct |
6 |
Correct |
12 ms |
31564 KB |
Output is correct |
7 |
Correct |
13 ms |
31564 KB |
Output is correct |
8 |
Correct |
12 ms |
31608 KB |
Output is correct |
9 |
Correct |
13 ms |
31628 KB |
Output is correct |
10 |
Correct |
13 ms |
31624 KB |
Output is correct |
11 |
Correct |
13 ms |
31564 KB |
Output is correct |
12 |
Correct |
12 ms |
31564 KB |
Output is correct |
13 |
Correct |
13 ms |
31524 KB |
Output is correct |
14 |
Correct |
13 ms |
31564 KB |
Output is correct |
15 |
Correct |
12 ms |
31564 KB |
Output is correct |
16 |
Correct |
12 ms |
31616 KB |
Output is correct |
17 |
Correct |
15 ms |
31580 KB |
Output is correct |
18 |
Correct |
14 ms |
31580 KB |
Output is correct |
19 |
Correct |
13 ms |
31580 KB |
Output is correct |
20 |
Correct |
12 ms |
31564 KB |
Output is correct |
21 |
Correct |
12 ms |
31564 KB |
Output is correct |
22 |
Correct |
12 ms |
31564 KB |
Output is correct |
23 |
Correct |
13 ms |
31564 KB |
Output is correct |
24 |
Correct |
13 ms |
31564 KB |
Output is correct |
25 |
Correct |
13 ms |
31564 KB |
Output is correct |
26 |
Correct |
14 ms |
31528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
31564 KB |
Output is correct |
2 |
Correct |
15 ms |
31564 KB |
Output is correct |
3 |
Correct |
13 ms |
31564 KB |
Output is correct |
4 |
Correct |
12 ms |
31564 KB |
Output is correct |
5 |
Correct |
12 ms |
31536 KB |
Output is correct |
6 |
Correct |
12 ms |
31564 KB |
Output is correct |
7 |
Correct |
13 ms |
31564 KB |
Output is correct |
8 |
Correct |
12 ms |
31608 KB |
Output is correct |
9 |
Correct |
13 ms |
31628 KB |
Output is correct |
10 |
Correct |
13 ms |
31624 KB |
Output is correct |
11 |
Correct |
13 ms |
31564 KB |
Output is correct |
12 |
Correct |
12 ms |
31564 KB |
Output is correct |
13 |
Correct |
13 ms |
31524 KB |
Output is correct |
14 |
Correct |
13 ms |
31564 KB |
Output is correct |
15 |
Correct |
12 ms |
31564 KB |
Output is correct |
16 |
Correct |
12 ms |
31616 KB |
Output is correct |
17 |
Correct |
15 ms |
31580 KB |
Output is correct |
18 |
Correct |
14 ms |
31580 KB |
Output is correct |
19 |
Correct |
13 ms |
31580 KB |
Output is correct |
20 |
Correct |
12 ms |
31564 KB |
Output is correct |
21 |
Correct |
12 ms |
31564 KB |
Output is correct |
22 |
Correct |
12 ms |
31564 KB |
Output is correct |
23 |
Correct |
13 ms |
31564 KB |
Output is correct |
24 |
Correct |
13 ms |
31564 KB |
Output is correct |
25 |
Correct |
13 ms |
31564 KB |
Output is correct |
26 |
Correct |
14 ms |
31528 KB |
Output is correct |
27 |
Correct |
12 ms |
31564 KB |
Output is correct |
28 |
Correct |
12 ms |
31564 KB |
Output is correct |
29 |
Correct |
13 ms |
31604 KB |
Output is correct |
30 |
Correct |
12 ms |
31576 KB |
Output is correct |
31 |
Correct |
13 ms |
31524 KB |
Output is correct |
32 |
Correct |
12 ms |
31544 KB |
Output is correct |
33 |
Correct |
12 ms |
31564 KB |
Output is correct |
34 |
Correct |
14 ms |
31604 KB |
Output is correct |
35 |
Correct |
12 ms |
31612 KB |
Output is correct |
36 |
Correct |
13 ms |
31632 KB |
Output is correct |
37 |
Correct |
12 ms |
31604 KB |
Output is correct |
38 |
Correct |
12 ms |
31564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
31564 KB |
Output is correct |
2 |
Correct |
15 ms |
31564 KB |
Output is correct |
3 |
Correct |
13 ms |
31564 KB |
Output is correct |
4 |
Correct |
12 ms |
31564 KB |
Output is correct |
5 |
Correct |
12 ms |
31536 KB |
Output is correct |
6 |
Correct |
12 ms |
31564 KB |
Output is correct |
7 |
Correct |
13 ms |
31564 KB |
Output is correct |
8 |
Correct |
12 ms |
31608 KB |
Output is correct |
9 |
Correct |
13 ms |
31628 KB |
Output is correct |
10 |
Correct |
13 ms |
31624 KB |
Output is correct |
11 |
Correct |
13 ms |
31564 KB |
Output is correct |
12 |
Correct |
12 ms |
31564 KB |
Output is correct |
13 |
Correct |
13 ms |
31524 KB |
Output is correct |
14 |
Correct |
13 ms |
31564 KB |
Output is correct |
15 |
Correct |
12 ms |
31564 KB |
Output is correct |
16 |
Correct |
12 ms |
31616 KB |
Output is correct |
17 |
Correct |
15 ms |
31580 KB |
Output is correct |
18 |
Correct |
14 ms |
31580 KB |
Output is correct |
19 |
Correct |
13 ms |
31580 KB |
Output is correct |
20 |
Correct |
12 ms |
31564 KB |
Output is correct |
21 |
Correct |
12 ms |
31564 KB |
Output is correct |
22 |
Correct |
12 ms |
31564 KB |
Output is correct |
23 |
Correct |
13 ms |
31564 KB |
Output is correct |
24 |
Correct |
13 ms |
31564 KB |
Output is correct |
25 |
Correct |
13 ms |
31564 KB |
Output is correct |
26 |
Correct |
14 ms |
31528 KB |
Output is correct |
27 |
Correct |
12 ms |
31564 KB |
Output is correct |
28 |
Correct |
12 ms |
31564 KB |
Output is correct |
29 |
Correct |
13 ms |
31604 KB |
Output is correct |
30 |
Correct |
12 ms |
31576 KB |
Output is correct |
31 |
Correct |
13 ms |
31524 KB |
Output is correct |
32 |
Correct |
12 ms |
31544 KB |
Output is correct |
33 |
Correct |
12 ms |
31564 KB |
Output is correct |
34 |
Correct |
14 ms |
31604 KB |
Output is correct |
35 |
Correct |
12 ms |
31612 KB |
Output is correct |
36 |
Correct |
13 ms |
31632 KB |
Output is correct |
37 |
Correct |
12 ms |
31604 KB |
Output is correct |
38 |
Correct |
12 ms |
31564 KB |
Output is correct |
39 |
Correct |
151 ms |
42264 KB |
Output is correct |
40 |
Correct |
262 ms |
49204 KB |
Output is correct |
41 |
Correct |
123 ms |
40212 KB |
Output is correct |
42 |
Correct |
114 ms |
39316 KB |
Output is correct |
43 |
Correct |
88 ms |
37056 KB |
Output is correct |
44 |
Correct |
309 ms |
53916 KB |
Output is correct |
45 |
Correct |
311 ms |
53904 KB |
Output is correct |
46 |
Correct |
303 ms |
54084 KB |
Output is correct |
47 |
Correct |
293 ms |
54084 KB |
Output is correct |
48 |
Correct |
303 ms |
54044 KB |
Output is correct |
49 |
Correct |
583 ms |
72724 KB |
Output is correct |
50 |
Correct |
584 ms |
72508 KB |
Output is correct |
51 |
Correct |
605 ms |
72484 KB |
Output is correct |
52 |
Correct |
595 ms |
72464 KB |
Output is correct |
53 |
Correct |
569 ms |
72516 KB |
Output is correct |
54 |
Correct |
595 ms |
72344 KB |
Output is correct |
55 |
Correct |
1189 ms |
100932 KB |
Output is correct |
56 |
Correct |
1125 ms |
101016 KB |
Output is correct |
57 |
Correct |
1105 ms |
101016 KB |
Output is correct |
58 |
Correct |
1122 ms |
101048 KB |
Output is correct |
59 |
Correct |
1067 ms |
100876 KB |
Output is correct |
60 |
Correct |
1116 ms |
100876 KB |
Output is correct |
61 |
Correct |
1114 ms |
100908 KB |
Output is correct |
62 |
Correct |
1131 ms |
100972 KB |
Output is correct |