Submission #180291

#TimeUsernameProblemLanguageResultExecution timeMemory
180291NightmarMoney (IZhO17_money)C++17
0 / 100
2 ms376 KiB
#include <iostream> #include <algorithm> #include <cmath> #include <string> #include <cstdlib> #include <vector> #include <queue> #include <set> #include <map> #include <cstdio> #include <iomanip> #include <unordered_map> #define SWS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define pb push_back #define ppb pop_back #define ft first #define sd second #define readf freopen("input.txt", "r", stdin) #define writef freopen("output.txt", "w", stdout) #define files readf; writef using namespace std; typedef long long ll; typedef pair<int, int> pii; const int Z = 999; const int N = (int)1e6 + 228; const int INF = (int)1e9 + 5; const int MOD = (int)1e9 + 7; int a[N], t[4 * N]; void update(int v, int tl, int tr, int pos) { if (tl == tr) { t[v]++; return; } int mid = (tl + tr) / 2; if (pos <= mid) update(2 * v, tl, mid, pos); else update(2 * v + 1, mid + 1, tr, pos); t[v] = t[2 * v] + t[2 * v + 1]; } int get(int v, int tl, int tr, int l, int r) { if (tl >= l && tr <= r) { return t[v]; } if (tl > r || tr < l) { return 0; } int mid = (tl + tr) / 2; return get(2 * v, tl, mid, l, r) + get(2 * v + 1, mid + 1, tr, l, r); } int main() { SWS; srand(time(0)); //files; int n; cin >> n; vector<int> v; v.pb(0); for (int i = 1; i <= n; i++) { cin >> a[i]; v.pb(a[i]); } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); int ans = 0; for (int i = 1; i <= n; i++) { vector<int> kek; int L = upper_bound(v.begin(), v.end(), a[i]) - v.begin(); int R = lower_bound(v.begin(), v.end(), a[i]) - v.begin() - 1; //cout << "DEBUG : " << i << "\n"; //cout << L << ' ' << R << endl; int now = lower_bound(v.begin(), v.end(), a[i]) - v.begin(); int r = i; kek.pb(now); while (r <= n && a[r + 1] >= a[r] && !get(1, 1, v.size(), L, R)) { r++; R = lower_bound(v.begin(), v.end(), a[r]) - v.begin() - 1; now = lower_bound(v.begin(), v.end(), a[r]) - v.begin(); kek.pb(now); //cout << L << ' ' << R << endl; } i = r; ans++; for (int q : kek) { update(1, 1, v.size(), q); } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...