#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int,int>
#define ret return
#define fr first
#define sc second
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define nosol puts("-1");
#define pb push_back
#define endi puts("");
#define ordered_set tree <int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N = 1e6+12,INF = 1e15+7;
int der[4*N],a[N];
void update(int v,int l,int r,int pos){
if (l == r){
der[v]++;
ret;
}
int m = l+r>>1;
if (m < pos)
update((v<<1)+1,m+1,r,pos);
else update(v<<1,l,m,pos);
der[v] = der[v<<1]+der[(v<<1)+1];
}
int get_ans(int v,int l,int r,int ql,int qr){
if (r <= ql || qr <= l || ql > qr)ret 0;
if (ql < l && r < qr)ret der[v];
int m = l+r>>1;
ret get_ans(v<<1,l,m,ql,qr)+get_ans(v<<1|1,m+1,r,ql,qr);
}
main(){
int n,i,ans=0;
cin>>n;
for (i=1;i<=n;++i)
cin>>a[i];
int l = 1;
for (i=1;i<=n;++i){
int x = get_ans(1,1,1000000,a[l],a[i+1]);
if (a[i+1] < a[i] || x){
ans++;
while (l <= i){
update(1,1,1000000,a[l++]);
}
}
}
cout <<ans;
}
Compilation message
money.cpp: In function 'void update(long long int, long long int, long long int, long long int)':
money.cpp:28:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int m = l+r>>1;
| ~^~
money.cpp: In function 'long long int get_ans(long long int, long long int, long long int, long long int, long long int)':
money.cpp:39:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | int m = l+r>>1;
| ~^~
money.cpp: At global scope:
money.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
44 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
0 ms |
432 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
556 KB |
Output is correct |
16 |
Correct |
0 ms |
552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
0 ms |
432 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
556 KB |
Output is correct |
16 |
Correct |
0 ms |
552 KB |
Output is correct |
17 |
Correct |
0 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
552 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
432 KB |
Output is correct |
21 |
Correct |
0 ms |
556 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
0 ms |
424 KB |
Output is correct |
25 |
Correct |
1 ms |
676 KB |
Output is correct |
26 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
0 ms |
432 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
556 KB |
Output is correct |
16 |
Correct |
0 ms |
552 KB |
Output is correct |
17 |
Correct |
0 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
552 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
432 KB |
Output is correct |
21 |
Correct |
0 ms |
556 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
0 ms |
424 KB |
Output is correct |
25 |
Correct |
1 ms |
676 KB |
Output is correct |
26 |
Correct |
1 ms |
716 KB |
Output is correct |
27 |
Correct |
0 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
260 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
552 KB |
Output is correct |
33 |
Correct |
1 ms |
424 KB |
Output is correct |
34 |
Correct |
1 ms |
556 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
2 ms |
3240 KB |
Output is correct |
38 |
Correct |
2 ms |
3276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
0 ms |
432 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
556 KB |
Output is correct |
16 |
Correct |
0 ms |
552 KB |
Output is correct |
17 |
Correct |
0 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
552 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
432 KB |
Output is correct |
21 |
Correct |
0 ms |
556 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
0 ms |
424 KB |
Output is correct |
25 |
Correct |
1 ms |
676 KB |
Output is correct |
26 |
Correct |
1 ms |
716 KB |
Output is correct |
27 |
Correct |
0 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
260 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
552 KB |
Output is correct |
33 |
Correct |
1 ms |
424 KB |
Output is correct |
34 |
Correct |
1 ms |
556 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
2 ms |
3240 KB |
Output is correct |
38 |
Correct |
2 ms |
3276 KB |
Output is correct |
39 |
Correct |
229 ms |
7388 KB |
Output is correct |
40 |
Correct |
375 ms |
12176 KB |
Output is correct |
41 |
Correct |
186 ms |
6060 KB |
Output is correct |
42 |
Correct |
189 ms |
5948 KB |
Output is correct |
43 |
Correct |
125 ms |
4332 KB |
Output is correct |
44 |
Correct |
475 ms |
15156 KB |
Output is correct |
45 |
Correct |
524 ms |
15000 KB |
Output is correct |
46 |
Correct |
486 ms |
15284 KB |
Output is correct |
47 |
Correct |
509 ms |
14984 KB |
Output is correct |
48 |
Correct |
494 ms |
15092 KB |
Output is correct |
49 |
Correct |
621 ms |
31360 KB |
Output is correct |
50 |
Correct |
600 ms |
31268 KB |
Output is correct |
51 |
Correct |
631 ms |
31236 KB |
Output is correct |
52 |
Correct |
634 ms |
31304 KB |
Output is correct |
53 |
Correct |
638 ms |
31300 KB |
Output is correct |
54 |
Correct |
611 ms |
31140 KB |
Output is correct |
55 |
Correct |
766 ms |
31244 KB |
Output is correct |
56 |
Correct |
752 ms |
31244 KB |
Output is correct |
57 |
Correct |
708 ms |
31248 KB |
Output is correct |
58 |
Correct |
748 ms |
31244 KB |
Output is correct |
59 |
Correct |
729 ms |
31280 KB |
Output is correct |
60 |
Correct |
749 ms |
31172 KB |
Output is correct |
61 |
Correct |
790 ms |
31248 KB |
Output is correct |
62 |
Correct |
737 ms |
31248 KB |
Output is correct |