이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
| # | 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... |