# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
999084 | IdanRosen | Diversity (CEOI21_diversity) | C++98 | 0 ms | 348 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;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
int main() {
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<int> arr(n);
for (auto &ref: arr) cin >> ref;
while (q--) {
int left, right;
cin >> left >> right;
left--;
std::sort(arr.begin(), arr.end());
vector<int> lens;
{
int last = -1;
for (int i = 0; i < n; i++) {
if (last == -1) {
last = i;
continue;
}
if (arr[i] == arr[last]) {}
else {
lens.push_back(i - last);
last = i;
}
}
lens.push_back(n - last);
std::sort(lens.begin(), lens.end());
vector<int> lens_copy = lens;
lens.clear();
int i = 0;
int j = lens_copy.size() - 1;
while (true) {
if (i <= j) {
lens.push_back(lens_copy[i]);
i++;
} else break;
if (i <= j) {
lens.push_back(lens_copy[j]);
j--;
} else break;
}
}
struct ptr {
int in;
int cnt;
};
auto advance = [&](ptr& ptr) {
if (ptr.cnt + 1 == lens[ptr.in]) {
ptr.cnt = 0;
ptr.in++;
} else ptr.cnt++;
};
int total = 0;
for (int sublen = 1; sublen <= n; sublen++) {
ptr first{0, 0};
ptr second{0, 0};
for (int _ = 0; _ < sublen - 1; _++) advance(second);
while (second.in < lens.size()) {
total += second.in - first.in + 1;
advance(first);
advance(second);
}
}
cout << total << "\n";
}
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |