QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#187649#7509. 01treeCrysflyCompile Error//C++205.3kb2023-09-24 19:42:592023-09-24 19:43:00

Judging History

你现在查看的是最新测评结果

  • [2023-09-24 19:43:00]
  • 评测
  • [2023-09-24 19:42:59]
  • 提交

answer

// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
#define i128 __int128
//#define int long long
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}

#define mod 1000000007
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,int b){return a.x==b;}
	friend bool operator !=(modint a,int b){return a.x!=b;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 200005
#define inf 0x3f3f3f3f

int n;
char s[maxn],t[maxn];
vi e[maxn];

int typ(char c){
	if(c=='?')return 2;
	return c&1;
}

int as[3],at[3],bs[3],bt[3];

struct node{
	int A,s1,s2,lim;
	modint res;
	// j<=lim,\sum C(A,j)*C(s1-A,s2-j)
	void adda(){
		res-=C(A,lim)*C(s1-A-1,s2-lim-1);
		++A;
	}
	void suba(){
		--A;
		res+=C(A,lim)*C(s1-A-1,s2-lim-1);
	}
	void addlim(){
		++lim;
		res+=C(A,lim)*C(s1-A,s2-lim);
	}
	void sublim(){
		res-=C(A,lim)*C(s1-A,s2-lim);
		--lim;
	}
	void init(){
		res=0;
		For(j,0,lim)res+=C(A,j)*C(s1-A,s2-j);
	}
}T1,T2;

void add(int i){
	--bs[s[i]],--bt[t[i]];
	++as[s[i]],++at[t[i]];
	if(s[i]==2) T1.adda(),T2.adda();
	if(t[i]==2) T1.adda(),T2.adda(),T1.addlim(),T2.addlim();
	if(s[i]==0) T1.sublim(),T2.sublim();
	if(t[i]==0) T1.addlim(),T2.addlim();
}
void sub(int i){
	++bs[s[i]],++bt[t[i]];
	--as[s[i]],--at[t[i]];
	if(s[i]==2) T1.suba(),T2.suba();
	if(t[i]==2) T1.suba(),T2.suba(),T1.sublim(),T2.sublim();
	if(s[i]==0) T1.addlim(),T2.addlim();
	if(t[i]==0) T1.sublim(),T2.sublim();
}

int dep[maxn];
int que[maxn],idx,L[maxn],R[maxn],sz[maxn],son[maxn];
void dfs0(int u,int pa){
	que[++idx]=u,L[u]=idx;
	sz[u]=1,son[u]=0;
	if(dep[u]){
		if(s[u]!='?')s[u]^=1;
		if(t[u]!='?')t[u]^=1;
	}
	for(int v:e[u])
		if(v!=pa){
			dep[v]=dep[u]^1,dfs0(v,u),sz[u]+=sz[v];
			if(sz[v]>sz[son[u]])son[u]=v;
		}
	R[u]=idx;
}

modint res;
void Ins(int u){
	For(i,L[u],R[u]) add(que[i]);
}
void Del(int u){
	For(i,L[u],R[u]) sub(que[i]);
}
void calc(){
		int A=as[2]+at[2],AA=at[2]-as[0]+at[0];
		int B=bs[2]+bt[2],BB=bt[2]-bs[0]+bt[0];
		// A+B = s? + t?
		// AA+BB = t?-s0+t0
		
		modint res1=0,res2=0;
//		For(j,0,n){
//			res1+=C(A,AA-j)*C(B,BB+j);
//			res2+=C(A,AA-j)*C(B-1,BB+j-1);
//		}
		res1=T1.res;
		res2=T2.res;
		res2*=B;
		res+=2*(res2-res1*BB);
		
		res1=C(A+B,AA+BB);
		res2=C(A+B-1,AA+BB-1)*B;
		res-=res2-res1*BB;
}
void dfs(int u,int pa){
	for(int v:e[u])
		if(v!=pa && v!=son[u]){
			dfs(v,u);
			Del(v);
		}
	if(son[u]) dfs(son[u],u);
	for(int v:e[u])
		if(v!=pa && v!=son[u]) Ins(v);
	add(u);
	if(pa) calc();
}
void work()
{
	n=read(); res=0;
	For(i,1,n)e[i].clear();idx=0;
	For(i,2,n){
		int u=read(),v=read();
		e[u].pb(v),e[v].pb(u);
	}
	
	cin>>(s+1)>>(t+1);
	dep[1]=0,dfs0(1,0);
	
	For(i,1,n) s[i]=typ(s[i]),t[i]=typ(t[i]);
	For(i,0,2) as[i]=at[i]=bs[i]=bt[i]=0;
	For(i,1,n) ++bs[s[i]],++bt[t[i]];
	
	T1.s1=bs[2]+bt[2];
	T1.s2=bt[2]-bs[0]+bt[0];
	T2.s1=T1.s1-1;
	T2.s2=T1.s2-1;
	T1.lim=T2.lim=0;
	T1.A=T2.A=0;
	T1.init(),T2.init();
	
	dfs(1,0);
	cout<<res.x<<"\n";
}

signed main()
{
	int T=read();
	while(T--)work();
	return 0;
}
/*
C(n,m) * m == C(n-1,m-1) * n
fac[n] * ifac[m-1] * ifac[n-m]
C(n-1,m-1) * n
fac[n-1] * ifac[m-1] * ifac[n-m]

C(m,k)*k
C(m-1,k-1)*m

1 4 7 10 3 6 9 2 5 8 11

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
1 10 45 120 210 252 210 120 45 10 1
我发现这题里 A+B 和 AA+BB 是定值,所以应该能移动端点
*/

詳細信息

answer.code: In function ‘void work()’:
answer.code:195:12: error: no match for ‘operator>>’ (operand types are ‘std::istream’ {aka ‘std::basic_istream<char>’} and ‘char*’)
  195 |         cin>>(s+1)>>(t+1);
      |         ~~~^~~~~~~
      |         |      |
      |         |      char*
      |         std::istream {aka std::basic_istream<char>}
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:5:
/usr/include/c++/11/istream:168:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ (near match)
  168 |       operator>>(bool& __n)
      |       ^~~~~~~~
/usr/include/c++/11/istream:168:7: note:   conversion of argument 1 would be ill-formed:
answer.code:195:16: error: cannot bind non-const lvalue reference of type ‘bool&’ to a value of type ‘char*’
  195 |         cin>>(s+1)>>(t+1);
      |              ~~^~~
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:5:
/usr/include/c++/11/istream:172:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]’ (near match)
  172 |       operator>>(short& __n);
      |       ^~~~~~~~
/usr/include/c++/11/istream:172:7: note:   conversion of argument 1 would be ill-formed:
answer.code:195:16: error: invalid conversion from ‘char*’ to ‘short int’ [-fpermissive]
  195 |         cin>>(s+1)>>(t+1);
      |              ~~^~~
      |                |
      |                char*
answer.code:195:16: error: cannot bind rvalue ‘(short int)(((char*)(& s)) + 1)’ to ‘short int&’
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:5:
/usr/include/c++/11/istream:175:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ (near match)
  175 |       operator>>(unsigned short& __n)
      |       ^~~~~~~~
/usr/include/c++/11/istream:175:7: note:   conversion of argument 1 would be ill-formed:
answer.code:195:16: error: invalid conversion from ‘char*’ to ‘short unsigned int’ [-fpermissive]
  195 |         cin>>(s+1)>>(t+1);
      |              ~~^~~
      |                |
      |                char*
answer.code:195:16: error: cannot bind rvalue ‘(short unsigned int)(((char*)(& s)) + 1)’ to ‘short unsigned int&’
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:5:
/usr/include/c++/11/istream:179:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]’ (near match)
  179 |       operator>>(int& __n);
      |       ^~~~~~~~
/usr/include/c++/11/istream:179:7: note:   conversion of argument 1 would be ill-formed:
answer.code:195:16: error: invalid conversion from ‘char*’ to ‘int’ [-fpermissive]
  195 |         cin>>(s+1)>>(t+1);
      |              ~~^~~
      |                |
      |                char*
answer.code:195:16: error: cannot bind rvalue ‘(int)(((char*)(& s)) + 1)’ to ‘int&’
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:5:
/usr/include/c++/11/istream:182:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ (near match)
  182 |       operator>>(unsigned int& __n)
      |       ^~~~~~~~
/usr/include/c++/11/istream:182:7: note:   conversion of argument 1 would be ill-formed:
answer.code:195:16: error: invalid conv...