Submission #168936

#TimeUsernameProblemLanguageResultExecution timeMemory
168936beso123Money (IZhO17_money)C++14
45 / 100
1580 ms61944 KiB
#include <bits/stdc++.h>
#define int long long
#define N 1000006
using namespace std;
int n,a[N],fen[N],ans;
set <int> st;
void UPD(int x,int val){
    while(x<=N){
        fen[x]+=val;
        x=x+(x&(-x));
    }
}
int GET(int x){
    int sum=0;
    while(x>=1){
        sum+=fen[x];
        x=x-(x&(-x));
    }
    return sum;
}
int get(int l,int r){
    if(l>r)
        return 0;
    return GET(r)-GET(l-1);
}
main(){
	scanf("%lld",&n);
	for(int k=1;k<=n;k++){
		scanf("%lld",&a[k]);
	}
	int l=1;
	for(int r=1;r<=n+1;r++){
		if(a[r-1]>a[r]){
			ans++;
			for(int j=l;j<=r-1;j++)
				st.insert(a[j]);
                l=r;
			continue;
		}
		auto it=st.upper_bound(a[l]);
		if(it!=st.end() && *it<a[r]){
			ans++;
			for(int j=l;j<=r-1;j++)
				st.insert(a[j]);
                l=r;
		}
	}
	printf("%lld",ans);
return 0;
}

Compilation message (stderr)

money.cpp:26:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
money.cpp: In function 'int main()':
money.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
  ~~~~~^~~~~~~~~~~
money.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a[k]);
   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...