Submission #168867

# Submission time Handle Problem Language Result Execution time Memory
168867 2019-12-16T18:13:46 Z beso123 Money (IZhO17_money) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
#define int long long
#define N 1000006
using namespace std;
int n,a[N],fen[N];
void UPD(int x,int val){
    x+=1;
    while(x<=N){
        fen[x]+=val;
        x=x+(x&(-x));
    }
}
int GET(int x){
    x+=1;
    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(){
cin>>n;
for(int k=1;k<=n;k++)
    cin>>a[k];
int ans=1;
int j=0;
while(j<n && a[j]<a[j+1]){
    UPD(a[j],1);
    j++;
}
j++;
int prev=a[j];
for(int k=j;k<=n;k++){
        int h=get(prev,a[k]);
    if(a[k]>a[k+1] || h!=0){
        ans++;
        prev=a[k]+1;
    }
    else{
    prev=a[k];
    }
    UPD(a[k],1);
}
cout<<ans;
return 0;
}

Compilation message

money.cpp:27:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -