Submission #710211

# Submission time Handle Problem Language Result Execution time Memory
710211 2023-03-15T05:45:45 Z safaricola Money (IZhO17_money) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pi pair <int, int>
#define pii pair <pi, int>
#define rep(i,n) for(ll i = 1; i <= n; i++)
#define fi first
#define se second
using namespace std;
int n, a[1000010];
bool vis[1000010];
#define debug(x) cout<<#x<<' '<<x<<endl;
int fw[1000010];
void update(int x, int v) {
    for (; x<n+1; x+=x&(-x)) fw[x] += v;
}
int sum(int x) {
   int res = 0;
   for(; x; x-=x&(-x)) res += fw[x];
   return res; 
}
int range_sum(int x, int y) { //inclusive
    return sum(y)-sum(x-1);
}

int main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   cin>>n;
   rep(i,n)cin>>a[i];
   int ans=1;
   vector<int> v;
   for(int i=n; i>1; i--){ 
      //debug(i);
      v.pb(a[i]);
      if(a[i-1]>a[i]){
         for(auto it: v)update(it,1);
         v.clear();
         ans++;
      }else{
         if(range_sum(a[i-1],a[i])!=a[i]-a[i-1]-1){
            ans++;
            for(auto it: v)update(it,1);
            v.clear();
         }
      }
      //rep(i,n)cout<<range_sum(i,i);cout<<endl;
   }
   cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -