$Luogu$ $P4792$ $[BalticOI 2018]$ 火星人的 $DNA$

链接

背景

\(Baltic\) \(Olympiad\) \(in\) \(Informatics\) \(2018\) \(Day1\) \(T2\)\(Luogu\) \(P3524/LOJ2775\) (原题面暂时无法打开)

题意

未完待续

解法

细节

代码

$View$ $Code$ ```cpp #include using namespace std; inline int read() { int ret=0,f=1; char ch=getchar(); while(ch>'9'||ch<'0') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { ret=(ret<<1)+(ret<<3)+ch-'0'; ch=getchar(); } return ret*f; } int n,k,q,x,y,l=1,r,s[200005],cnt[200005],ans=1e9+7; inline void add(int x) { cnt[x]--; if(!cnt[x]) q--; } inline void del(int x) { cnt[x]++; if(cnt[x]==1) q++; } int main() { n=read(); k=read(); q=read(); for(register int i=1;i<=n;i++) s[i]=read(); for(register int i=1;i<=q;i++) { x=read(); y=read(); cnt[x]=y; } while(1) { while(r<=n&&q) add(s[++r]); if(r>n) break; ans=min(ans,r-l+1); del(s[l++]); } if(ans<1e9+7) printf("%d\n",ans); else printf("impossible\n"); return 0; } ```

猜你喜欢

转载自www.cnblogs.com/Peter0701/p/11348939.html