Submission #506736

#TimeUsernameProblemLanguageResultExecution timeMemory
506736abc864197532Money (IZhO17_money)C++17
45 / 100
1521 ms58064 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mp make_pair #define eb emplace_back #define pb push_back #define X first #define Y second #define pii pair<int, int> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() void abc() {cout << endl;} template <typename T, typename ...U> void abc(T i, U ...j) { cout << i << ' ', abc(j...); } template <typename T> void printv(T l, T r) { for (; l != r; ++l) cout << *l << " \n"[l + 1 == r]; } #define test(x...) abc("[" + string(#x) + "]", x); const int N = 1000001; int main () { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector <int> a(n); multiset <int> s; for (int i = 0; i < n; ++i) { cin >> a[i], --a[i], s.insert(a[i]); } reverse(all(a)); int ans = 0; for (int i = 0, j = 0; i < n; i = j) { ans++; if (i + 1 == n) { break; } while (j < n && a[i] == a[j]) j++; auto it = s.lower_bound(a[i]); while (j < n && it != s.begin()) { --it; if (*it != a[j]) break; j++; } for (int k = i; k < j; ++k) { s.erase(s.lower_bound(a[k])); } } cout << ans << endl; } /* 6 3 6 4 5 1 2 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...