#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,int x){
if (l == r){
der[v] = x;
ret;
}
int m = l+r>>1;
if (m < pos)
update((v<<1)+1,m+1,r,pos,x);
else update(v<<1,l,m,pos,x);
der[v] = der[v<<1]+der[(v<<1)+1];
}
int get_ans(int v,int l,int r,int ql,int qr){
if (ql <= l && r <= qr)ret der[v];
if (qr < l || r < ql)ret 0;
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,x,y,ans=0;
cin>>n;
int p;
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++],1);
}
}
}
cout <<ans;
}
Compilation message
money.cpp: In function 'void update(long long int, 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:38:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | int m = l+r>>1;
| ~^~
money.cpp: At global scope:
money.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
43 | main(){
| ^~~~
money.cpp: In function 'int main()':
money.cpp:44:10: warning: unused variable 'x' [-Wunused-variable]
44 | int n,i,x,y,ans=0;
| ^
money.cpp:44:12: warning: unused variable 'y' [-Wunused-variable]
44 | int n,i,x,y,ans=0;
| ^
money.cpp:46:6: warning: unused variable 'p' [-Wunused-variable]
46 | int p;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |