QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#79829#2131. Zbiory niezależne [A]Crysfly10 ✓8244ms108016kbC++176.7kb2023-02-20 23:49:562023-02-20 23:50:00

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-20 23:50:00]
  • 评测
  • 测评结果:10
  • 用时:8244ms
  • 内存:108016kb
  • [2023-02-20 23:49:56]
  • 提交

answer

// what is matter? never mind.
#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)
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 998244353
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 poly vector<modint>
const modint G=3,Ginv=modint(1)/3;
inline poly one(){poly a;a.push_back(1);return a;}
vector<int>rev;
vector<modint>rts;
inline int ext(int n){
	int k=0;
	while((1<<k)<n)++k;return k; 
}
inline void init(int k){
	int n=1<<k;
	if(rev.size()==n)return;
	rev.resize(n);
	For(i,0,n-1)rev[i]=(rev[i>>1]>>1)|((i&1)<<(k-1));
	if(rts.size()>=n)return;
	int lst=max(1,(int)rts.size()); rts.resize(n);
	for(int mid=lst;mid<n;mid<<=1){
		modint wn=G^((mod-1)/(mid<<1));
		rts[mid]=1;
		For(i,1,mid-1)rts[i+mid]=rts[i+mid-1]*wn;
	}
}
void ntt(poly&a,int k,int typ)
{
	int n=1<<k;
	if(typ<0) reverse(a.begin()+1,a.end());
	For(i,0,n-1)if(i<rev[i])swap(a[i],a[rev[i]]); 
	for(int mid=1;mid<n;mid<<=1)
		for(int r=mid<<1,j=0;j<n;j+=r)
			for(int k=0;k<mid;++k){
				modint x=a[j+k],y=rts[mid+k]*a[j+k+mid];
				a[j+k]=x+y,a[j+k+mid]=x-y;
			}
	if(typ<0){
		modint inv=modint(1)/n;
		For(i,0,n-1)a[i]*=inv;
	}
}
 
poly operator +(poly a,poly b){
	int n=max(a.size(),b.size());a.resize(n),b.resize(n);
	For(i,0,n-1)a[i]+=b[i];return a;
}
poly operator -(poly a,poly b){
	int n=max(a.size(),b.size());a.resize(n),b.resize(n);
	For(i,0,n-1)a[i]-=b[i];return a;
}
poly operator *(poly a,modint b){
	int n=a.size();
	For(i,0,n-1)a[i]*=b;return a;
} 
poly operator *(modint b,poly a){
	int n=a.size();
	For(i,0,n-1)a[i]*=b;return a;
} 
poly operator *(poly a,poly b){
	if(!a.size()||!b.size())return {};
	if((int)a.size()<=32 || (int)b.size()<=32){
		poly c(a.size()+b.size()-1,0);
		for(int i=0;i<a.size();++i)
			for(int j=0;j<b.size();++j)
				c[i+j]+=a[i]*b[j];
		return c; 
	}
	int n=(int)a.size()+(int)b.size()-1,k=ext(n);
	a.resize(1<<k),b.resize(1<<k),init(k);
	ntt(a,k,1),ntt(b,k,1);
	For(i,0,(1<<k)-1)a[i]*=b[i];
	ntt(a,k,-1),a.resize(n);return a;
}

poly Tmp;
poly pmul(poly a,poly b,int n,bool ok=0)
{
	int k=ext(n); init(k);
	a.resize(1<<k),ntt(a,k,1);
	if(!ok) b.resize(1<<k),ntt(b,k,1),Tmp=b;
	For(i,0,(1<<k)-1)a[i]*=Tmp[i];
	ntt(a,k,-1),a.resize(n);
	return a;
}
poly inv(poly a,int n)
{
	a.resize(n);
	if(n==1){
		poly f(1,1/a[0]);
		return f;
	}
	poly f0=inv(a,(n+1)>>1),f=f0;
	poly now=pmul(a,f0,n,0);
	for(int i=0;i<f0.size();++i)now[i]=0;
	now=pmul(now,poly(0),n,1);
	f.resize(n);
	for(int i=f0.size();i<n;++i)f[i]=-now[i];
	return f;
}
poly inv(poly a){return inv(a,a.size());}

poly deriv(poly a){
	int n=(int)a.size()-1;
	For(i,0,n-1)a[i]=a[i+1]*(i+1);
	a.resize(n);return a;
}
poly inter(poly a){
	int n=a.size()+1;a.resize(n);
	Rep(i,n-1,1)a[i]=a[i-1]/i;
	a[0]=0;return a;
}
poly ln(poly a){
	int n=a.size();
	a=inter(deriv(a)*inv(a));
	a.resize(n);return a;
}
poly exp(poly a,int k){
	int n=1<<k;a.resize(n);
	if(n==1)return one();
	poly f0=exp(a,k-1);f0.resize(n);
	return f0*(one()+a-ln(f0)); 
}
poly exp(poly a){
	int n=a.size();
	a=exp(a,ext(n));a.resize(n);return a;
}

#define maxn 1000005
#define inf 0x3f3f3f3f

modint c;
poly g,h,eg;
poly get(poly f,int n){
	poly res(n,0);
	f.resize(n);
	For(i,2,n-1)
		for(int j=0;i*j<n;++j)
			res[j*i]+=iv[i]*f[j];
	return res;
}
poly mulx(poly f){
	int n=f.size(); f.resize(n+1);
	Rep(i,n,1)f[i]=f[i-1]; f[0]=0; return f;
}
void solve(int mx){
	g={0},h={0},eg={1};
	for(int n=2;n<=mx;n<<=1){
		poly a=get(g+h,n);
		poly b=get(g,n);
		g.resize(n),h.resize(n);
		poly C=mulx({c});
		
	//	cout<<"n: "<<n<<endl;
	//	for(auto x:a)cout<<x.x<<" ";cout<<"\n";
	//	for(auto x:b)cout<<x.x<<" ";cout<<"\n";
		
		poly ex1=exp(b+g);
		poly ex2=exp(g+a);
		poly ex3=C*ex1; ex3.resize(n); ex3=exp(ex3);
		poly qwq=mulx(ex1)*c; qwq.resize(n); // qwq = c*x*e^{g+b}
		poly up=c*ex2*ex3-c*ex1-g; up.resize(n);
		
		poly dw=ex3*(C*c*ex1*ex2+c*ex2);
		dw=dw-c*ex1;
		dw[0]-=1; dw.resize(n);
		
	//	for(auto x:up)cout<<x.x<<" ";cout<<"\n";
	//	for(auto x:dw)cout<<x.x<<" ";cout<<"\n";
		
		poly res=g-up*inv(dw); res.resize(n);
		
	//	poly chk=c*exp(a+res+C*exp(b+res))-c*exp(b+res); chk.resize(n);
	//	for(auto x:chk)cout<<x.x<<" "; cout<<"  chk\n";
	//	for(auto x:res)cout<<x.x<<" "; cout<<"  res\n";
		
		g=res;
		h=mulx(exp(b+g))*c; h.resize(n);
		
	//	for(auto x:g)cout<<x.x<<" ";puts("");
	//	for(auto x:h)cout<<x.x<<" ";puts("");
	}
}

