# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1124836 | luvna | Martian DNA (BOI18_dna) | C++20 | 28 ms | 2544 KiB |
#include<bits/stdc++.h>
#define MASK(i) (1 << (i))
#define pub push_back
#define all(v) v.begin(), v.end()
#define compact(v) v.erase(unique(all(v)), end(v))
#define pii pair<int,int>
#define fi first
#define se second
#define endl "\n"
#define sz(v) (int)(v).size()
#define dbg(x) "[" #x " = " << (x) << "]"
using namespace std;
template<class T> bool minimize(T& a, T b){if(a > b) return a = b, true;return false;}
template<class T> bool maximize(T& a, T b){if(a < b) return a = b, true;return false;}
typedef long long ll;
typedef long double ld;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r){return uniform_int_distribution<ll>(l, r)(rng);}
const int N = 2e5 + 15;
const int INF = 1e9;
int n, k, q;
int a[N];
int freq[N];
int ask[N];
void solve(){
cin >> n >> k >> q;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= q; i++){
int u, quant; cin >> u >> quant;
ask[u] = quant;
}
int ans = INF, full = 0;
for(int i = 1, j = 1; i <= n; i++){
freq[a[i]]++;
if(ask[a[i]] && freq[a[i]] == ask[a[i]]) full++;
while(j < i){
if(ask[a[j]] && freq[a[j]] <= ask[a[j]]) break;
freq[a[j]]--;
j++;
}
if(full == q) minimize(ans, i - j + 1);
}
if(ans == INF) cout << "impossible" << endl;
else cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "task"
if(fopen(task".INP", "r")){
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t; t = 1; //cin >> t;
while(t--) solve();
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |