# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
999084 | 2024-06-15T06:23:09 Z | IdanRosen | Diversity (CEOI21_diversity) | C++ | 0 ms | 348 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Incorrect | 0 ms | 348 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Incorrect | 0 ms | 348 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Incorrect | 0 ms | 348 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |