QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#307501 | #7736. Red Black Tree | Register# | Compile Error | / | / | C++20 | 1.6kb | 2024-01-18 18:54:53 | 2024-01-18 18:54:53 |
Due to the privacy settings of the submitter, you are not allowed to view this code.
详细
answer.code: In function ‘int main()’: answer.code:2:1449: error: no match for ‘operator>>’ (operand types are ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} and ‘char*’) 2 | using namespace std;struct edge{int v,nxt;}e[200005];int h[100005],cnt,a[100005],T,x,ans[100005],n;char s[100005];struct node{int val0,cnt0,sum1;vector<int>v1,v2;int size(){return cnt0+v1.size()+v2.size();}}f[100005];void add(int u,int v){e[++cnt]={v,h[u]};h[u]=cnt;}node operator+(node x,node y){node res;res.val0=res.cnt0=res.sum1=0;res.val0=x.val0+y.val0;int siz=min(x.size(),y.size());int tot=0;vector<int>now;now.resize(siz);for(int i=0;i<x.v1.size();i++){if(tot>=siz)break;now[tot++]+=x.v1[i];}tot+=x.cnt0;reverse(x.v2.begin(),x.v2.end());for(int i=0;i<x.v2.size();i++){if(tot>=siz)break;now[tot++]+=x.v2[i];}tot=0;for(int i=0;i<y.v1.size();i++){if(tot>=siz)break;now[tot++]+=y.v1[i];}tot+=y.cnt0;reverse(y.v2.begin(),y.v2.end());for(int i=0;i<y.v2.size();i++){if(tot>=siz)break;now[tot++]+=y.v2[i];}for(int i=0;i<siz;i++){if(now[i]<0)res.v1.emplace_back(now[i]),res.sum1+=now[i];else if(now[i]==0)res.cnt0++;else res.v2.emplace_back(now[i]);}reverse(res.v2.begin(),res.v2.end());return res;}void dfs(int u,int fa){int son=0;f[u].val0=f[u].cnt0=f[u].sum1=0;f[u].v1.clear();f[u].v2.clear();f[u].v1.shrink_to_fit();f[u].v2.shrink_to_fit();for(int i=h[u];i;i=e[i].nxt){int v=e[i].v;if(v==fa)continue;dfs(v,u);if(!son)son=1,swap(f[u],f[v]);else f[u]=f[u]+f[v];}if(a[u]==1){f[u].val0++;f[u].sum1--;f[u].v1.emplace_back(-1);}else f[u].v2.emplace_back(1);ans[u]=f[u].val0+f[u].sum1;}int main(){cin.tie(0)->sync_with_stdio(0);cin>>T;while(T--){cin>>n>>(s+1);for(int i=1;i<=n;i++)a[i]=(s[i]-'0'),h[i]=0;cnt=0;for(int i=2;i<=n;i++)cin>>x,add(x,i);dfs(1,0);for(int i=1;i<=n;i++)cout<<ans[i]<<' ';cout<<'\n';}return 0;} | ~~~~~~^~~~~~~ | | | | ...