# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
555544 | fuad27 | Aliens (IOI16_aliens) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
const int MAXK = 50;
long long k;
vector<long long> 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 () {
long long n, m;
cin >> n >> k >> m;
for(int i = 0;i<50;i++) {
pref[i].resize(MAXN);
}
long long 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;
long long ans = 1e9;
while(p2 < n) {
if(check(p1, p2)) {
ans = min(ans, (long long)p2-p1+1);
p1++;
}
else {
p2++;
}
}
if(ans == 1e9)ans = -1;
cout << ans << "\n";
}
}
}