#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;
const int MAXN = 3e5 + 123;
int a[MAXN];
signed main() {
int n, q;
cin >> n >> q;
for (int i = 0; i < n; ++i)
cin >> a[i];
vector<int> cpr(n);
for (int i = 0; i < n; ++i)
cpr[i] = a[i];
sort(cpr.begin(), cpr.end());
cpr.resize(unique(cpr.begin(), cpr.end()) - cpr.begin());
for (int i = 0; i < n; ++i)
a[i] = lower_bound(cpr.begin(), cpr.end(), a[i]) - cpr.begin();
for (int t = 0; t < q; ++t) {
int l, r;
cin >> l >> r;
--l;
int m = r - l;
ll ans = 1ll * n * n * n;
vector<int> permut(m);
for (int i = 0; i < m; ++i)
permut[i] = i;
vector<int> permut_ = permut;
do {
vector<int> arr(m);
for (int i = 0; i < m; ++i)
arr[i] = a[l + permut[i]];
ll curans = 0;
for (int i = 0; i < m; ++i) {
int msk = 0;
for (int j = i; j < m; ++j) {
msk |= (1 << arr[j]);
curans += __builtin_popcount(msk);
}
}
ans = min(ans, curans);
next_permutation(permut.begin(), permut.end());
} while (permut != permut_);
cout << ans << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
7013 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
7035 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
7035 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
7035 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
7013 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
7013 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |