#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];
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;
}
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]]) cur++;
l++;
}
else {
cnt[arr[r]]++;
if(cnt[arr[r]] == e[arr[r]]) cur--;
r++;
}
}
(ans == INF ? cout << "impossible" << endl : cout << ans << endl);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2516 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2536 KB |
Output is correct |
2 |
Correct |
8 ms |
2396 KB |
Output is correct |
3 |
Correct |
8 ms |
2396 KB |
Output is correct |
4 |
Correct |
7 ms |
2568 KB |
Output is correct |
5 |
Correct |
10 ms |
2652 KB |
Output is correct |
6 |
Incorrect |
6 ms |
2648 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
2652 KB |
Output is correct |
2 |
Correct |
16 ms |
2652 KB |
Output is correct |
3 |
Correct |
12 ms |
2636 KB |
Output is correct |
4 |
Correct |
6 ms |
2392 KB |
Output is correct |
5 |
Correct |
16 ms |
2620 KB |
Output is correct |
6 |
Correct |
17 ms |
2652 KB |
Output is correct |
7 |
Correct |
10 ms |
2652 KB |
Output is correct |
8 |
Correct |
11 ms |
2652 KB |
Output is correct |
9 |
Correct |
6 ms |
2516 KB |
Output is correct |
10 |
Correct |
8 ms |
2396 KB |
Output is correct |
11 |
Correct |
10 ms |
2396 KB |
Output is correct |
12 |
Correct |
10 ms |
2396 KB |
Output is correct |
13 |
Correct |
10 ms |
2652 KB |
Output is correct |
14 |
Incorrect |
7 ms |
2516 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |