Submission #1184137

#TimeUsernameProblemLanguageResultExecution timeMemory
1184137al95ireyizMoney (IZhO17_money)C++20
0 / 100
0 ms324 KiB
//*** Bismillah ***//
// It's the evening of another day. And the end of mine...
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#if !defined(ONLINE_JUDGE) and !defined(EVAL)
#include "template/debug.h"
#else
#define d(x...)
#endif
#define ll long long
const ll INF = 1e9;
const ll INFL = 1e18;
const ll MOD = 1e9 + 7;
const ll maxn = 1e6 + 5;
ll n,m,k=0;
ll fw[maxn], a[maxn];
void upd(ll i, ll val){
    for(;i<maxn;i+=i&-i) fw[i] += val;
}
ll get(ll i){
    ll cv=0;
    for(;i>0;i-=i&-i) cv += fw[i];
    return cv;
}
void _(){
    cin>>n;
    for(ll i=1;i<=n;i++) cin>>a[i];
    // increasing olmalidi
    // a[l] ve a[r] arasinda olan eded olmamalidi evvelki segmentlerde
    ll cv = 0;
    for(ll i=1,j;i<=n;i++){
        cv ++;
        for(j=i+1;;j++){
            if(j > n) break;
            if(a[j-1] > a[j] or (get(a[i]+1) != get(a[j]-1))) break;
        }
        for(;i<j;i++){
            upd(a[i], 1);
        }
    }
    cout<<cv<<'\n';
}
signed main(){
    auto testcaseruntime=clock();
    cin.tie(0)->sync_with_stdio(0);
    ll t=1;
    // cin>>t;
    while(t--){
        _();
    }
    cerr<<"\n\033[1;31mTime: \033[1;30m"
        <<(double)(clock()-testcaseruntime)/1000000<<"\033[1;32m seconds\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...