题解:P3570 [POI 2014] PRZ-Criminals
ACehomoxue · · 题解
简单题。
我们设
:::success[code]
#include <bits/stdc++.h>
using namespace std;
#define int int
#define ll long long
#define usd unsigned
#define el putchar('\n')
#define lowbit(x) (x & (-x))
#define AC return
#define AK return 0
#define YS cout << "YES"
#define NO cout << "NO"
#define Ys cout << "Yes"
#define No cout << "No"
#define ys cout << "yes"
#define no cout << "no"
#define ls(i) ch[i][0]
#define rs(i) ch[i][1]
#define debug(num) cerr << #num << ' ' << num << '\n'
#define void inline void
#define il inline
#define Mod(x) (((x) % mod + mod) % mod)
#define pii pair <int, int>
#define pll pair <ll, ll>
il char gc() { char c; while((c = getchar()) <= ' ') ; return c; }
il int rd() {
char c; int x, f = 1;
while(!isdigit(c = getchar())) if(c == '-') f *= -1;
x = c ^ 48;
while(isdigit(c = getchar())) x = (x << 3) + (x << 1) + (c ^ 48);
return x * f;
}
void ACehomoxue();
signed main() {
srand(time(0));
int t = 1;
// t = rd();
while(t--) ACehomoxue();
AK;
}
const int mod = 998244353, maxn = 1e6 + 6;
int n, k, c[maxn], m1, m2, s, pre[maxn], mx[maxn], suf[maxn], lst[maxn], frm[maxn], lf[maxn], rh[maxn];
vector <int> ans;
void ACehomoxue() {
n = rd(), k = rd();
for(int i = 1; i <= n; i++) c[i] = rd();
m1 = rd(), m2 = rd();
for(int i = 1; i <= k; i++) frm[i] = -1;
for(int i = 1, pr = 0, x; i <= m1; i++) {
x = rd();
frm[x] = pr;
pr = x;
if(i == m1) s = x;
}
for(int i = 1; i <= n; i++) {
if(frm[c[i]] == -1) continue;
if(frm[c[i]] == 0) pre[i] = i;
else pre[i] = pre[lst[frm[c[i]]]];
lst[c[i]] = i;
}
suf[n + 1] = n + 1;
for(int i = 1; i <= k; i++) frm[i] = -1, lst[i] = n + 1;
for(int i = 1, pr = 0, x; i <= m2; i++) {
x = rd();
frm[x] = pr;
pr = x;
}
for(int i = n; i; i--) {
if(frm[c[i]] == -1) continue;
if(frm[c[i]] == 0) suf[i] = i;
else suf[i] = suf[lst[frm[c[i]]]];
lst[c[i]] = i;
}
for(int i = 1; i <= n; i++) if(!lf[c[i]]) lf[c[i]] = i;
for(int i = n; i; i--) if(!rh[c[i]]) rh[c[i]] = i;
for(int i = 1; i <= k; i++) mx[lf[i]] = max(mx[lf[i]], rh[i]);
for(int i = 1; i <= n; i++) mx[i] = max(mx[i], mx[i - 1]);
for(int i = 1; i <= n; i++) {
if(c[i] == s) {
int l = pre[i], r = suf[i];
if(l && r <= n && mx[l - 1] > r) ans.push_back(i);
}
}
cout << ans.size(), el;
for(int i : ans) cout << i << ' ';
el;
}
:::