#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int ans = 0;
bitset<1000502> s;
ll a[1000500];
int t[4000500];
int p[1000500];
int sz = 1000001;
inline void upd(int v, int tl, int tr, int p)
{
if(tl == tr)
{
t[v] = 1;
return;
}
int tm = tl + tr >> 1;
if(p <= tm) upd(v << 1, tl, tm, p);
else upd((v << 1) + 1, tm + 1, tr, p);
t[v] = t[v << 1] + t[(v << 1) + 1];
}
inline int get(int v, int tl , int tr, int l, int r)
{
if(l > r) return 0;
if(tl == l && tr == r)
return t[v];
int tm = tl + tr >> 1;
return get((v << 1), tl, tm, l, min(r, tm)) + get((v << 1) + 1, tm + 1, tr, max(tm + 1, l), r);
}
inline int fnd(int v, int tl, int tr, int need)
{
if(tl == tr)
return tl;
int tm = tl + tr >> 1;
if(need <= t[(v << 1)])
return fnd((v << 1), tl, tm, need);
else
return fnd((v << 1) + 1, tm + 1, tr, need- t[(v << 1)]);
}
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%lld", a + i);
upd(1, 1, sz, sz);
for(int i = 1; i <= n;)
{
int f = get(1, 1, sz, 1, a[i]) + 1;
int nxt = fnd(1, 1, sz, f);
ll last = a[i];
while(i <= n && a[i] <= nxt && a[i] >= last)
upd(1, 1, sz, a[i]), last = a[i], i++;
ans++;
}
printf("%d\n", ans);
return 0;
}
Compilation message
money.cpp: In function 'void upd(int, int, int, int)':
money.cpp:22:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int tm = tl + tr >> 1;
^
money.cpp: In function 'int get(int, int, int, int, int)':
money.cpp:33:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int tm = tl + tr >> 1;
^
money.cpp: In function 'int fnd(int, int, int, int)':
money.cpp:41:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int tm = tl + tr >> 1;
^
money.cpp: In function 'int main()':
money.cpp:50:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
money.cpp:52:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", a + i);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
29500 KB |
Output is correct |
2 |
Correct |
0 ms |
29500 KB |
Output is correct |
3 |
Correct |
0 ms |
29500 KB |
Output is correct |
4 |
Correct |
0 ms |
29500 KB |
Output is correct |
5 |
Correct |
0 ms |
29500 KB |
Output is correct |
6 |
Correct |
0 ms |
29500 KB |
Output is correct |
7 |
Correct |
0 ms |
29500 KB |
Output is correct |
8 |
Correct |
0 ms |
29500 KB |
Output is correct |
9 |
Correct |
0 ms |
29500 KB |
Output is correct |
10 |
Correct |
0 ms |
29500 KB |
Output is correct |
11 |
Correct |
0 ms |
29500 KB |
Output is correct |
12 |
Correct |
0 ms |
29500 KB |
Output is correct |
13 |
Correct |
0 ms |
29500 KB |
Output is correct |
14 |
Correct |
0 ms |
29500 KB |
Output is correct |
15 |
Correct |
0 ms |
29500 KB |
Output is correct |
16 |
Correct |
0 ms |
29500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
29500 KB |
Output is correct |
2 |
Correct |
0 ms |
29500 KB |
Output is correct |
3 |
Correct |
0 ms |
29500 KB |
Output is correct |
4 |
Correct |
0 ms |
29500 KB |
Output is correct |
5 |
Correct |
0 ms |
29500 KB |
Output is correct |
6 |
Correct |
0 ms |
29500 KB |
Output is correct |
7 |
Correct |
0 ms |
29500 KB |
Output is correct |
8 |
Correct |
0 ms |
29500 KB |
Output is correct |
9 |
Correct |
0 ms |
29500 KB |
Output is correct |
10 |
Correct |
0 ms |
29500 KB |
Output is correct |
11 |
Correct |
0 ms |
29500 KB |
Output is correct |
12 |
Correct |
0 ms |
29500 KB |
Output is correct |
13 |
Correct |
0 ms |
29500 KB |
Output is correct |
14 |
Correct |
0 ms |
29500 KB |
Output is correct |
15 |
Correct |
0 ms |
29500 KB |
Output is correct |
16 |
Correct |
0 ms |
29500 KB |
Output is correct |
17 |
Correct |
0 ms |
29500 KB |
Output is correct |
18 |
Correct |
0 ms |
29500 KB |
Output is correct |
19 |
Correct |
0 ms |
29500 KB |
Output is correct |
20 |
Correct |
0 ms |
29500 KB |
Output is correct |
21 |
Correct |
0 ms |
29500 KB |
Output is correct |
22 |
Correct |
0 ms |
29500 KB |
Output is correct |
23 |
Correct |
0 ms |
29500 KB |
Output is correct |
24 |
Correct |
0 ms |
29500 KB |
Output is correct |
25 |
Correct |
0 ms |
29500 KB |
Output is correct |
26 |
Correct |
0 ms |
29500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
29500 KB |
Output is correct |
2 |
Correct |
0 ms |
29500 KB |
Output is correct |
3 |
Correct |
0 ms |
29500 KB |
Output is correct |
4 |
Correct |
0 ms |
29500 KB |
Output is correct |
5 |
Correct |
0 ms |
29500 KB |
Output is correct |
6 |
Correct |
0 ms |
29500 KB |
Output is correct |
7 |
Correct |
0 ms |
29500 KB |
Output is correct |
8 |
Correct |
0 ms |
29500 KB |
Output is correct |
9 |
Correct |
0 ms |
29500 KB |
Output is correct |
10 |
Correct |
0 ms |
29500 KB |
Output is correct |
11 |
Correct |
0 ms |
29500 KB |
Output is correct |
12 |
Correct |
0 ms |
29500 KB |
Output is correct |
13 |
Correct |
0 ms |
29500 KB |
Output is correct |
14 |
Correct |
0 ms |
29500 KB |
Output is correct |
15 |
Correct |
0 ms |
29500 KB |
Output is correct |
16 |
Correct |
0 ms |
29500 KB |
Output is correct |
17 |
Correct |
0 ms |
29500 KB |
Output is correct |
18 |
Correct |
0 ms |
29500 KB |
Output is correct |
19 |
Correct |
0 ms |
29500 KB |
Output is correct |
20 |
Correct |
0 ms |
29500 KB |
Output is correct |
21 |
Correct |
0 ms |
29500 KB |
Output is correct |
22 |
Correct |
0 ms |
29500 KB |
Output is correct |
23 |
Correct |
0 ms |
29500 KB |
Output is correct |
24 |
Correct |
0 ms |
29500 KB |
Output is correct |
25 |
Correct |
0 ms |
29500 KB |
Output is correct |
26 |
Correct |
0 ms |
29500 KB |
Output is correct |
27 |
Correct |
0 ms |
29500 KB |
Output is correct |
28 |
Correct |
0 ms |
29500 KB |
Output is correct |
29 |
Correct |
0 ms |
29500 KB |
Output is correct |
30 |
Correct |
0 ms |
29500 KB |
Output is correct |
31 |
Correct |
0 ms |
29500 KB |
Output is correct |
32 |
Correct |
0 ms |
29500 KB |
Output is correct |
33 |
Correct |
0 ms |
29500 KB |
Output is correct |
34 |
Correct |
0 ms |
29500 KB |
Output is correct |
35 |
Correct |
0 ms |
29500 KB |
Output is correct |
36 |
Correct |
0 ms |
29500 KB |
Output is correct |
37 |
Correct |
0 ms |
29500 KB |
Output is correct |
38 |
Correct |
0 ms |
29500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
29500 KB |
Output is correct |
2 |
Correct |
0 ms |
29500 KB |
Output is correct |
3 |
Correct |
0 ms |
29500 KB |
Output is correct |
4 |
Correct |
0 ms |
29500 KB |
Output is correct |
5 |
Correct |
0 ms |
29500 KB |
Output is correct |
6 |
Correct |
0 ms |
29500 KB |
Output is correct |
7 |
Correct |
0 ms |
29500 KB |
Output is correct |
8 |
Correct |
0 ms |
29500 KB |
Output is correct |
9 |
Correct |
0 ms |
29500 KB |
Output is correct |
10 |
Correct |
0 ms |
29500 KB |
Output is correct |
11 |
Correct |
0 ms |
29500 KB |
Output is correct |
12 |
Correct |
0 ms |
29500 KB |
Output is correct |
13 |
Correct |
0 ms |
29500 KB |
Output is correct |
14 |
Correct |
0 ms |
29500 KB |
Output is correct |
15 |
Correct |
0 ms |
29500 KB |
Output is correct |
16 |
Correct |
0 ms |
29500 KB |
Output is correct |
17 |
Correct |
0 ms |
29500 KB |
Output is correct |
18 |
Correct |
0 ms |
29500 KB |
Output is correct |
19 |
Correct |
0 ms |
29500 KB |
Output is correct |
20 |
Correct |
0 ms |
29500 KB |
Output is correct |
21 |
Correct |
0 ms |
29500 KB |
Output is correct |
22 |
Correct |
0 ms |
29500 KB |
Output is correct |
23 |
Correct |
0 ms |
29500 KB |
Output is correct |
24 |
Correct |
0 ms |
29500 KB |
Output is correct |
25 |
Correct |
0 ms |
29500 KB |
Output is correct |
26 |
Correct |
0 ms |
29500 KB |
Output is correct |
27 |
Correct |
0 ms |
29500 KB |
Output is correct |
28 |
Correct |
0 ms |
29500 KB |
Output is correct |
29 |
Correct |
0 ms |
29500 KB |
Output is correct |
30 |
Correct |
0 ms |
29500 KB |
Output is correct |
31 |
Correct |
0 ms |
29500 KB |
Output is correct |
32 |
Correct |
0 ms |
29500 KB |
Output is correct |
33 |
Correct |
0 ms |
29500 KB |
Output is correct |
34 |
Correct |
0 ms |
29500 KB |
Output is correct |
35 |
Correct |
0 ms |
29500 KB |
Output is correct |
36 |
Correct |
0 ms |
29500 KB |
Output is correct |
37 |
Correct |
0 ms |
29500 KB |
Output is correct |
38 |
Correct |
0 ms |
29500 KB |
Output is correct |
39 |
Correct |
146 ms |
29500 KB |
Output is correct |
40 |
Correct |
276 ms |
29500 KB |
Output is correct |
41 |
Correct |
139 ms |
29500 KB |
Output is correct |
42 |
Correct |
133 ms |
29500 KB |
Output is correct |
43 |
Correct |
83 ms |
29500 KB |
Output is correct |
44 |
Correct |
306 ms |
29500 KB |
Output is correct |
45 |
Correct |
296 ms |
29500 KB |
Output is correct |
46 |
Correct |
319 ms |
29500 KB |
Output is correct |
47 |
Correct |
213 ms |
29500 KB |
Output is correct |
48 |
Correct |
263 ms |
29500 KB |
Output is correct |
49 |
Correct |
609 ms |
29500 KB |
Output is correct |
50 |
Correct |
593 ms |
29500 KB |
Output is correct |
51 |
Correct |
603 ms |
29500 KB |
Output is correct |
52 |
Correct |
589 ms |
29500 KB |
Output is correct |
53 |
Correct |
533 ms |
29500 KB |
Output is correct |
54 |
Correct |
629 ms |
29500 KB |
Output is correct |
55 |
Correct |
823 ms |
29500 KB |
Output is correct |
56 |
Correct |
816 ms |
29500 KB |
Output is correct |
57 |
Correct |
859 ms |
29500 KB |
Output is correct |
58 |
Correct |
886 ms |
29500 KB |
Output is correct |
59 |
Correct |
896 ms |
29500 KB |
Output is correct |
60 |
Correct |
819 ms |
29500 KB |
Output is correct |
61 |
Correct |
833 ms |
29500 KB |
Output is correct |
62 |
Correct |
913 ms |
29500 KB |
Output is correct |