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;
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 2e5;
int n, k, q;
vector<int> a;
vector<pair<int, int> > query;
int nuk[N+10], need[N + 10];
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k >> q;
a.resize(n);
for(int i = 0;i < n; i++){
cin >> a[i];
nuk[a[i]]++;
}
for(int i = 0;i < q; i++){
int c, cnt; cin >> c >> cnt;
query.push_back({c, cnt});
need[c] = cnt;
}
for(auto [c, cnt] : query){
if(nuk[c] < cnt){
cout << "impossible";
return 0;
}
}
for(int i = 0;i < n; i++) nuk[a[i]] = 0;
int ans = n, ok = 0;
for(int l = 0, r = 0; l < n; l++){
while(r < n && ok < q){
nuk[a[r]]++;
if(nuk[a[r]] == need[a[r]]){
ok++;
}
r++;
}
if(ok > q) assert(false);
if(ok == q){
ans = min(ans, r - l);
}
if(nuk[a[l]] == need[a[l]]){
ok--;
}
nuk[a[l]]--;
}
cout << ans;
return 0;
}
Compilation message (stderr)
dna.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
16 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |