//Just try and the idea will come!
#include<bits/stdc++.h>
using namespace std;
int mx,n,i,a[1000001],ans,tree[4000004];
void update(int v,int l,int r,int pos,int val){
if(l==pos&&r==pos){
tree[v]=val;
return;
}
int mid=(l+r)>>1;
if(pos<=mid)update((v*2),l,mid,pos,val);
else update((v*2)+1,mid+1,r,pos,val);
tree[v]=min(tree[(v*2)],tree[(v*2)+1]);
}
int get(int v,int l,int r,int ql,int qr){
if(ql<=l&&r<=qr)return tree[v];
if(r<ql||qr<l)return 1000001;
int mid=(l+r)>>1;
return min(get((v*2),l,mid,ql,qr),get((v*2)+1,mid+1,r,ql,qr));
}
main(){
for(i=0;i<4000004;i++)tree[i]=1000001;
scanf("%d",&n);
for(i=0;i<n;i++)scanf("%d",&a[i]);
i=0;
while(i<n){
mx=get(1,1,1000001,a[i]+1,1000001);
update(1,1,1000001,a[i],a[i]);
while(i+1<n&&a[i]<=a[i+1]&&a[i+1]<=mx)i++,update(1,1,1000001,a[i],a[i]);;
i++;
ans++;
}
printf("%d",ans);
}
Compilation message
money.cpp:21:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
money.cpp: In function 'int main()':
money.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
money.cpp:24:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=0;i<n;i++)scanf("%d",&a[i]);
~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
15992 KB |
Output is correct |
2 |
Correct |
16 ms |
15992 KB |
Output is correct |
3 |
Correct |
16 ms |
15992 KB |
Output is correct |
4 |
Correct |
16 ms |
15992 KB |
Output is correct |
5 |
Correct |
16 ms |
15992 KB |
Output is correct |
6 |
Correct |
16 ms |
15992 KB |
Output is correct |
7 |
Correct |
16 ms |
15992 KB |
Output is correct |
8 |
Correct |
16 ms |
15992 KB |
Output is correct |
9 |
Correct |
16 ms |
15992 KB |
Output is correct |
10 |
Correct |
16 ms |
15992 KB |
Output is correct |
11 |
Correct |
16 ms |
15992 KB |
Output is correct |
12 |
Correct |
15 ms |
15992 KB |
Output is correct |
13 |
Correct |
16 ms |
15992 KB |
Output is correct |
14 |
Correct |
16 ms |
15992 KB |
Output is correct |
15 |
Correct |
18 ms |
15992 KB |
Output is correct |
16 |
Correct |
16 ms |
15992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
15992 KB |
Output is correct |
2 |
Correct |
16 ms |
15992 KB |
Output is correct |
3 |
Correct |
16 ms |
15992 KB |
Output is correct |
4 |
Correct |
16 ms |
15992 KB |
Output is correct |
5 |
Correct |
16 ms |
15992 KB |
Output is correct |
6 |
Correct |
16 ms |
15992 KB |
Output is correct |
7 |
Correct |
16 ms |
15992 KB |
Output is correct |
8 |
Correct |
16 ms |
15992 KB |
Output is correct |
9 |
Correct |
16 ms |
15992 KB |
Output is correct |
10 |
Correct |
16 ms |
15992 KB |
Output is correct |
11 |
Correct |
16 ms |
15992 KB |
Output is correct |
12 |
Correct |
15 ms |
15992 KB |
Output is correct |
13 |
Correct |
16 ms |
15992 KB |
Output is correct |
14 |
Correct |
16 ms |
15992 KB |
Output is correct |
15 |
Correct |
18 ms |
15992 KB |
Output is correct |
16 |
Correct |
16 ms |
15992 KB |
Output is correct |
17 |
Correct |
16 ms |
15992 KB |
Output is correct |
18 |
Correct |
16 ms |
16120 KB |
Output is correct |
19 |
Correct |
16 ms |
15992 KB |
Output is correct |
20 |
Correct |
16 ms |
15992 KB |
Output is correct |
21 |
Correct |
16 ms |
15992 KB |
Output is correct |
22 |
Correct |
16 ms |
15992 KB |
Output is correct |
23 |
Correct |
16 ms |
15992 KB |
Output is correct |
24 |
Correct |
16 ms |
15992 KB |
Output is correct |
25 |
Correct |
16 ms |
15992 KB |
Output is correct |
26 |
Correct |
16 ms |
15992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
15992 KB |
Output is correct |
2 |
Correct |
16 ms |
15992 KB |
Output is correct |
3 |
Correct |
16 ms |
15992 KB |
Output is correct |
4 |
Correct |
16 ms |
15992 KB |
Output is correct |
5 |
Correct |
16 ms |
15992 KB |
Output is correct |
6 |
Correct |
16 ms |
15992 KB |
Output is correct |
7 |
Correct |
16 ms |
15992 KB |
Output is correct |
8 |
Correct |
16 ms |
15992 KB |
Output is correct |
9 |
Correct |
16 ms |
15992 KB |
Output is correct |
10 |
Correct |
16 ms |
15992 KB |
Output is correct |
11 |
Correct |
16 ms |
15992 KB |
Output is correct |
12 |
Correct |
15 ms |
15992 KB |
Output is correct |
13 |
Correct |
16 ms |
15992 KB |
Output is correct |
14 |
Correct |
16 ms |
15992 KB |
Output is correct |
15 |
Correct |
18 ms |
15992 KB |
Output is correct |
16 |
Correct |
16 ms |
15992 KB |
Output is correct |
17 |
Correct |
16 ms |
15992 KB |
Output is correct |
18 |
Correct |
16 ms |
16120 KB |
Output is correct |
19 |
Correct |
16 ms |
15992 KB |
Output is correct |
20 |
Correct |
16 ms |
15992 KB |
Output is correct |
21 |
Correct |
16 ms |
15992 KB |
Output is correct |
22 |
Correct |
16 ms |
15992 KB |
Output is correct |
23 |
Correct |
16 ms |
15992 KB |
Output is correct |
24 |
Correct |
16 ms |
15992 KB |
Output is correct |
25 |
Correct |
16 ms |
15992 KB |
Output is correct |
26 |
Correct |
16 ms |
15992 KB |
Output is correct |
27 |
Correct |
16 ms |
15992 KB |
Output is correct |
28 |
Correct |
16 ms |
16120 KB |
Output is correct |
29 |
Correct |
16 ms |
15996 KB |
Output is correct |
30 |
Correct |
16 ms |
15992 KB |
Output is correct |
31 |
Correct |
16 ms |
15992 KB |
Output is correct |
32 |
Correct |
16 ms |
15992 KB |
Output is correct |
33 |
Correct |
16 ms |
15992 KB |
Output is correct |
34 |
Correct |
16 ms |
15992 KB |
Output is correct |
35 |
Correct |
18 ms |
15992 KB |
Output is correct |
36 |
Correct |
16 ms |
15992 KB |
Output is correct |
37 |
Correct |
16 ms |
15992 KB |
Output is correct |
38 |
Correct |
16 ms |
15992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
15992 KB |
Output is correct |
2 |
Correct |
16 ms |
15992 KB |
Output is correct |
3 |
Correct |
16 ms |
15992 KB |
Output is correct |
4 |
Correct |
16 ms |
15992 KB |
Output is correct |
5 |
Correct |
16 ms |
15992 KB |
Output is correct |
6 |
Correct |
16 ms |
15992 KB |
Output is correct |
7 |
Correct |
16 ms |
15992 KB |
Output is correct |
8 |
Correct |
16 ms |
15992 KB |
Output is correct |
9 |
Correct |
16 ms |
15992 KB |
Output is correct |
10 |
Correct |
16 ms |
15992 KB |
Output is correct |
11 |
Correct |
16 ms |
15992 KB |
Output is correct |
12 |
Correct |
15 ms |
15992 KB |
Output is correct |
13 |
Correct |
16 ms |
15992 KB |
Output is correct |
14 |
Correct |
16 ms |
15992 KB |
Output is correct |
15 |
Correct |
18 ms |
15992 KB |
Output is correct |
16 |
Correct |
16 ms |
15992 KB |
Output is correct |
17 |
Correct |
16 ms |
15992 KB |
Output is correct |
18 |
Correct |
16 ms |
16120 KB |
Output is correct |
19 |
Correct |
16 ms |
15992 KB |
Output is correct |
20 |
Correct |
16 ms |
15992 KB |
Output is correct |
21 |
Correct |
16 ms |
15992 KB |
Output is correct |
22 |
Correct |
16 ms |
15992 KB |
Output is correct |
23 |
Correct |
16 ms |
15992 KB |
Output is correct |
24 |
Correct |
16 ms |
15992 KB |
Output is correct |
25 |
Correct |
16 ms |
15992 KB |
Output is correct |
26 |
Correct |
16 ms |
15992 KB |
Output is correct |
27 |
Correct |
16 ms |
15992 KB |
Output is correct |
28 |
Correct |
16 ms |
16120 KB |
Output is correct |
29 |
Correct |
16 ms |
15996 KB |
Output is correct |
30 |
Correct |
16 ms |
15992 KB |
Output is correct |
31 |
Correct |
16 ms |
15992 KB |
Output is correct |
32 |
Correct |
16 ms |
15992 KB |
Output is correct |
33 |
Correct |
16 ms |
15992 KB |
Output is correct |
34 |
Correct |
16 ms |
15992 KB |
Output is correct |
35 |
Correct |
18 ms |
15992 KB |
Output is correct |
36 |
Correct |
16 ms |
15992 KB |
Output is correct |
37 |
Correct |
16 ms |
15992 KB |
Output is correct |
38 |
Correct |
16 ms |
15992 KB |
Output is correct |
39 |
Correct |
201 ms |
21088 KB |
Output is correct |
40 |
Correct |
374 ms |
22136 KB |
Output is correct |
41 |
Correct |
170 ms |
20112 KB |
Output is correct |
42 |
Correct |
174 ms |
19708 KB |
Output is correct |
43 |
Correct |
128 ms |
18556 KB |
Output is correct |
44 |
Correct |
445 ms |
22900 KB |
Output is correct |
45 |
Correct |
430 ms |
22904 KB |
Output is correct |
46 |
Correct |
490 ms |
22896 KB |
Output is correct |
47 |
Correct |
340 ms |
22904 KB |
Output is correct |
48 |
Correct |
377 ms |
22904 KB |
Output is correct |
49 |
Correct |
602 ms |
22904 KB |
Output is correct |
50 |
Correct |
610 ms |
22896 KB |
Output is correct |
51 |
Correct |
620 ms |
22936 KB |
Output is correct |
52 |
Correct |
598 ms |
22776 KB |
Output is correct |
53 |
Correct |
595 ms |
22776 KB |
Output is correct |
54 |
Correct |
594 ms |
22904 KB |
Output is correct |
55 |
Correct |
789 ms |
22896 KB |
Output is correct |
56 |
Correct |
775 ms |
22904 KB |
Output is correct |
57 |
Correct |
771 ms |
22776 KB |
Output is correct |
58 |
Correct |
770 ms |
22876 KB |
Output is correct |
59 |
Correct |
769 ms |
22892 KB |
Output is correct |
60 |
Correct |
765 ms |
23056 KB |
Output is correct |
61 |
Correct |
772 ms |
26744 KB |
Output is correct |
62 |
Correct |
826 ms |
26744 KB |
Output is correct |