이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
bool debug = false;
signed main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, k, r, temp; cin >> n >> k >> r;
vector<int> v(n);
for (int i = 0 ;i < n; ++i){
cin >> v[i];
}
vector<int> val(k, 1e9+7);
for (int i = 0;i < r; ++i){
cin >> temp;
cin >> val[temp];
}
int lo = 1, hi = n, mid = (lo + hi)/2;
while (temp!=r && mid != n){
if(debug) cout << mid << '\n';
temp = 0;
vector<int> cur(n, 0);
for (int i = 0; i < mid; ++i){
cur[v[i]]++;
if(cur[v[i]] == val[v[i]])temp++;
}
if(temp == r){
hi = mid;
mid = (lo + hi)/2;
continue;
}
for (int i = mid; i < n; ++i){
cur[v[i]]++;
cur[v[i-mid]]--;
if (v[i] != v[i-mid]){
if(cur[v[i]] == val[v[i]])temp++;
if (cur[v[i-mid]] == val[v[i-mid]]-1)temp--;
}
if(temp == r){
hi = mid;
mid = (lo + hi)/2;
continue;
}
}
lo = mid+1;
mid = (lo + hi)/2;
}
if (temp != r && mid == n)cout << "impossible";
else cout << mid;
}
# | 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... |