답안 #710112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710112 2023-03-15T04:50:30 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],mx,mi;
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);
   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);
            //cout<<it<<endl;
         }
         v.clear();
         mx=a[i-1];
         ans++;
         //cout<<"this\n";
      }else{
         mi=a[i-1];
         if(range_sum(a[i-1],a[i])!=a[i]-a[i-1]-1){
            ans++;
            for(auto it: v){
               update(it,1);
               //cout<<it<<endl;
            }
            v.clear();
            //cout<<"other\n";
         }
      }
      //rep(i,n)cout<<range_sum(i,i);cout<<endl;
   }
   cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -