// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define no1 cout<<"-1\n"
using namespace std;
const int N = 2e5+100;
const int M = 1e5+10;
const int INF = 1e18;
const int mod = 1e9+7;
// int binpow (int a, int n) {
// if (n == 0)
// return 1;
// if (n % 2 == 1)
// return (binpow (a, n-1) * a)%mod;
// else {
// int b = binpow (a, n/2);
// return (b * b)%mod;
// }
// }
int n,k,R;
int a[N];
map<int,int> mn;
map<int,int> mx;
map<int,int> m;
int d[N];
void solve(){
cin>>n>>k>>R;
for(int i = 1;i<=n;i++){
cin>>a[i];
if(!mn[a[i]]) mn[a[i]] = i;
mx[a[i]] = i;
m[a[i]]++;
}
int l = INF;
int r = 0;
while(R--){
int b,q;
cin>>b>>q;
d[b] = q;
if(m[b] < q){
cout<<"impossible\n";
return;
}
l = min(l,mn[b]);
r = max(r,mx[b]);
}
m.clear();
for(int i = l;i<=r;i++){
m[a[i]]++;
}
while(1){
if(l==r){
break;
}
bool ok = 0;
if(m[a[l]]-1>=d[a[l]]){
ok = 1;
m[a[l]]--;
l++;
}
if(m[a[r]]-1>=d[a[r]]){
ok = 1;
m[a[r]]--;
r--;
}
if(!ok) break;
}
cout<<r-l+1<<'\n';
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
// cout.tie(nullptr);
int t = 1;
// cin>>t;
// cout<<"";
for(int i = 1;i<=t;i++){
// cout<<"Case "<<i<<": ";
solve();
// cout<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
3420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
314 ms |
18424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |