Submission #1273625

#TimeUsernameProblemLanguageResultExecution timeMemory
1273625bbldrizzyMoney (IZhO17_money)C++20
0 / 100
8 ms16048 KiB
#include <bits/stdc++.h> #include <ios> #include <iostream> #include <set> #include <random> using namespace std; using ll = long long; using P = pair<ll, ll>; #define f first #define s second const int MOD = 1e9+7; const ll inf = 4*1e18; const int mx = 5*1e5+5; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; const int N = 1e6+5; template <class T> class BIT { private: int size; vector<T> bit; vector<T> arr; public: BIT(int size) : size(size), bit(size + 1), arr(size) {} /** Sets the value at index ind to val. */ void set(int ind, T val) { add(ind, val - arr[ind]); } /** Adds val to the element at index ind. */ void add(int ind, T val) { arr[ind] += val; ind++; for (; ind <= size; ind += ind & -ind) { bit[ind] += val; } } /** @return The sum of all values in [0, ind]. */ T pref_sum(int ind) { ind++; T total = 0; for (; ind > 0; ind -= ind & -ind) { total += bit[ind]; } return total; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; BIT<ll> bit(N); ll ans = 0; ll prev = -1; for (int i = 0; i < n; i++) { int x; cin >> x; if (prev == -1 || x < prev) { ans++; prev = x; // cout << "i: " << i << "\n"; } else { ll v = bit.pref_sum(x-1)-bit.pref_sum(prev); // cout << i << ", " << bit.pref_sum(x) << " " << bit.pref_sum(prev) << "\n"; if (v > 0) { // cout << "i2: " << i << "\n"; ans++; } prev = x; } bit.add(x, 1); } cout << ans << "\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...