# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
35195 | ulna | Money (IZhO17_money) | C++11 | 0 ms | 9828 KiB |
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;
// why am I so weak
int n;
int a[1000055];
int dat[1000055];
inline void read(int &x) {
x = 0;
char ch = 0;
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9') {
x = x * 10 + (ch - '0');
ch = getchar();
}
}
void add(int id) {
while (id <= (int)1e6) {
dat[id]++;
id += id & -id;
}
}
int get(int id) {
int res = 0;
while (id > 0) {
res += dat[id];
id -= id & -id;
}
return res;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
read(a[i]);
}
int res = 1;
vector<int> buf;
buf.push_back(a[0]);
for (int i = 0; i + 1 < n; i++) {
if (a[i + 1] < a[i]) {
res++;
for (auto u : buf) add(u);
buf.clear();
buf.push_back(a[i + 1]);
continue;
}
if (a[i + 1] == a[i]) continue;
if (get(a[i + 1] - 1) - get(a[i] - 1) > 0) {
res++;
for (auto u : buf) add(u);
buf.clear();
buf.push_back(a[i + 1]);
}
}
printf("%d\n", res);
return 0;
}
Compilation message (stderr)
# | 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... |