#include <bits/stdc++.h>
using namespace std;
int main() {
//ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n,q; cin >> n >> q;
vector<int> vv(n); for (int i = 0; i<n; ++i) cin >> vv[i];
while (q--) {
long long fin = 4e18;
int L, R;
cin >> L >> R;
--L; --R;
vector<int> v(R-L+1); for (int i = 0; i<R-L+1; ++i) v[i] = vv[i+L];
do {
//int l,r; cin >> l >> r; --l;
long long ans = 0;
for (int i = 0; i < n; ++i) {
set<int> s;
for (int j = i; j < n; ++j) {
s.insert(v[j]);
ans += s.size();
}
}
fin = min(fin, ans);
} while (std::next_permutation(v.begin(), v.end()));
cout << fin;
}
return 0;
}
/*
*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
13 ms |
348 KB |
Output is correct |
5 |
Correct |
280 ms |
412 KB |
Output is correct |
6 |
Correct |
1969 ms |
412 KB |
Output is correct |
7 |
Correct |
142 ms |
408 KB |
Output is correct |
8 |
Execution timed out |
7044 ms |
344 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
7034 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
7034 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
7034 ms |
348 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 |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
13 ms |
348 KB |
Output is correct |
5 |
Correct |
280 ms |
412 KB |
Output is correct |
6 |
Correct |
1969 ms |
412 KB |
Output is correct |
7 |
Correct |
142 ms |
408 KB |
Output is correct |
8 |
Execution timed out |
7044 ms |
344 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
13 ms |
348 KB |
Output is correct |
5 |
Correct |
280 ms |
412 KB |
Output is correct |
6 |
Correct |
1969 ms |
412 KB |
Output is correct |
7 |
Correct |
142 ms |
408 KB |
Output is correct |
8 |
Execution timed out |
7044 ms |
344 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |