Josif_tepe

Untitled

Feb 9th, 2026
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. using namespace std;
  4. typedef long long ll;
  5. const int INF = 2e9;
  6. const int maxn = 1e5 + 10;
  7. int n, k, m;
  8.  
  9. int solve(vector<int> & v) {
  10.     vector<int> cnt(51, 0);
  11.    
  12.     int j = 0, c = 0;
  13.    
  14.     int res = INF;
  15.     for(int i = 0; i < n; i++) {
  16.         if(cnt[v[i]] == 0) {
  17.             c++;
  18.         }
  19.        
  20.         cnt[v[i]]++;
  21.         if(c == k) {
  22.             while(cnt[v[j]] > 1) {
  23.                 cnt[v[j]]--;
  24.                 j++;
  25.             }
  26.             res = min(res, i - j + 1);
  27.         }
  28.     }
  29.     if(res == INF) res = -1;
  30.    
  31.     return res;
  32. }
  33. int main() {
  34.     ios_base::sync_with_stdio(false);
  35.     cin >> n >> k >> m;
  36.    
  37.     vector<int> v(n);
  38.     for(int i = 0; i < n; i++) {
  39.         cin >> v[i];
  40.     }
  41.    
  42.     for(int i = 0; i < m; i++) {
  43.         int tip;
  44.         cin >> tip;
  45.        
  46.         if(tip == 1) {
  47.             int x, y;
  48.             cin >> x >> y;
  49.            
  50.             v[x - 1] = y;
  51.         }
  52.         else {
  53.             cout << solve(v) << "\n";
  54.         }
  55.     }
  56.     return 0;
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment