Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- int n, k, m;
- cin >> n >> k >> m;
- int a[n];
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- }
- for(int i = 0; i < m; i++) {
- int tip;
- cin >> tip;
- if(tip == 1) {
- int p, v;
- cin >> p >> v;
- a[p - 1] = v;
- }
- else {
- vector<int> brojac(k + 1, 0);
- int x = 0;
- int br_tipovi = 0;
- int najmala_podniza = 2e9;
- for(int j = 0; j < n; j++) {
- if(brojac[a[j]] == 0) {
- br_tipovi++;
- }
- brojac[a[j]]++;
- if(br_tipovi == k) {
- while(brojac[a[x]] > 1) {
- brojac[a[x]]--;
- x++;
- }
- if(najmala_podniza > j - x + 1) {
- najmala_podniza = j - x + 1;
- }
- }
- }
- if(najmala_podniza == 2e9) najmala_podniza = -1;
- cout << najmala_podniza << endl;
- }
- }
- return 0;
- }
- /*
- brojac[k]
- brojac[1] = brojac[2] = brojac[3] = .. = 0
- 1 2 |3 2 1| 1
- 3
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement