/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 528.0 KiB
#3 Accepted 1ms 540.0 KiB
#4 Accepted 1ms 540.0 KiB
#5 Accepted 2ms 540.0 KiB
#6 Accepted 1ms 540.0 KiB
#7 Accepted 1ms 540.0 KiB
#8 Accepted 1ms 540.0 KiB
#9 Accepted 1ms 540.0 KiB
#10 Accepted 1ms 492.0 KiB
#11 Accepted 1ms 608.0 KiB
#12 Accepted 1ms 620.0 KiB
#13 Accepted 1ms 328.0 KiB
#14 Accepted 1ms 332.0 KiB
#15 Accepted 1ms 540.0 KiB
#16 Accepted 1ms 540.0 KiB
#17 Accepted 1ms 684.0 KiB
#18 Accepted 1ms 516.0 KiB
#19 Accepted 1ms 504.0 KiB
#20 Accepted 1ms 384.0 KiB
#21 Accepted 1ms 540.0 KiB
#22 Accepted 1ms 540.0 KiB
#23 Accepted 1ms 456.0 KiB
#24 Accepted 1ms 552.0 KiB
#25 Accepted 1ms 488.0 KiB
#26 Accepted 1ms 540.0 KiB
#27 Accepted 1ms 540.0 KiB
#28 Accepted 1ms 540.0 KiB
#29 Accepted 1ms 588.0 KiB
#30 Accepted 1ms 540.0 KiB
#31 Accepted 1ms 320.0 KiB
#32 Accepted 1ms 540.0 KiB
#33 Accepted 1ms 584.0 KiB
#34 Accepted 1ms 332.0 KiB
#35 Accepted 1ms 540.0 KiB
#36 Accepted 1ms 512.0 KiB
#37 Accepted 1ms 512.0 KiB
#38 Accepted 1ms 540.0 KiB
#39 Accepted 1ms 540.0 KiB
#40 Accepted 1ms 540.0 KiB
#41 Accepted 1ms 540.0 KiB
#42 Accepted 1ms 540.0 KiB
#43 Accepted 1ms 332.0 KiB
#44 Accepted 1ms 540.0 KiB
#45 Accepted 2ms 540.0 KiB
#46 Accepted 1ms 540.0 KiB
#47 Accepted 1ms 540.0 KiB
#48 Accepted 1ms 540.0 KiB
#49 Accepted 1ms 584.0 KiB
#50 Accepted 1ms 772.0 KiB
#51 Accepted 1ms 540.0 KiB
#52 Accepted 1ms 540.0 KiB
#53 Accepted 1ms 556.0 KiB
#54 Accepted 1ms 540.0 KiB
#55 Accepted 1ms 540.0 KiB
#56 Accepted 1ms 540.0 KiB
#57 Accepted 1ms 540.0 KiB
#58 Accepted 1ms 540.0 KiB
#59 Accepted 1ms 332.0 KiB
#60 Accepted 1ms 540.0 KiB
#61 Accepted 3ms 540.0 KiB
#62 Accepted 2ms 588.0 KiB
#63 Accepted 2ms 540.0 KiB
#64 Accepted 3ms 540.0 KiB
#65 Accepted 2ms 540.0 KiB
#66 Accepted 2ms 540.0 KiB
#67 Accepted 2ms 540.0 KiB
#68 Accepted 2ms 540.0 KiB
#69 Accepted 2ms 540.0 KiB
#70 Accepted 2ms 540.0 KiB
#71 Accepted 5ms 796.0 KiB
#72 Accepted 2ms 540.0 KiB
#73 Accepted 2ms 540.0 KiB
#74 Accepted 4ms 840.0 KiB
#75 Accepted 4ms 588.0 KiB
#76 Accepted 2ms 540.0 KiB
#77 Accepted 2ms 796.0 KiB
#78 Accepted 2ms 540.0 KiB
#79 Accepted 2ms 796.0 KiB
#80 Accepted 2ms 772.0 KiB
#81 Accepted 6ms 728.0 KiB
#82 Accepted 3ms 540.0 KiB
#83 Accepted 3ms 796.0 KiB
#84 Accepted 5ms 708.0 KiB
#85 Accepted 4ms 540.0 KiB
#86 Accepted 3ms 540.0 KiB
#87 Accepted 2ms 796.0 KiB
#88 Accepted 3ms 540.0 KiB
#89 Accepted 2ms 812.0 KiB
#90 Accepted 3ms 796.0 KiB
#91 Accepted 45ms 1.449 MiB
#92 Accepted 13ms 1.109 MiB
#93 Accepted 14ms 1.316 MiB
#94 Accepted 29ms 2.02 MiB
#95 Accepted 29ms 2.02 MiB
#96 Accepted 13ms 1.273 MiB
#97 Accepted 12ms 1.188 MiB
#98 Accepted 14ms 1.27 MiB
#99 Accepted 12ms 1.184 MiB
#100 Accepted 12ms 1.098 MiB

