版本比较
题解:P4792 [BalticOI 2018] 火星人的 DNA
正文
增加 4 行删除 4 行
20 行未改动212223242525262728292930313232333435362 行未改动3940414243434445464720 行未改动i64 n, k, r, s[MAXN], all[MAXN], tot[MAXN], sum, vis[MAXN], R;
int main() noexcept{ read (n, k, R);
for (i32 i = 1; i <= n; i++) read (s[i]); for (i32 i = 1; i <= R; i++){ i64 x; read (x); read (all[x]); i64 x; read (x); read (all[x]); vis[x] = 1; }
i64 l = 1, ans = INF; for (i32 r = 1; r <= n; r++){ tot[s[r]]++; if (tot[s[r]] >= all[s[r]] && vis[s[r]])2 行未改动 tot[s[l++]]--; /*合并左端点,将不需要的删除*/ if (sum == R) ans = std::min (ans, r - l + 1); }
if (ans == INF) puts ("impossible"); else put (ans); return 0;}```