嗯,有可能。
review 了一下今年这个CSP-J组满分小学生的代码(信息学比赛这点好,完全透明公开)
确实如果真的是小学生的话,有点太逆天了。
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e6+10;
const int maxlen=1e6+10;
const int inf=1e8;
int n, len, q, tot, root;
char str[maxlen];
int a[maxn];
struct Node {
int ls,rs,fa,op,old;
int val[2];
} tr[maxn];
stack<int> s;
inline int read(){
int x=0,f=1,ch=getchar();
while (ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-'0');ch=getchar();}
return f==1?x:-x;
}
inline bool gettoken(int &pos,int &val){
while (pos<len&&!(str[pos]=='&'||str[pos]=='|'||str[pos]=='!'||str[pos]=='x'))pos++;
if (pos>=len) return false;
//printf("pos %d ch %c\n", pos, str[pos]);
if (str[pos]=='&') val=-1;
else if (str[pos]=='|') val=-2;
else if (str[pos]=='!') val=-3;
else {
val=0; pos++;
while (pos<len && str[pos]>='0' && str[pos]<='9')val=val*10+str[pos]-'0',pos++;
pos--;
}
pos++;
return true;
}
inline void print(const Node &x){
printf("fa:%d l:%d r:%d op:%d old:%d v0:%d v1:%d\n", x.fa, x.ls, x.rs, x.op, x.old, x.val[0], x.val[1]);
}
inline void dfs(int x){
if (x<=n) {tr[x].old=a[x]; return;}
if (tr[x].op==-1) {dfs(tr[x].ls); dfs(tr[x].rs); tr[x].old=tr[tr[x].ls].old & tr[tr[x].rs].old;}
if (tr[x].op==-2) {dfs(tr[x].ls); dfs(tr[x].rs); tr[x].old=tr[tr[x].ls].old | tr[tr[x].rs].old;}
if (tr[x].op==-3) {dfs(tr[x].ls); tr[x].old=!tr[tr[x].ls].old;}
}
inline void solve(int x,int new_val){
int cur=x, curval=new_val, ans;
while (tr[cur].val[curval]==-1) {
int pa=tr[cur].fa, nxtval;
if (tr[pa].ls==cur) {
if (tr[pa].op==-1) nxtval=tr[tr[pa].rs].old & curval;
else if (tr[pa].op==-2) nxtval=tr[tr[pa].rs].old | curval;
else nxtval= ! curval;
} else {
if (tr[pa].op==-1) nxtval=tr[tr[pa].ls].old & curval;
else nxtval=tr[tr[pa].ls].old | curval;
}
curval=nxtval; cur=pa;
}
ans=tr[cur].val[curval];
cur=x; curval=new_val;
while (tr[cur].val[curval]==-1) {
tr[cur].val[curval]=ans;
int pa=tr[cur].fa, nxtval;
if (tr[pa].ls==cur) {
if (tr[pa].op==-1) nxtval=tr[tr[pa].rs].old & curval;
else if (tr[pa].op==-2) nxtval=tr[tr[pa].rs].old | curval;
else nxtval= ! curval;
} else {
if (tr[pa].op==-1) nxtval=tr[tr[pa].ls].old & curval;
else nxtval=tr[tr[pa].ls].old | curval;
}
curval=nxtval; cur=pa;
}
printf("%d\n", ans);
}
int main() {
freopen("expr.in", "r", stdin);
freopen("expr.out", "w", stdout);
fgets(str,1000005,stdin);
//scanf("%s", str);
len=strlen(str);
//printf("%s\n",str);
//printf("len:%d\n", len);
n=read();
for (int i=1; i<=n; i++) a[i]=read();
//for (int i=1; i<=n; i++) printf("%d ", a[i]); printf("\n");
int pos=0, val;
tot=n;
while (gettoken(pos, val)) {
int x,y;
//printf("pos:%d val:%d\n", pos, val);
if (val>0) s.push(val);
else if (val==-1 || val==-2) {
x=s.top(); s.pop(); y=s.top(); s.pop();
tot++; tr[tot].ls=x; tr[tot].rs=y; tr[tot].op=val;
tr[x].fa=tr[y].fa=tot;
s.push(tot);
} else {
x=s.top(); s.pop();
tot++; tr[tot].ls=x; tr[tot].op=val;
tr[x].fa=tot;
s.push(tot);
}
}
//printf("%d %d\n", n, tot);
for (int i=1; i<=tot; i++) {
tr[i].val[0]=tr[i].val[1]=-1;
if (i<=n) tr[i].op=i;
}
root=tot;
dfs(root);
for (int i=1; i<=tot; i++) tr[i].val[tr[i].old]=tr[root].old;
tr[root].val[0]=0; tr[root].val[1]=1;
//for (int i=1; i<=tot; i++) print(tr[i]);
q=read();
while(q--){
int x=read();
solve(x,a[x]^1);
}
return 0;
}
【 在 littlebt 的大作中提到: 】
: 机构老师呀,提高组一等奖里面的小学生,有的早就在初中集训了(挂着小学学籍而已),有的是机构老师或其它个人报名的,真正的小学生只有1-2个。
--
FROM 120.244.220.*