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 ll long long
#define fi first
#define se second
#define sst string
#define pb push_back
#define maxco 100000+5
#define lld long double
#define cha ios_base::sync_with_stdio(false);
#define ffl cout.flush();
#define phi acos(-1)
#define mr make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define pqin priority_queue<ll,vector<ll>,greater<>>
#define pqpair priority_queue<pair<ll,ll> ,vector<pair<ll,ll>>,greater<pair<ll,ll>>>
#define pqpair2 priority_queue<pair<pair<ll,ll>,pair<ll,ll>>,vector<pair<pi,pair<ll,ll>>>,greater<pair<pi,pair<ll,ll>>>>
#define INF 1000000009
#define MAXN 1000006
#define pii pair<ll,ll>
#define mod 998244353
ll a[MAXN];
ll n,k,r;
map<ll,ll> nd;
map<ll,ll> cnt;
int main(){
cin>>n>>k>>r;
REP(i,1,n){
cin>>a[i];
}
REP(i,1,r){
ll b,c;
cin>>b>>c;
nd[b]=c;
}
ll ans=1e18;
set<ll> st;
ll l=1;
for(ll i=1;i<=n;i++){
cnt[a[i]]++;
if(cnt[a[i]]==nd[a[i]] && nd[a[i]]>0){
st.insert(a[i]);
}
if(st.size()==r){
while(l<i && cnt[a[l]]>nd[a[l]]){
cnt[a[l]]--;
l++;
}
ans=min(ans,i-l+1);
}
}
if(ans==1e18)cout<<-1<<endl;
else cout<<ans<<endl;
}
Compilation message (stderr)
dna.cpp: In function 'int main()':
dna.cpp:46:21: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
46 | if(st.size()==r){
| ~~~~~~~~~^~~
# | 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... |