/*
.:*+=%@@@@@@=-.
.:=@#@@@#@@#######%==*.
.-=####@######%*-.....:%##%.
.*@###########%+:--........-%@-
.*@##############@+--.........-:%-
.+##################@==%%%%=+*:----+.
.-@####################%++%@@@@@=+**%@@*
.%###################@%%@@@###@%+:--%@@%.
-@###################@%%%%*::*%++:-----=@+.
-#####################@%=++++++*:-------.-=:
.+####################@%++*::-:::--::*:::***=:
.@#####################%=++*::::-:::++*=##@@#@-
..#####################@%%=++**:::::**+%@#@%%##-..
.%####################@@%=+++*+****::*=@######@.
.=######################@%%==+==++**+=@%@##@###+:...
-#######################@@@%%%===++=@@@%=++===*::--...
-########################@@@@@@@%==%%=++==@@:::::*:--.
..:#########################@@@@@@%%======++++::-..:-.--...
%#############################@###@%%@@%==%=%*----.--.::---.
#############################################*-:*:-:---*---- .
#############################################*--*--:---*---:-.
#############################################+--::--::-*::-::.
###########################################+:*-.---.---.:---*-..
###########################################**:-----------------.
##########################################@::**:--::::::--:::::-
###########################################:--:*:::::::::**::*+*
###########################################=:::***::::::**:::*+*
############################@@@@@@#########@+****::::********+++
############################@%%%%%@@@@@@@###%+***::::::::***+==+
############################@%%%%%%%%%%%@####=+:::-::::-::*+=%%+
#############################@%%%%%%%%%%@#####=::--------:*=%@%+
%###########################@%%%%==%%%%%%@##@#=:------..-:+%@@%=
----------------------------------------------
--------------------------------------------
----------------------------------------------
--------------------------------------------
----------------------------------------------
o###########oo
o##" ""##o
o#" "##
o#" "#o
#" ## ## "##
#" ##
# ################### #
# #
# #
# #
# #
# #
# #
#o #
"#o ##
"#o ##
"#o o#"
"#o ##
"#o o#"
"#ooo ooo#######oo
############### "######o
o###"" "###o # ###
o###o oooo ### oo####"
o###**# #**# ############"
""##""""""""""########### #
# oooooooo#"#** ## #
# # # # ** ## #
#o# #o# *****###ooo#
##
## o###o
## o##***##
o########## #***#**##o
o##" ""### #***##***#
o#######o ### oo#### ##**####*#
o##" ""#############"" ##****###
##" ## ##*##*###
## ### ##### ##
## ### # ## #
## ## #
## ##
## ###
## ###oo
### ""###
###
###
*/
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int mysqrt(ll x){
int l = 0, r = 1e9 + 1;
while (r - l > 1){
int m = (l + r) / 2;
if (m * (ll)m <= x)
l = m;
else
r = m;
}
return l;
}
mt19937 rnd(1337);
ll AR = 19, BR = 13, CR = 23, XR = 228, YR = 322, MODR = 1e9 + 993;
ll myrand(){
ll ZR = (XR * AR + YR * BR + CR) % MODR;
XR = YR;
YR = ZR;
return ZR;
}
const int Mod = 1e9 + 7;
int bpow(int x, int y){
if (y == 0)
return 1;
if (y == 1)
return x;
int ret = bpow(x, y >> 1);
ret = (ret * (ll)ret) % Mod;
if (y & 1)
ret = (ret * (ll)x) % Mod;
return ret;
}
int bdiv(int x, int y){
return (x * (ll)bpow(y, Mod - 2)) % Mod;
}
void setmin(int &x, int y){
x = min(x, y);
}
void setmax(int &x, int y){
x = max(x, y);
}
const ll llinf = 1e18 + 100;
const int maxn = 1e6 + 100, inf = 2e9 + 100, sq = 300, mod = 1e9 + 7, LG = 17;
int n;
int a[maxn];
int p[maxn];
int q[maxn];
set<int> g;
int main()
{
#ifdef ONPC
//ifstream cin("a.in");
//ofstream cout("a.out");
freopen("a.in", "r", stdin);
freopen("a.out", "w", stdout);
#else
//ifstream cin("bootfall.in");
//ofstream cout("bootfall.out");
//freopen("trap.in", "r", stdin);
//freopen("trap.out", "w", stdout);
#endif // ONPC
//ios::sync_with_stdio(0);
//cin.tie(0);
//cout.tie(0);
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
p[n - 1] = n - 1;
for (int i = n - 2; i >= 0; i--){
if (a[i] <= a[i + 1])
p[i] = p[i + 1];
else
p[i] = i;
}
q[0] = 0;
for (int i = 1; i <= n; i++)
q[i] = inf;
for (int i = 0; i < n; i++){
if (q[i] != inf){
set<int> :: iterator it = g.upper_bound(a[i]);
int x;
if (it == g.end())
x = inf;
else
x = *it;
int l = i, r = p[i] + 1;
while (r - l > 1){
int m = (l + r) / 2;
if (a[m] <= x)
l = m;
else
r = m;
}
q[l + 1] = min(q[l + 1], q[i] + 1);
}
g.insert(a[i]);
}
printf("%d\n", q[n]);
}
Compilation message
money.cpp: In function 'int main()':
money.cpp:180:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
money.cpp:182:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
13744 KB |
Output is correct |
2 |
Correct |
0 ms |
13744 KB |
Output is correct |
3 |
Correct |
0 ms |
13744 KB |
Output is correct |
4 |
Correct |
0 ms |
13744 KB |
Output is correct |
5 |
Correct |
0 ms |
13744 KB |
Output is correct |
6 |
Correct |
0 ms |
13744 KB |
Output is correct |
7 |
Correct |
0 ms |
13744 KB |
Output is correct |
8 |
Correct |
0 ms |
13744 KB |
Output is correct |
9 |
Correct |
0 ms |
13744 KB |
Output is correct |
10 |
Correct |
0 ms |
13744 KB |
Output is correct |
11 |
Correct |
0 ms |
13744 KB |
Output is correct |
12 |
Correct |
0 ms |
13744 KB |
Output is correct |
13 |
Correct |
0 ms |
13744 KB |
Output is correct |
14 |
Correct |
0 ms |
13744 KB |
Output is correct |
15 |
Correct |
0 ms |
13744 KB |
Output is correct |
16 |
Correct |
0 ms |
13744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
13744 KB |
Output is correct |
2 |
Correct |
0 ms |
13744 KB |
Output is correct |
3 |
Correct |
0 ms |
13744 KB |
Output is correct |
4 |
Correct |
0 ms |
13744 KB |
Output is correct |
5 |
Correct |
0 ms |
13744 KB |
Output is correct |
6 |
Correct |
0 ms |
13744 KB |
Output is correct |
7 |
Correct |
0 ms |
13744 KB |
Output is correct |
8 |
Correct |
0 ms |
13744 KB |
Output is correct |
9 |
Correct |
0 ms |
13744 KB |
Output is correct |
10 |
Correct |
0 ms |
13744 KB |
Output is correct |
11 |
Correct |
0 ms |
13744 KB |
Output is correct |
12 |
Correct |
0 ms |
13744 KB |
Output is correct |
13 |
Correct |
0 ms |
13744 KB |
Output is correct |
14 |
Correct |
0 ms |
13744 KB |
Output is correct |
15 |
Correct |
0 ms |
13744 KB |
Output is correct |
16 |
Correct |
0 ms |
13744 KB |
Output is correct |
17 |
Correct |
0 ms |
13744 KB |
Output is correct |
18 |
Correct |
0 ms |
13744 KB |
Output is correct |
19 |
Correct |
0 ms |
13744 KB |
Output is correct |
20 |
Correct |
0 ms |
13744 KB |
Output is correct |
21 |
Correct |
0 ms |
13744 KB |
Output is correct |
22 |
Correct |
0 ms |
13744 KB |
Output is correct |
23 |
Correct |
0 ms |
13744 KB |
Output is correct |
24 |
Correct |
0 ms |
13744 KB |
Output is correct |
25 |
Correct |
0 ms |
13744 KB |
Output is correct |
26 |
Correct |
0 ms |
13744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
13744 KB |
Output is correct |
2 |
Correct |
0 ms |
13744 KB |
Output is correct |
3 |
Correct |
0 ms |
13744 KB |
Output is correct |
4 |
Correct |
0 ms |
13744 KB |
Output is correct |
5 |
Correct |
0 ms |
13744 KB |
Output is correct |
6 |
Correct |
0 ms |
13744 KB |
Output is correct |
7 |
Correct |
0 ms |
13744 KB |
Output is correct |
8 |
Correct |
0 ms |
13744 KB |
Output is correct |
9 |
Correct |
0 ms |
13744 KB |
Output is correct |
10 |
Correct |
0 ms |
13744 KB |
Output is correct |
11 |
Correct |
0 ms |
13744 KB |
Output is correct |
12 |
Correct |
0 ms |
13744 KB |
Output is correct |
13 |
Correct |
0 ms |
13744 KB |
Output is correct |
14 |
Correct |
0 ms |
13744 KB |
Output is correct |
15 |
Correct |
0 ms |
13744 KB |
Output is correct |
16 |
Correct |
0 ms |
13744 KB |
Output is correct |
17 |
Correct |
0 ms |
13744 KB |
Output is correct |
18 |
Correct |
0 ms |
13744 KB |
Output is correct |
19 |
Correct |
0 ms |
13744 KB |
Output is correct |
20 |
Correct |
0 ms |
13744 KB |
Output is correct |
21 |
Correct |
0 ms |
13744 KB |
Output is correct |
22 |
Correct |
0 ms |
13744 KB |
Output is correct |
23 |
Correct |
0 ms |
13744 KB |
Output is correct |
24 |
Correct |
0 ms |
13744 KB |
Output is correct |
25 |
Correct |
0 ms |
13744 KB |
Output is correct |
26 |
Correct |
0 ms |
13744 KB |
Output is correct |
27 |
Correct |
0 ms |
13744 KB |
Output is correct |
28 |
Correct |
0 ms |
13744 KB |
Output is correct |
29 |
Correct |
0 ms |
13744 KB |
Output is correct |
30 |
Correct |
0 ms |
13744 KB |
Output is correct |
31 |
Correct |
0 ms |
13744 KB |
Output is correct |
32 |
Correct |
0 ms |
13744 KB |
Output is correct |
33 |
Correct |
0 ms |
13744 KB |
Output is correct |
34 |
Correct |
0 ms |
13744 KB |
Output is correct |
35 |
Correct |
0 ms |
13744 KB |
Output is correct |
36 |
Correct |
0 ms |
13744 KB |
Output is correct |
37 |
Correct |
0 ms |
13744 KB |
Output is correct |
38 |
Correct |
0 ms |
13744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
13744 KB |
Output is correct |
2 |
Correct |
0 ms |
13744 KB |
Output is correct |
3 |
Correct |
0 ms |
13744 KB |
Output is correct |
4 |
Correct |
0 ms |
13744 KB |
Output is correct |
5 |
Correct |
0 ms |
13744 KB |
Output is correct |
6 |
Correct |
0 ms |
13744 KB |
Output is correct |
7 |
Correct |
0 ms |
13744 KB |
Output is correct |
8 |
Correct |
0 ms |
13744 KB |
Output is correct |
9 |
Correct |
0 ms |
13744 KB |
Output is correct |
10 |
Correct |
0 ms |
13744 KB |
Output is correct |
11 |
Correct |
0 ms |
13744 KB |
Output is correct |
12 |
Correct |
0 ms |
13744 KB |
Output is correct |
13 |
Correct |
0 ms |
13744 KB |
Output is correct |
14 |
Correct |
0 ms |
13744 KB |
Output is correct |
15 |
Correct |
0 ms |
13744 KB |
Output is correct |
16 |
Correct |
0 ms |
13744 KB |
Output is correct |
17 |
Correct |
0 ms |
13744 KB |
Output is correct |
18 |
Correct |
0 ms |
13744 KB |
Output is correct |
19 |
Correct |
0 ms |
13744 KB |
Output is correct |
20 |
Correct |
0 ms |
13744 KB |
Output is correct |
21 |
Correct |
0 ms |
13744 KB |
Output is correct |
22 |
Correct |
0 ms |
13744 KB |
Output is correct |
23 |
Correct |
0 ms |
13744 KB |
Output is correct |
24 |
Correct |
0 ms |
13744 KB |
Output is correct |
25 |
Correct |
0 ms |
13744 KB |
Output is correct |
26 |
Correct |
0 ms |
13744 KB |
Output is correct |
27 |
Correct |
0 ms |
13744 KB |
Output is correct |
28 |
Correct |
0 ms |
13744 KB |
Output is correct |
29 |
Correct |
0 ms |
13744 KB |
Output is correct |
30 |
Correct |
0 ms |
13744 KB |
Output is correct |
31 |
Correct |
0 ms |
13744 KB |
Output is correct |
32 |
Correct |
0 ms |
13744 KB |
Output is correct |
33 |
Correct |
0 ms |
13744 KB |
Output is correct |
34 |
Correct |
0 ms |
13744 KB |
Output is correct |
35 |
Correct |
0 ms |
13744 KB |
Output is correct |
36 |
Correct |
0 ms |
13744 KB |
Output is correct |
37 |
Correct |
0 ms |
13744 KB |
Output is correct |
38 |
Correct |
0 ms |
13744 KB |
Output is correct |
39 |
Correct |
96 ms |
13744 KB |
Output is correct |
40 |
Correct |
176 ms |
13744 KB |
Output is correct |
41 |
Correct |
69 ms |
13744 KB |
Output is correct |
42 |
Correct |
89 ms |
13744 KB |
Output is correct |
43 |
Correct |
53 ms |
13744 KB |
Output is correct |
44 |
Correct |
243 ms |
13744 KB |
Output is correct |
45 |
Correct |
253 ms |
13744 KB |
Output is correct |
46 |
Correct |
269 ms |
13744 KB |
Output is correct |
47 |
Correct |
196 ms |
13744 KB |
Output is correct |
48 |
Correct |
189 ms |
13744 KB |
Output is correct |
49 |
Correct |
926 ms |
32224 KB |
Output is correct |
50 |
Correct |
866 ms |
32224 KB |
Output is correct |
51 |
Correct |
813 ms |
32224 KB |
Output is correct |
52 |
Correct |
889 ms |
32224 KB |
Output is correct |
53 |
Correct |
893 ms |
32224 KB |
Output is correct |
54 |
Correct |
966 ms |
32224 KB |
Output is correct |
55 |
Execution timed out |
1500 ms |
60604 KB |
Execution timed out |
56 |
Halted |
0 ms |
0 KB |
- |