#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const int MAXN = 5010;
const int MAXK = 50;
int k;
vector<int> pref[50];
bool check(int l, int r) {
bool c = true;
for(int i = 0;i<k;i++) {
if(!(pref[i][r+1] - pref[i][l]))c = false;
}
return c;
}
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> k >> m;
for(int i = 0;i<50;i++) {
pref[i].resize(MAXN);
}
int arr[n];
for(int i = 0;i<n;i++){
cin >> arr[i];
arr[i]--;
}
for(int i = 0;i<50;i++) {
pref[i][0] = 0;
for(int j = 1;j<=n;j++) {
if(arr[j-1] == i) {
pref[i][j] = pref[i][j-1]+1;
}
else pref[i][j] = pref[i][j-1];
}
}
while(m--) {
int type;
cin >> type;
if(type == 1) {
int p, v;
cin >> p >> v;
v--;p--;
arr[p] = v;
for(int i = 0;i<50;i++) {
pref[i][0] = 0;
for(int j = 1;j<=n;j++) {
if(arr[j-1] == i) {
pref[i][j] = pref[i][j-1]+1;
}
else pref[i][j] = pref[i][j-1];
}
}
}
else {
int p1 = 0, p2 = 0;
int ans = 1e9;
while(p2 < n) {
if(check(p1, p2)) {
ans = min(ans, (int)p2-p1+1);
p1++;
}
else {
p2++;
}
}
if(ans == 1e9)ans = -1;
cout << ans << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
897 ms |
1356 KB |
Output is correct |
2 |
Correct |
1107 ms |
1292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1652 ms |
1296 KB |
Output is correct |
2 |
Correct |
1855 ms |
1296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2811 ms |
1300 KB |
Output is correct |
2 |
Execution timed out |
3032 ms |
1300 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3033 ms |
1412 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
3028 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
2872 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
3156 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
3104 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
22 ms |
3344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
17 ms |
3348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |