Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- using namespace std;
- typedef long long ll;
- const int INF = 2e9;
- const int maxn = 1e5 + 10;
- int n, k, m;
- int solve(vector<int> & v) {
- vector<int> cnt(51, 0);
- int j = 0, c = 0;
- int res = INF;
- for(int i = 0; i < n; i++) {
- if(cnt[v[i]] == 0) {
- c++;
- }
- cnt[v[i]]++;
- if(c == k) {
- while(cnt[v[j]] > 1) {
- cnt[v[j]]--;
- j++;
- }
- res = min(res, i - j + 1);
- }
- }
- if(res == INF) res = -1;
- return res;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin >> n >> k >> m;
- vector<int> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- }
- for(int i = 0; i < m; i++) {
- int tip;
- cin >> tip;
- if(tip == 1) {
- int x, y;
- cin >> x >> y;
- v[x - 1] = y;
- }
- else {
- cout << solve(v) << "\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment