#include using namespace std; const int nax = 123 * 1000; const int pot = 128 * 1024; int n, q, k; int t[nax]; int indices[115][2*pot]; #define next next_compile #define prev prev_compile int next(int val, int i) { // returns 'i' if t[i]=val int * tr = indices[val]; if(tr[i+pot]) return i; i += pot; while(i > 1 && (i % 2 == 1 || !tr[i+1])) i /= 2; if(i == 1) return n + 1; ++i; while(i < pot) { if(tr[2*i]) i = 2 * i; else i = 2 * i + 1; } return i - pot; } int prev(int val, int i) { // returns 'i' if t[i]=val int * tr = indices[val]; if(tr[i+pot]) return i; i += pot; while(i > 1 && (i % 2 == 0 || !tr[i-1])) i /= 2; if(i == 1) return 0; --i; while(i < pot) { if(tr[2*i+1]) i = 2 * i + 1; else i = 2 * i; } return i - pot; } void add(int val, int i, int diff) { int * tr = indices[val]; for(int x = pot + i; x >= 1; x /= 2) tr[x] += diff; } int best[2*pot]; void best_add(int i, int diff) { for(int x = pot + i; x >= 1; x /= 2) best[x] += diff; } int tr_ans[2*pot]; int list_ans[nax]; void clear_ans(int a, int b) { int * tr = tr_ans; while(true) { int i = pot + a; if(!tr[i]) { while(i > 1 && (i % 2 == 1 || !tr[i+1])) i /= 2; if(i == 1) return; ++i; while(i < pot) { if(tr[2*i]) i = 2 * i; else i = 2 * i + 1; } } assert(tr[i]); i -= pot; assert(list_ans[i]); if(i > b) return; if(list_ans[i] != n + 1) best_add(list_ans[i] - i + 1, -1); list_ans[i] = 0; for(int x = pot + i; x >= 1; x /= 2) tr[x]--; } } void update(int where) { vector w; for(int j = 1; j <= k; ++j) { int i = prev(j, where - 1); w.push_back(i); } w.push_back(where); sort(w.begin(), w.end()); clear_ans(w[0], where); int big = 0; for(int j = 1; j <= k; ++j) big = max(big, next(j, w[0])); for(int i : w) if(i) { assert(list_ans[i] == 0); list_ans[i] = big; for(int x = pot + i; x >= 1; x /= 2) tr_ans[x]++; if(big != n + 1) best_add(big - i + 1, 1); big = max(big, next(t[i], i + 1)); } } int main() { scanf("%d%d%d", &n, &k, &q); for(int i = 1; i <= n; ++i) { scanf("%d", &t[i]); add(t[i], i, 1); update(i); } while(q--) { int i, val; scanf("%d%d", &i, &val); add(t[i], i, -1); t[i] = val; add(t[i], i, 1); update(i); if(best[1] == 0) puts("-1"); else { i = 1; while(i < pot) { if(best[2*i]) i = 2 * i; else i = 2 * i + 1; } printf("%d\n", i - pot); } } }