Code

#include <bits/stdc++.h>
#include <cstdio>
using namespace std;

#define sp << " " << 
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define PI 3.1415926535897932384626

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sortall(x) sort(all(x))
#define sortrall(x) sort(rall(x))

#define printv(v) for(auto x : v) cout << x << " "; cout << "\n"
#define printm(m) for(auto x : m) cout << x.F sp x.S << "\n"

#define make_unique(x) sortall(x); (x).resize(unique(all(x)) - (x).begin())

const int mod = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template<typename T1, typename T2>
using safe_map = unordered_map<T1, T2, custom_hash>;

template<typename T>
using safe_set = unordered_set<T, custom_hash>;

template<typename T>
void debug(T x) {
    cerr << x << endl;
}

template<typename T, typename... Args>
void debug(T x, Args... args) {
    cerr << x << " ";
    debug(args...);
}

void fastIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void fraction() {
    cout.unsetf(ios::floatfield); 
    cout.precision(10); 
    cout.setf(ios::fixed,ios::floatfield);
}

void yn(bool res, bool cap = false) {
    if(!cap) cout << ((res) ? "YES\n" : "NO\n");
    else cout << ((res) ? "Yes\n" : "No\n");
}

inline int nxt() {
    int x;
    cin >> x;
    return x;
}
 

void proc(){

}

const int MAX = 1e5 + 5;

struct BIT {
    vector<int> tree;
    BIT(int n) : tree(n + 1, 0) {}

    void update(int i, int v) {
        for (; i < (int)tree.size(); i += i & -i)
            tree[i] += v;
    }

    int query(int i) {
        int res = 0;
        for (; i > 0; i -= i & -i)
            res += tree[i];
        return res;
    }

    int query(int l, int r) {
        return query(r) - query(l - 1);
    }
};


void solve() {
    int n; cin >> n;
    vector<int> v(n);
    for (auto &x : v) cin >> x;

    vector<int> comp = v;
    sortall(comp);
    make_unique(comp);

    auto id = [&](int x) {
        return lower_bound(all(comp), x) - comp.begin() + 1;
    };

    BIT bit(comp.size());
    vector<bool> ans(n, false);

    for (int i = 0; i < n; i++) {
        int val = id(v[i]);
        int cnt = bit.query(val);
        if (cnt >= v[i]) ans[i] = true;
        bit.update(val, 1);
    }

    bit = BIT(comp.size());
    for (int i = n - 1; i >= 0; i--) {
        int val = id(v[i]);
        int cnt = bit.query(val, comp.size()); 
        if (cnt >= v[i]) ans[i] = true;
        bit.update(val, 1);
    }

    cout << count(all(ans), true) << '\n';
}

int main() {
    fastIO(); 
    proc();

    int tc = 1;
    // tc = nxt();
    for (int t = 1; t <= tc; t++) {
        // cout << "Case " << t << ": ";
        solve();
    }
}

Information

Submit By
Type
Submission
Problem
P1184 The Curious Kid and the Number Game
Contest
Brain Booster #9
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-06 17:09:37
Judged At
2025-04-06 17:09:37
Judged By
Score
100
Total Time
45ms
Peak Memory
2.02 MiB