BZOJ 十连测 二进制的世界
SOL:
我们可以分块啊·。
#include<bits/stdc++.h> using namespace std; #define sight(c) ('0'<=c&&c<='9') char ch[10]; int f[277][277],g[277][277],v[277],k,ans,cnt,n,op,x; inline void read(int &x){ static char c; for (c=getchar();!sight(c);c=getchar()); for (x=0;sight(c);c=getchar())x=x*10+c-48; } void write(int x){if (x<10) {putchar('0'+x); return;} write(x/10); putchar('0'+x%10);} inline void writeln(int x){ if (x<0) putchar('-'),x*=-1; write(x); putchar('\n'); } inline void writel(int x){ if (x<0) putchar('-'),x*=-1; write(x); putchar(' '); } inline int fun(int x,int y) { if (ch[0]=='a') return x&y; if (ch[0]=='o') return x|y; return x^y; } void add(int x){ int A=x>>8,B=x&255; v[A]=1; for (int i=0;i<256;i++) { k=fun(i,B); if (k>f[A][i]) f[A][i]=k,g[A][i]=1; else if (k==f[A][i]) g[A][i]++; } } void ask(int x) { int A=x>>8,B=x&255; ans=cnt=0; for (int i=0;i<256;i++) if (v[i]){ k=fun(i,A)<<8|f[i][B]; if (k>ans) ans=k,cnt=g[i][B]; else if (k==ans) cnt+=g[i][B]; } } signed main () { freopen("binary.in","r",stdin); freopen("binary.out","w",stdout); scanf("%d%s%d",&n,ch,&op); for (int i=1;i<=n;i++) { read(x); if (i!=1) { ask(x); if (op) writel(ans),writeln(cnt); else writeln(ans); } add(x); } }