poly sq(poly f){
	int n=f.size();
	poly res(n);
	For(i,0,n-1)if(i%2==0)res[i]=f[i/2];
	return res;
}
poly divx(poly f){
	int n=f.size();
	assert(f[0].x==0);
	For(i,0,n-2)f[i]=f[i+1];
	f.resize(n-1);
	return f;
}
signed main()
{
	initC(1<<20);
	int l=read(),r=read();
	int n=1<<ext(r+2);
	c=read();
	solve(n);
	poly res=g+h;
	res=res-g*h;
	res=res+((mod+1)/2)*(sq(g)-g*g);
	res=res+((mod+1)/2)*divx(sq(h)-h*h);
	res.resize(n);
//	for(auto x:res)cout<<x.x<<" ";
	modint out=0;
	For(i,l,r)out+=res[i];
	cout<<out.x; 
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 23ms
memory: 15208kb

input:

1 3 1

output:

9

result:

ok single line: '9'

Test #2:

score: 0
Accepted
time: 11ms
memory: 15300kb

input:

1 3 2

output:

149

result:

ok single line: '149'

Test #3:

score: 0
Accepted
time: 15ms
memory: 15336kb

input:

1 1 1

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 20ms
memory: 15300kb

input:

1 8 1

output:

5227

result:

ok single line: '5227'

Test #5:

score: 0
Accepted
time: 12ms
memory: 15340kb

input:

3 8 1

output:

5223

result:

ok single line: '5223'

Subtask #2:

score: 1
Accepted

Test #6:

score: 1
Accepted
time: 22ms
memory: 15340kb

input:

80 80 1

output:

812033063

result:

ok single line: '812033063'

Test #7:

score: 0
Accepted
time: 19ms
memory: 15336kb

input:

78 78 1

output:

182498472

result:

ok single line: '182498472'

Test #8:

score: 0
Accepted
time: 11ms
memory: 15296kb

input:

75 75 1

output:

617232937

result:

ok single line: '617232937'

Subtask #3:

score: 1
Accepted

Test #9:

score: 1
Accepted
time: 65ms
memory: 16196kb

input:

3000 3000 1

output:

316190887

result:

ok single line: '316190887'

Test #10:

score: 0
Accepted
time: 58ms
memory: 16216kb

input:

2836 2836 1

output:

78805654

result:

ok single line: '78805654'

Subtask #4:

score: 1
Accepted

Test #11:

score: 1
Accepted
time: 208ms
memory: 18228kb

input:

10000 10000 737697546

output:

662262394

result:

ok single line: '662262394'

Test #12:

score: 0
Accepted
time: 222ms
memory: 18324kb

input:

9692 9692 521790758

output:

688689567

result:

ok single line: '688689567'

Subtask #5:

score: 1
Accepted

Test #13:

score: 1
Accepted
time: 911ms
memory: 26884kb

input:

46264 60000 823824735

output:

279507395

result:

ok single line: '279507395'

Test #14:

score: 0
Accepted
time: 906ms
memory: 26888kb

input:

40971 58765 596622251

output:

519148445

result:

ok single line: '519148445'

Subtask #6:

score: 1
Accepted

Test #15:

score: 1
Accepted
time: 1850ms
memory: 38108kb

input:

1315 120000 1

output:

400606029

result:

ok single line: '400606029'

Test #16:

score: 0
Accepted
time: 1877ms
memory: 38108kb

input:

65583 118765 1

output:

930420532

result:

ok single line: '930420532'

Subtask #7:

score: 1
Accepted

Test #17:

score: 1
Accepted
time: 3938ms
memory: 61760kb

input:

250000 250000 485195676

output:

723474605

result:

ok single line: '723474605'

Test #18:

score: 0
Accepted
time: 3851ms
memory: 61820kb

input:

234567 234567 549849068

output:

674655026

result:

ok single line: '674655026'

Subtask #8:

score: 1
Accepted

Test #19:

score: 1
Accepted
time: 3870ms
memory: 61728kb

input:

124158 250000 526698216

output:

401019144

result:

ok single line: '401019144'

Test #20:

score: 0
Accepted
time: 3863ms
memory: 61752kb

input:

164096 244921 299495732

output:

460839141

result:

ok single line: '460839141'

Subtask #9:

score: 1
Accepted

Test #21:

score: 1
Accepted
time: 7995ms
memory: 107916kb

input:

500000 500000 504789929

output:

821656212

result:

ok single line: '821656212'

Test #22:

score: 0
Accepted
time: 8048ms
memory: 108016kb

input:

489127 489127 612302745

output:

411092702

result:

ok single line: '411092702'

Subtask #10:

score: 1
Accepted

Test #23:

score: 1
Accepted
time: 8244ms
memory: 107932kb

input:

482751 500000 921732625

output:

368107184

result:

ok single line: '368107184'

Test #24:

score: 0
Accepted
time: 8225ms
memory: 107936kb

input:

55889 499999 19705394

output:

706108398

result:

ok single line: '706108398'