#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[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=1;
cin>>n;
set <int> s;
int p;
s.insert(0);
cin>>p;
for (i=2;i<=n;++i){
cin>>x;
if (x > p){
int c = get_ans(1,1,n,p,x);
if (c > 0)ans++;
}
else ans++;
update(1,1,n,p,1);
p = x;
}
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:12: warning: unused variable 'y' [-Wunused-variable]
44 | int n,i,x,y,ans=1;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |