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>
#include <fstream>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define mod 1000000007
#define INF 1000000000
#define INF2 2000000000
#define fi first
#define se second
using namespace std;
double const EPS = 1e-14;
const int P = 100780807;
typedef long long ll;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
const int N = 2e5 + 5;
int arr[N], e[N], cnt[N];
bool ok[N];
int main()
{
ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
int n, k, m; cin >> n >> k >> m;
for(int i = 0; i < n; i++) cin >> arr[i];
int cur = m;
for(int i = 0; i < m; i++) {
int a, b; cin >> a >> b;
e[a] = b;
ok[a] = 1;
}
int l = 0, r = 0;
int ans = INF;
while(r <= n) {
if(cur == 0) {
ans = min(ans,(r-l));
cnt[arr[l]]--;
if(cnt[arr[l]]+1 == e[arr[l]] && ok[arr[l]] == 1) cur++;
l++;
}
else {
if(r >= n) break;
cnt[arr[r]]++;
if(cnt[arr[r]] == e[arr[r]] && ok[arr[r]] == 1) cur--;
r++;
}
}
(ans == INF ? cout << "impossible" << endl : cout << ans << endl);
return 0;
}
# | 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... |