제출 #1129711

#제출 시각아이디문제언어결과실행 시간메모리
1129711assanaliMoney (IZhO17_money)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define pb push_back
#define lv v+v
#define rv v+v+1
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair <long long, long long>;
using pii = pair <int,int>;
using pld = pair <long double, long double>;
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
long long mod = 1e9 + 7;
const ll N = 1e6 + 10;
const ll M = 1e6 + 10;
const ll P = 311;
const ld EPS = 1e-7;
const ll block = 450;
const ll inf = 1e18;
ll n,a[N],pos[N],ans,t[N];
pll b[N];
void upd(ll k,ll val) {
    while(k <= n) {
        t[k] += val;
        k += k & -k;
    }
}
ll sum(ll k) {
    ll tyla = 0;
    while(k >= 1) {
        tyla += t[k];
        k -= k & -k;
    }
    return tyla;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll _=1; //cin>>_;
while(_--) {
    cin>>n;
    for(ll i = 1; i<=n; i++) {
        cin>>a[i];
        b[i] = {a[i], i};
    }
    sort(b+1,b+1+n);
    set <ll> s;
    for(ll i = 1; i<=n; i++) {
        pos[b[i].S] = i;
        upd(i,1);
    }
    ll lst;
    pos[n+1] = n+1;
    for(ll i = n; i>0; i--) {
        upd(pos[i], -1);
        ans++;
        ll fir = sum(pos[i]), sec = sum(pos[i+1]);
        //cout<<i<<" "<<pos[i]<<" "<<fir<<" "<<sec<<" "<<"\n";
        if(sec - fir == 0 && pos[i+1] > pos[i] && i!=n) {
            //cout<<i<<" \n";
            ans--;
        }
    }
    cout<<ans;
}
return 0;
}
// equal, min, max, 1, random, build
/*
6
3 6 4 5 1 2
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...