$ Luogu $ $ P4792 $ $ [BalticOI 2018] $ Martian $ DNA $

link

background

\ (Baltic \) \ (Olympiad \) \ (in \) \ (Informatics \) \ (2018 \) \ (Day1 \) \ (T2 \) , \ (Luogu \) \ (P3524 / LOJ2775 \) (formerly temporarily unable to face the question open)

The meaning of problems

To be continued

solution

detail

Code

$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; } ```

Guess you like

Origin www.cnblogs.com/Peter0701/p/11348939.html