#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
ll ttt;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const int N = 1000007;
ll n, m, k;
ll a[N];
ll cc[N];
set<int>cur;
ll cnt[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for(int i=0;i<k;i++){
int x,y;
cin>>x>>y;
cc[x]=y;
cur.insert(x);
}
int l=0,r=0;
int ans=MOD;
while(l<n&&r<=n){
if(!cur.empty()){
if(r==n)break;
cnt[a[r]]++;
if(cnt[a[r]]==cc[a[r]]){
cur.erase(a[r]);
}
r++;
}
else{
ans=min(ans,r-l);
cnt[a[l]]--;
if(cnt[a[l]]==cc[a[l]]-1){
cur.insert(a[l]);
}
l++;
}
// for(auto x:cur)cout<<x<<" ";
// cout<<endl;
}
if(ans!=MOD)cout<<ans<<endl;
else cout<<"impossible"<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
2260 KB |
Output is correct |
2 |
Correct |
15 ms |
2260 KB |
Output is correct |
3 |
Correct |
17 ms |
2352 KB |
Output is correct |
4 |
Correct |
15 ms |
2292 KB |
Output is correct |
5 |
Correct |
17 ms |
3788 KB |
Output is correct |
6 |
Correct |
11 ms |
2276 KB |
Output is correct |
7 |
Correct |
12 ms |
2384 KB |
Output is correct |
8 |
Correct |
21 ms |
4692 KB |
Output is correct |
9 |
Correct |
16 ms |
2912 KB |
Output is correct |
10 |
Correct |
11 ms |
2260 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
352 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
8772 KB |
Output is correct |
2 |
Correct |
54 ms |
7244 KB |
Output is correct |
3 |
Correct |
28 ms |
5064 KB |
Output is correct |
4 |
Correct |
16 ms |
2260 KB |
Output is correct |
5 |
Correct |
56 ms |
9328 KB |
Output is correct |
6 |
Correct |
85 ms |
11536 KB |
Output is correct |
7 |
Correct |
19 ms |
3312 KB |
Output is correct |
8 |
Correct |
25 ms |
4028 KB |
Output is correct |
9 |
Correct |
14 ms |
2220 KB |
Output is correct |
10 |
Correct |
14 ms |
2260 KB |
Output is correct |
11 |
Correct |
16 ms |
2348 KB |
Output is correct |
12 |
Correct |
14 ms |
2276 KB |
Output is correct |
13 |
Correct |
24 ms |
3660 KB |
Output is correct |
14 |
Correct |
11 ms |
2292 KB |
Output is correct |
15 |
Correct |
12 ms |
2420 KB |
Output is correct |
16 |
Correct |
19 ms |
4732 KB |
Output is correct |
17 |
Correct |
15 ms |
2860 KB |
Output is correct |
18 |
Correct |
12 ms |
2260 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |