This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
const int MXN = 1000005;
int n;
vector<int> v;
int a[MXN];
multiset<int> MS;
int f(int sr) {
auto it = MS.find(a[sr]);
FOR(i, sr + 1, n) {
it = MS.erase(it);
if (it == MS.begin()) return i;
it = prev(it);
if (*it != a[i]) return i;
}
return n;
}
void miku() {
cin >> n;
v.resize(n);
for (auto &i : v) cin >> i;
n = 0;
for (int i = 0, j = 0; i < v.size(); i = j) {
while (j < v.size() && v[i] == v[j]) j++;
a[n] = v[i];
n++;
}
FOR(i, 0, n) MS.insert(a[i]);
reverse(a, a + n);
int ans = 0, now = 0;
while (now < n) {
now = f(now);
ans++;
}
cout << ans << '\n';
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}
Compilation message (stderr)
money.cpp: In function 'void miku()':
money.cpp:43:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int i = 0, j = 0; i < v.size(); i = j) {
| ~~^~~~~~~~~~
money.cpp:44:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | while (j < v.size() && v[i] == v[j]) j++;
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |