/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 4ms 3.523 MiB
#2 Accepted 4ms 3.52 MiB
#3 Accepted 4ms 3.52 MiB
#4 Accepted 4ms 3.434 MiB
#5 Wrong Answer 4ms 3.52 MiB
#6 Wrong Answer 4ms 3.52 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define int long long

template<class Fun> class y_combinator_result {
  Fun fun_;
public:
  template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
  template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename... Args> ostream& operator<<(ostream& os, const tuple<Args...>& t) { os << '('; apply([&os](const Args&... args) { size_t n = 0; ((os << args << (++n != sizeof...(Args) ? ", " : "")), ...); }, t); return os << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

template<typename T>ostream& operator<<(ostream& os, queue<T>& _q) { queue<T> q = _q; os << '{'; string sep; while (!q.empty()) { os << sep << q.front(); sep = ", "; q.pop(); } return os << '}';}
template<typename T>ostream& operator<<(ostream& os, stack<T> st) { os << '{'; string sep; while (!st.empty()) { os << sep << st.top(); sep = ", "; st.pop(); } return os << '}';}
template<typename T, typename Container, typename Compare>ostream& operator<<(ostream& os, priority_queue<T, Container, Compare> pq) { os << '{'; string sep; while (!pq.empty()) { os << sep << pq.top(); sep = ", "; pq.pop(); } return os << '}';}
template<size_t N>ostream& operator<<(ostream& os, const bitset<N>& bs) { return os << bs.to_string();}

void debug_out() { cout << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cout << ' ' << H; debug_out(T...); }
#ifdef LOCAL_DEBUG
  #define debug(...) cout << "[Line " <<  __LINE__ << "] (" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
  #define debug(...)
#endif

/*
  
*/

const int MAXN = 2e5 + 5;

template <class T>
struct BIT { //1-indexed
  int n; vector<T> t;
  BIT() {}
  BIT(int _n) {
    n = _n; t.assign(n + 1, 0);
  }
  T query(int i) {
    T ans = 0;
    for (; i >= 1; i -= (i & -i)) ans += t[i];
    return ans;
  }
  void upd(int i, T val) {
    if (i <= 0) return;
    for (; i <= n; i += (i & -i)) t[i] += val;
  }
  void upd(int l, int r, T val) {
    upd(l, val);
    upd(r + 1, -val);
  }
  T query(int l, int r) {
    return query(r) - query(l - 1);
  }
};

void run_case() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  
  BIT<int> bit(MAXN);
  vector<int> left(n);
  for (int i = 0; i < n; i++) {
    left[i] = bit.query(a[i]);
    bit.upd(a[i], 1);
  }
  
  bit = BIT<int>(MAXN);
  vector<int> right(n);
  for (int i = n - 1; i >= 0; i--) {
    right[i] = (n - 1 - i) - bit.query(a[i] - 1);
    bit.upd(a[i], 1);
  }
  
  int res = 0;
  for (int i = 0; i < n; i++) {
    res += (max(left[i], right[i]) >= a[i]);
  }
  cout << res << '\n';
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin.exceptions(cin.failbit);

  int T = 1;
  // cin >> T;
  for (int t = 1; t <= T; t++) {
    // cout << "Case #" << t << ": ";
    run_case();
  }

  return 0;
}

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 16:51:32
Judged At
2025-04-06 16:51:32
Judged By
Score
4
Total Time
4ms
Peak Memory
3.523 MiB