NOI十连测 第五测 T1

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cmath>
 4 #include<iostream>
 5 #include<algorithm>
 6 int f[257][257],n,type,V[257],g[257][257],ans,cnt;
 7 char op[204];
 8 int read(){
 9     int t=0,f=1;char ch=getchar();
10     while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
11     while ('0'<=ch&&ch<='9'){t=t*10+ch-'0';ch=getchar();}
12     return t*f;
13 }
14 int fun(int x,int y){
15     if (op[0]=='a') return x&y;
16     else
17     if (op[0]=='o') return x|y;
18     return x^y;
19 }
20 void add(int x){
21     int A=x>>8,B=x&255;
22     V[A]=1;
23     for (int i=0;i<256;i++){
24         int k=fun(i,B);
25         if (k>f[A][i]) f[A][i]=k,g[A][i]=1;
26         else if (k==f[A][i]) g[A][i]++;
27     }
28 }
29 void ask(int x){
30     int A=x>>8,B=x&255;
31     ans=cnt=0;
32     for (int i=0;i<256;i++)if (V[i]){
33         int k=fun(i,A)<<8|f[i][B];
34         if (k>ans) ans=k,cnt=g[i][B];else
35         if (k==ans) cnt+=g[i][B];
36     }
37 }
38 int main(){
39     n=read();scanf("%s",op);type=read();
40     for (int i=1;i<=n;i++){
41         int x;
42         scanf("%d",&x);
43         if (i!=1){
44             ask(x);
45             if (type) printf("%d %d\n",ans,cnt);
46             else printf("%d\n",ans);
47         }
48         add(x);
49     }
50     return 0;
51 }

 

posted @ 2016-06-21 21:40  GFY  阅读(252)  评论(0编辑  收藏  举报