Submission #499030

#TimeUsernameProblemLanguageResultExecution timeMemory
499030beksultan04Money (IZhO17_money)C++14
100 / 100
790 ms31360 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...