#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5;
int n, v[nx], k, r, res[nx], b, q, ans=INT_MAX;
vector<int> d[nx];
struct segtree
{
int d[4*nx];
void update(int l, int r, int i, int ql, int qr, int vl)
{
if (qr<l||r<ql||r<l) return;
if (ql<=l&&r<=qr) return d[i]=min(d[i], vl), void();
int md=(l+r)/2;
update(l, md, 2*i, ql, qr, vl);
update(md+1, r, 2*i+1, ql, qr, vl);
}
void solve(int l, int r, int i)
{
if (d[i]==INT_MIN) return;
if (l==r) return ans=min(ans, l-d[i]+1), void();
d[2*i]=min(d[2*i], d[i]);
d[2*i+1]=min(d[2*i+1], d[i]);
int md=(l+r)/2;
solve(l, md, 2*i);
solve(md+1, r, 2*i+1);
}
} s;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>k>>r;
for (int i=1; i<=n; i++) cin>>v[i], d[v[i]].push_back(i);
for (int i=1; i<4*nx; i++) s.d[i]=INT_MAX;
for (int i=1; i<=r; i++)
{
cin>>b>>q;
d[b].push_back(n+1);
s.update(1, n, 1, 1, d[b][q-1]-1, INT_MIN);
for (int j=q; j<(int)d[b].size(); j++) s.update(1, n, 1, d[b][j-1], d[b][j]-1, d[b][j-q]);
//s.solve(1, n, 1);
}
s.solve(1, n , 1);
if (ans==INT_MAX) cout<<"impossible";
else cout<<ans;
}
/*
10 2 2
0 0 1 0 0 0 0 1 0 0
1 2
0 2
10 2 2
0 0 1 0 0 0 0 1 0 0
1 1
0 2
10 2 2
0 0 1 0 0 0 0 1 0 0
0 2
1 2
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
3 ms |
8796 KB |
Output is correct |
4 |
Correct |
3 ms |
8796 KB |
Output is correct |
5 |
Incorrect |
2 ms |
8796 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
3 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8796 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Incorrect |
4 ms |
8796 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
11356 KB |
Output is correct |
2 |
Correct |
23 ms |
10928 KB |
Output is correct |
3 |
Correct |
33 ms |
11028 KB |
Output is correct |
4 |
Correct |
26 ms |
11312 KB |
Output is correct |
5 |
Correct |
23 ms |
12884 KB |
Output is correct |
6 |
Correct |
11 ms |
11072 KB |
Output is correct |
7 |
Correct |
14 ms |
11100 KB |
Output is correct |
8 |
Correct |
31 ms |
16572 KB |
Output is correct |
9 |
Correct |
19 ms |
11612 KB |
Output is correct |
10 |
Correct |
27 ms |
11260 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
3 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
2 ms |
8936 KB |
Output is correct |
16 |
Correct |
3 ms |
8796 KB |
Output is correct |
17 |
Correct |
2 ms |
8796 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
3 ms |
8796 KB |
Output is correct |
20 |
Correct |
2 ms |
8796 KB |
Output is correct |
21 |
Incorrect |
2 ms |
8796 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
13140 KB |
Output is correct |
2 |
Correct |
74 ms |
12692 KB |
Output is correct |
3 |
Correct |
38 ms |
12636 KB |
Output is correct |
4 |
Correct |
29 ms |
10740 KB |
Output is correct |
5 |
Runtime error |
39 ms |
27104 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |