Submission #1296704

#TimeUsernameProblemLanguageResultExecution timeMemory
1296704OmarAlimammadzadeMoney (IZhO17_money)C++20
0 / 100
4 ms7996 KiB
#include "bits/stdc++.h" using namespace std; #ifdef DEBUG #include "algo/debug" #else #define debug(...) #endif #define int long long struct fenwick { vector<int> t; int n; fenwick(int n) : n(n) { t.assign(n + 1, 0); } void add(int i) { for (; i <= n; i += i & -i) { t[i]++; } } int ask(int i) { int ans = 0; for (; i >= 1; i -= i & -i) { ans += t[i]; } return ans; } int ask(int l, int r) { return ask(r) - ask(l - 1); } }; void run() { int n; cin >> n; int a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } int m = *max_element(a + 1, a + n + 1); fenwick ft(m); int ans = 1, j = 1; for (int i = 2; i <= n; i++) { if (a[i] < a[i - 1] or ft.ask(a[j] + 1, a[i] - 1)) { while (j < i) { ft.add(a[j++]); } ans++; } } cout << ans << '\n'; } signed main() { ios::sync_with_stdio(0); cin.tie(nullptr); int tt = 1; // cin >> tt; for (int cs = 1; cs <= tt; cs++) { #ifdef DEBUG cout << "\n--- Case #" << cs << " ---\n"; cerr << "\n--- Logs #" << cs << " ---\n"; #endif run(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...