#include <bits/stdc++.h>
using namespace std;
inline string sread(){
string ans="";
char ch=getchar();
while(ch!=' '&&ch!='\n'&&ch!='\t'){ans+=ch;ch=getchar();}
return ans;
}
template<class T>
struct Hash{
size_t operator()(const T& key)const{
return key.x+key.y;
}
};
struct node{
int x,y;
bool operator<(const node& A)const{
if(A.x!=x)return x<A.x;
return y<A.y;
}
bool operator==(const node& A)const{
return x==A.x&&y==A.y;
}
};
int n;
int c1[1000001],c2[1000001];
int l1[1000001],l2[1000001];
string s;
int ans1=0,ans2=0;
unordered_map<int,bool>mp;
unordered_map<node,node,Hash<node>>rm;
inline int calc(int l,int r){
if(rm[{l,r}].y)return rm[{l,r}].x;
if(l1[r]>=l){
int t=calc(l,l1[r]-1);
if(t==1){if(!mp[l1[r]]){ans1++;mp[l1[r]]=true;}rm[{l,r}]={1,1};return 1;}
int _=calc(l,l1[r]-1),__=calc(l1[r]+1,r);
rm[{l,l1[r]-1}]={_,1};rm[{l1[r]+1,r}]={__,1};
rm[{l,r}]={_|__,1};
return _|__;
}
if(l2[r]>=l){
int t=calc(l,l2[r]-1);
if(t==0){if(!mp[l2[r]]){ans2++;mp[l2[r]]=true;}rm[{l,r}]={0,1};return 0;}
int _=calc(l,l2[r]-1),__=calc(l2[r]+1,r);
rm[{l,l2[r]-1}]={_,1};rm[{l2[r]+1,r}]={__,1};
rm[{l,r}]={_&__,1};
return _&__;
}
if(s[l]=='('&&s[r]==')'){rm[{l+1,r-1}]={calc(l+1,r-1),1};return rm[{l+1,r-1}].x;}
int v=0;
for(int i=l;i<=r;i++)v=v*10+s[i]-'0';
rm[{l,r}]={v,1};
return v;
}
int main(){
int x=0;
s=sread();
s=' '+s;
n=(int)s.size();
n--;
for(int i=1;i<=n;i++){
if(s[i]=='(')x++;
if(s[i]==')')x--;
if(s[i]=='|')c1[x]=i;
if(s[i]=='&')c2[x]=i;
l1[i]=c1[x];l2[i]=c2[x];
}
// for(int i=1;i<=n;i++)cout<<i<<':'<<l1[i]<<','<<l2[i]<<endl;
printf("%d\n%d %d\n",calc(1,n),ans2,ans1);
return 0;
}
Input:
0&1
Xcode:
0
1 0
luogu:
0
0 0