답안 #156178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
156178 2019-10-04T09:22:31 Z andrew Money (IZhO17_money) C++17
0 / 100
11 ms 8312 KB
#include <bits/stdc++.h>

//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)

using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 1e6 + 2;
const ll inf = 3e18;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());

template <typename T> void vout(T s){cout << s << endl;exit(0);}

ll t[MAXN], poz[MAXN];
bool Beg[MAXN], End[MAXN];

void u(ll pos, ll val){for(; pos <= N; pos += pos & -pos)t[pos] += val;}
ll f(ll pos){ll res = 0; for(; pos > 0; pos -= pos & -pos)res += t[pos]; return res;}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    set <ll> s;

    ll n;
    cin >> n;

    vector <ll> a(n + 1), pozit(n + 1), is_begin(n + 1);

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        poz[a[i]]++;
    }

    for(int i = 1; i <= N; i++)poz[i] += poz[i - 1];

    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ll P = poz[a[i]]--;
        pozit[i] = P;
        is_begin[i] = 1;
        if(i > 1 && a[i - 1] <= a[i]){
            ll x = pozit[i - 1];
            if(!(f(P - 1) - f(x))){
                if(!is_begin[i - 1])u(i - 1, 1);
                ans--;
                is_begin[i] = 0;
            }
        }
        ans++;
    }

    cout << ans << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8184 KB Output is correct
2 Incorrect 11 ms 8312 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8184 KB Output is correct
2 Incorrect 11 ms 8312 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8184 KB Output is correct
2 Incorrect 11 ms 8312 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8184 KB Output is correct
2 Incorrect 11 ms 8312 KB Output isn't correct
3 Halted 0 ms 0 KB -