#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstring>
#include <set>
#warning That's the baby, that's not my baby
typedef long long ll;
const int NMAX = 3e5;
int a[NMAX + 1];
int f[15];
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int n, q;
std::cin >> n >> q;
std::vector<int> norm;
for (int i = 1; i <= n; i++) {
std::cin >> a[i];
norm.push_back(a[i]);
}
std::sort(norm.begin(), norm.end());
norm.erase(std::unique(norm.begin(), norm.end()));
for (int i = 1; i <= n; i++) {
a[i] = std::lower_bound(norm.begin(), norm.end(), a[i]) - norm.begin();
}
while (q--) {
int l, r;
std::cin >> l >> r;
std::vector<int> b;
for (int i = l; i <= r; i++) {
b.push_back(a[i]);
}
std::sort(b.begin(), b.end());
int m = (int) b.size();
int answer = 1e9;
do {
int cur = 0;
for (int i = 0; i < m; i++) {
int cnt = 0;
memset(f, 0, sizeof(f));
for (int j = i; j < m; j++) {
if (!f[b[j]]) {
cnt++;
f[b[j]] = 1;
}
cur += cnt;
}
}
answer = std::min(answer, cur);
} while (std::next_permutation(b.begin(), b.end()));
std::cout << answer << '\n';
}
return 0;
}
Compilation message
diversity.cpp:7:2: warning: #warning That's the baby, that's not my baby [-Wcpp]
7 | #warning That's the baby, that's not my baby
| ^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
9 ms |
344 KB |
Output is correct |
5 |
Correct |
57 ms |
344 KB |
Output is correct |
6 |
Correct |
233 ms |
348 KB |
Output is correct |
7 |
Correct |
601 ms |
440 KB |
Output is correct |
8 |
Correct |
944 ms |
440 KB |
Output is correct |
9 |
Correct |
1517 ms |
440 KB |
Output is correct |
10 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
7020 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
7020 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
7020 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
9 ms |
344 KB |
Output is correct |
5 |
Correct |
57 ms |
344 KB |
Output is correct |
6 |
Correct |
233 ms |
348 KB |
Output is correct |
7 |
Correct |
601 ms |
440 KB |
Output is correct |
8 |
Correct |
944 ms |
440 KB |
Output is correct |
9 |
Correct |
1517 ms |
440 KB |
Output is correct |
10 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
9 ms |
344 KB |
Output is correct |
5 |
Correct |
57 ms |
344 KB |
Output is correct |
6 |
Correct |
233 ms |
348 KB |
Output is correct |
7 |
Correct |
601 ms |
440 KB |
Output is correct |
8 |
Correct |
944 ms |
440 KB |
Output is correct |
9 |
Correct |
1517 ms |
440 KB |
Output is correct |
10 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |