# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
312304 |
2020-10-13T02:32:53 Z |
ttnhuy313 |
Money (IZhO17_money) |
C++14 |
|
1318 ms |
81664 KB |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
const int N = 1e6 + 5, LOG = 21;
int n, a[N], st[4 * N], maxRange[N], dp[N];
struct SegmentTree {
int n;
vector <int> st;
SegmentTree() {}
SegmentTree(int _n) {
this -> n = _n;
st.assign(4 * n + 5, N);
}
int Left(int x) {return (x << 1);}
int Right(int x) {return (x << 1) + 1;}
void update(int id, int L, int R, int i, int j, int val) {
if (L > j || R < i) return;
if (L >= i && R <= j) {
st[id] = min(st[id], val);
return;
}
int mid = (L + R) >> 1;
update(Left(id), L, mid, i, j, val);
update(Right(id), mid + 1, R, i, j, val);
}
int get(int id, int L, int R, int i) {
if (L > i || R < i) return N;
if (L == R) {
return st[id];
}
int mid = (L + R) >> 1, res = st[id];
res = min(res, get(Left(id), L, mid, i));
res = min(res, get(Right(id), mid + 1, R, i));
return res;
}
void update(int i, int j, int val) {
update(1, 1, n, i, j, val);
}
int get(int i) {
return get(1, 1, n, i);
}
};
int main(int argc, char const *argv[])
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
maxRange[n] = n;
for (int i = n - 1; i >= 1; --i) {
if (a[i] <= a[i + 1]) maxRange[i] = maxRange[i + 1];
else maxRange[i] = i;
}
SegmentTree solver = SegmentTree(n);
set <int> S; S.clear(); S.insert(a[1]);
for (int i = 1; i <= n; ++i) dp[i] = N;
dp[maxRange[1]] = 1;
for (int i = 2; i <= n; ++i) {
int val;
set <int>::iterator it = S.upper_bound(a[i]);
if (it == S.end()) val = N;
else val = *it;
int l = i, r = maxRange[i], far = i;
while (l <= r) {
int mid = (l + r) >> 1;
if (a[mid] > val) r = mid - 1;
else l = mid + 1, far = mid;
}
dp[far] = min(dp[far], dp[i - 1] + 1);
S.insert(a[i]);
}
cout << dp[n] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
0 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
0 ms |
384 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
0 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
0 ms |
384 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
64 ms |
13480 KB |
Output is correct |
40 |
Correct |
114 ms |
22008 KB |
Output is correct |
41 |
Correct |
57 ms |
11000 KB |
Output is correct |
42 |
Correct |
53 ms |
9720 KB |
Output is correct |
43 |
Correct |
37 ms |
7168 KB |
Output is correct |
44 |
Correct |
137 ms |
27768 KB |
Output is correct |
45 |
Correct |
136 ms |
27772 KB |
Output is correct |
46 |
Correct |
137 ms |
27768 KB |
Output is correct |
47 |
Correct |
120 ms |
27852 KB |
Output is correct |
48 |
Correct |
125 ms |
27768 KB |
Output is correct |
49 |
Correct |
558 ms |
46328 KB |
Output is correct |
50 |
Correct |
549 ms |
46200 KB |
Output is correct |
51 |
Correct |
565 ms |
46256 KB |
Output is correct |
52 |
Correct |
549 ms |
46328 KB |
Output is correct |
53 |
Correct |
541 ms |
46200 KB |
Output is correct |
54 |
Correct |
545 ms |
46356 KB |
Output is correct |
55 |
Correct |
1202 ms |
74744 KB |
Output is correct |
56 |
Correct |
1220 ms |
81664 KB |
Output is correct |
57 |
Correct |
1225 ms |
81656 KB |
Output is correct |
58 |
Correct |
1230 ms |
81656 KB |
Output is correct |
59 |
Correct |
1235 ms |
81448 KB |
Output is correct |
60 |
Correct |
1318 ms |
81528 KB |
Output is correct |
61 |
Correct |
1309 ms |
81484 KB |
Output is correct |
62 |
Correct |
1269 ms |
81528 KB |
Output is correct |