//Just try and the idea will come!
#include<bits/stdc++.h>
#define int long long int
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("%lld",&n);
for(i=0;i<n;i++)scanf("%lld",&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("%lld",ans);
}
Compilation message
money.cpp:22:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
money.cpp: In function 'int main()':
money.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&n);
~~~~~^~~~~~~~~~~
money.cpp:25: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("%lld",&a[i]);
~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
31608 KB |
Output is correct |
2 |
Correct |
28 ms |
31608 KB |
Output is correct |
3 |
Correct |
28 ms |
31608 KB |
Output is correct |
4 |
Correct |
28 ms |
31608 KB |
Output is correct |
5 |
Correct |
28 ms |
31736 KB |
Output is correct |
6 |
Correct |
28 ms |
31612 KB |
Output is correct |
7 |
Correct |
28 ms |
31608 KB |
Output is correct |
8 |
Correct |
28 ms |
31608 KB |
Output is correct |
9 |
Correct |
28 ms |
31608 KB |
Output is correct |
10 |
Correct |
28 ms |
31668 KB |
Output is correct |
11 |
Correct |
28 ms |
31608 KB |
Output is correct |
12 |
Correct |
28 ms |
31580 KB |
Output is correct |
13 |
Correct |
28 ms |
31608 KB |
Output is correct |
14 |
Correct |
28 ms |
31608 KB |
Output is correct |
15 |
Correct |
31 ms |
31668 KB |
Output is correct |
16 |
Correct |
28 ms |
31608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
31608 KB |
Output is correct |
2 |
Correct |
28 ms |
31608 KB |
Output is correct |
3 |
Correct |
28 ms |
31608 KB |
Output is correct |
4 |
Correct |
28 ms |
31608 KB |
Output is correct |
5 |
Correct |
28 ms |
31736 KB |
Output is correct |
6 |
Correct |
28 ms |
31612 KB |
Output is correct |
7 |
Correct |
28 ms |
31608 KB |
Output is correct |
8 |
Correct |
28 ms |
31608 KB |
Output is correct |
9 |
Correct |
28 ms |
31608 KB |
Output is correct |
10 |
Correct |
28 ms |
31668 KB |
Output is correct |
11 |
Correct |
28 ms |
31608 KB |
Output is correct |
12 |
Correct |
28 ms |
31580 KB |
Output is correct |
13 |
Correct |
28 ms |
31608 KB |
Output is correct |
14 |
Correct |
28 ms |
31608 KB |
Output is correct |
15 |
Correct |
31 ms |
31668 KB |
Output is correct |
16 |
Correct |
28 ms |
31608 KB |
Output is correct |
17 |
Correct |
28 ms |
31608 KB |
Output is correct |
18 |
Correct |
28 ms |
31608 KB |
Output is correct |
19 |
Correct |
28 ms |
31608 KB |
Output is correct |
20 |
Correct |
28 ms |
31608 KB |
Output is correct |
21 |
Correct |
28 ms |
31608 KB |
Output is correct |
22 |
Correct |
28 ms |
31580 KB |
Output is correct |
23 |
Correct |
28 ms |
31608 KB |
Output is correct |
24 |
Correct |
28 ms |
31608 KB |
Output is correct |
25 |
Correct |
28 ms |
31608 KB |
Output is correct |
26 |
Correct |
28 ms |
31736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
31608 KB |
Output is correct |
2 |
Correct |
28 ms |
31608 KB |
Output is correct |
3 |
Correct |
28 ms |
31608 KB |
Output is correct |
4 |
Correct |
28 ms |
31608 KB |
Output is correct |
5 |
Correct |
28 ms |
31736 KB |
Output is correct |
6 |
Correct |
28 ms |
31612 KB |
Output is correct |
7 |
Correct |
28 ms |
31608 KB |
Output is correct |
8 |
Correct |
28 ms |
31608 KB |
Output is correct |
9 |
Correct |
28 ms |
31608 KB |
Output is correct |
10 |
Correct |
28 ms |
31668 KB |
Output is correct |
11 |
Correct |
28 ms |
31608 KB |
Output is correct |
12 |
Correct |
28 ms |
31580 KB |
Output is correct |
13 |
Correct |
28 ms |
31608 KB |
Output is correct |
14 |
Correct |
28 ms |
31608 KB |
Output is correct |
15 |
Correct |
31 ms |
31668 KB |
Output is correct |
16 |
Correct |
28 ms |
31608 KB |
Output is correct |
17 |
Correct |
28 ms |
31608 KB |
Output is correct |
18 |
Correct |
28 ms |
31608 KB |
Output is correct |
19 |
Correct |
28 ms |
31608 KB |
Output is correct |
20 |
Correct |
28 ms |
31608 KB |
Output is correct |
21 |
Correct |
28 ms |
31608 KB |
Output is correct |
22 |
Correct |
28 ms |
31580 KB |
Output is correct |
23 |
Correct |
28 ms |
31608 KB |
Output is correct |
24 |
Correct |
28 ms |
31608 KB |
Output is correct |
25 |
Correct |
28 ms |
31608 KB |
Output is correct |
26 |
Correct |
28 ms |
31736 KB |
Output is correct |
27 |
Correct |
28 ms |
31580 KB |
Output is correct |
28 |
Correct |
27 ms |
31608 KB |
Output is correct |
29 |
Correct |
28 ms |
31608 KB |
Output is correct |
30 |
Correct |
28 ms |
31608 KB |
Output is correct |
31 |
Correct |
28 ms |
31608 KB |
Output is correct |
32 |
Correct |
28 ms |
31736 KB |
Output is correct |
33 |
Correct |
28 ms |
31736 KB |
Output is correct |
34 |
Correct |
28 ms |
31652 KB |
Output is correct |
35 |
Correct |
28 ms |
31608 KB |
Output is correct |
36 |
Correct |
28 ms |
31580 KB |
Output is correct |
37 |
Correct |
28 ms |
31608 KB |
Output is correct |
38 |
Correct |
32 ms |
31608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
31608 KB |
Output is correct |
2 |
Correct |
28 ms |
31608 KB |
Output is correct |
3 |
Correct |
28 ms |
31608 KB |
Output is correct |
4 |
Correct |
28 ms |
31608 KB |
Output is correct |
5 |
Correct |
28 ms |
31736 KB |
Output is correct |
6 |
Correct |
28 ms |
31612 KB |
Output is correct |
7 |
Correct |
28 ms |
31608 KB |
Output is correct |
8 |
Correct |
28 ms |
31608 KB |
Output is correct |
9 |
Correct |
28 ms |
31608 KB |
Output is correct |
10 |
Correct |
28 ms |
31668 KB |
Output is correct |
11 |
Correct |
28 ms |
31608 KB |
Output is correct |
12 |
Correct |
28 ms |
31580 KB |
Output is correct |
13 |
Correct |
28 ms |
31608 KB |
Output is correct |
14 |
Correct |
28 ms |
31608 KB |
Output is correct |
15 |
Correct |
31 ms |
31668 KB |
Output is correct |
16 |
Correct |
28 ms |
31608 KB |
Output is correct |
17 |
Correct |
28 ms |
31608 KB |
Output is correct |
18 |
Correct |
28 ms |
31608 KB |
Output is correct |
19 |
Correct |
28 ms |
31608 KB |
Output is correct |
20 |
Correct |
28 ms |
31608 KB |
Output is correct |
21 |
Correct |
28 ms |
31608 KB |
Output is correct |
22 |
Correct |
28 ms |
31580 KB |
Output is correct |
23 |
Correct |
28 ms |
31608 KB |
Output is correct |
24 |
Correct |
28 ms |
31608 KB |
Output is correct |
25 |
Correct |
28 ms |
31608 KB |
Output is correct |
26 |
Correct |
28 ms |
31736 KB |
Output is correct |
27 |
Correct |
28 ms |
31580 KB |
Output is correct |
28 |
Correct |
27 ms |
31608 KB |
Output is correct |
29 |
Correct |
28 ms |
31608 KB |
Output is correct |
30 |
Correct |
28 ms |
31608 KB |
Output is correct |
31 |
Correct |
28 ms |
31608 KB |
Output is correct |
32 |
Correct |
28 ms |
31736 KB |
Output is correct |
33 |
Correct |
28 ms |
31736 KB |
Output is correct |
34 |
Correct |
28 ms |
31652 KB |
Output is correct |
35 |
Correct |
28 ms |
31608 KB |
Output is correct |
36 |
Correct |
28 ms |
31580 KB |
Output is correct |
37 |
Correct |
28 ms |
31608 KB |
Output is correct |
38 |
Correct |
32 ms |
31608 KB |
Output is correct |
39 |
Correct |
211 ms |
35832 KB |
Output is correct |
40 |
Correct |
371 ms |
38528 KB |
Output is correct |
41 |
Correct |
176 ms |
35192 KB |
Output is correct |
42 |
Correct |
183 ms |
34752 KB |
Output is correct |
43 |
Correct |
138 ms |
34028 KB |
Output is correct |
44 |
Correct |
440 ms |
40144 KB |
Output is correct |
45 |
Correct |
423 ms |
40056 KB |
Output is correct |
46 |
Correct |
435 ms |
40132 KB |
Output is correct |
47 |
Correct |
336 ms |
40168 KB |
Output is correct |
48 |
Correct |
379 ms |
40124 KB |
Output is correct |
49 |
Correct |
631 ms |
40216 KB |
Output is correct |
50 |
Correct |
610 ms |
40184 KB |
Output is correct |
51 |
Correct |
642 ms |
40216 KB |
Output is correct |
52 |
Correct |
611 ms |
40156 KB |
Output is correct |
53 |
Correct |
629 ms |
40184 KB |
Output is correct |
54 |
Correct |
611 ms |
40184 KB |
Output is correct |
55 |
Correct |
835 ms |
40184 KB |
Output is correct |
56 |
Correct |
837 ms |
40828 KB |
Output is correct |
57 |
Correct |
819 ms |
40804 KB |
Output is correct |
58 |
Correct |
892 ms |
40640 KB |
Output is correct |
59 |
Correct |
820 ms |
40732 KB |
Output is correct |
60 |
Correct |
842 ms |
40588 KB |
Output is correct |
61 |
Correct |
826 ms |
40184 KB |
Output is correct |
62 |
Correct |
814 ms |
40132 KB |
Output is correct |