QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#377763#622. 多项式多点求值fragmentCompile Error//C++174.0kb2024-04-05 17:35:532024-04-05 17:35:54

Judging History

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

  • [2024-04-05 17:35:54]
  • 评测
  • [2024-04-05 17:35:53]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
typedef unsigned long long ull;
const int mod=998244353,i2=(mod+1)>>1,i3=332748118,o=21;
int n,m,f[1<<o],q[1<<o],ans;
int t1[1<<o],t2[1<<o];
int fac[1<<o],ifac[1<<o],iv[1<<o];
inline int add(int x,int y){return x+y<mod?x+y:x+y-mod;}
inline int sub(int x,int y){return x<y?x+mod-y:x-y;}
inline int power(int a,int n){
	int tp=1;
	while(n){
		if(n&1) tp=1ll*tp*a%mod;
		a=1ll*a*a%mod,n>>=1;
	}
	return tp;
}
namespace poly{
	int w[1<<o],r[1<<o],up,l;
	inline void pre(int n){
		up=1,l=0;
		while(up<=n) up<<=1,l++;
		for(int i=0;i<up;i++) r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
	}
	inline void init(){
		const int w0=power(3,(mod-1)>>o);
		w[1<<(o-1)]=1;
		for(int i=(1<<(o-1))+1;i<(1<<o);i++) w[i]=1ll*w[i-1]*w0%mod;
		for(int i=(1<<(o-1))-1;~i;i--) w[i]=w[i<<1];
	}
	
void ntt(int *a, int n, bool op) {
  static ull t[len], x, y;
  for (int i = 0; i != n; i += 2) {
    x = a[r[i] >> (o - l)], y = a[r[i + 1] >> (o - l)];
    t[i] = x + y, t[i + 1] = x + mod - y;
  }
  for (int l = 2; l != n; l <<= 1) {
    if (l == (1 << 18))
      for (ull *f = t; f != t + n; f++)
        *f %= mod;
    int *k = w + l;
    for (ull *f = t; f != t + n; f += l)
      for (int *j = k; j != k + l; j++, f++) {
        ull x = *f, y = f[l] * *j % mod;
        f[l] = x + mod - y, *f += y;
      }
  }
  if (op) {
    if (n == (1 << 18))
      for (ull *f = t; f != t + n; f++)
        *f %= mod;
    for (int i = 0, x = mod - (mod >> l); i != n; i++)
      a[i] = t[i] * x % mod;
    reverse(a + 1, a + n);
  } else
    for (int i = 0; i != n; i++)
      a[i] = t[i] % mod;
}
	inline void mul(int *f,int n,int *g,int m,int *h,int q){
		static int a[1<<o],b[1<<o];
		pre(n+m);
		memcpy(a,f,(n+1)<<2),memcpy(b,g,(m+1)<<2);
		ntt(a,up,0),ntt(b,up,0);
		for(int i=0;i<up;i++) h[i]=1ll*a[i]*b[i]%mod;
		ntt(h,up,1);
		fill(a,a+up,0),fill(b,b+up,0),fill(h+q+1,h+up,0);
	}
	inline void inv(int *a,int n,int *f){
		static int x[1<<o];
		int lt=(n+1)>>1;
		if(!n){f[0]=power(a[0],mod-2);return;}
		if(n==1) lt=0;
		inv(a,lt,f);
		pre(2*lt+n);
		memcpy(x,a,(n+1)<<2);
		ntt(f,up,0),ntt(x,up,0);
		for(int i=0;i<up;i++) f[i]=1ll*f[i]*(2-1ll*x[i]*f[i]%mod+mod)%mod;
		ntt(f,up,1);
		fill(x,x+up,0),fill(f+n+1,f+up,0);
	}
	vector<int> v[240001];
	inline void solve1(int i,int l,int r){
		static int t1[1<<o],t2[1<<o];
		if(l==r){v[i].push_back(1),v[i].push_back(sub(0,q[l]));return;}
		int mid=(l+r)>>1;
		solve1(i<<1,l,mid),solve1(i<<1|1,mid+1,r);
		for(int j=0;j<=mid-l+1;j++) t1[j]=v[i<<1][j];
		for(int j=0;j<=r-mid;j++) t2[j]=v[i<<1|1][j];
		mul(t1,mid-l+1,t2,r-mid,t1,r-l+1),v[i].resize(r-l+2);
		for(int j=0;j<=r-l+1;j++) v[i][j]=t1[j];
		fill(t1,t1+r-l+2,0),fill(t2,t2+r-mid+1,0);
	}
	inline void solve2(int i,int l,int r,vector<int> f){
		static int t1[1<<o],t2[1<<o];
		if(l==r){
			printf("%d\n",sub(ans,1ll*f[0]*v[i][1]%mod));
			return;
		}
		int mid=(l+r)>>1,len=f.size()-1;
		vector<int> f1,f2;
		if(r-l<=f.size()) pre(len);
		else pre(len+mid-l+1);
		for(int j=0;j<=len;j++) t1[j]=f[j];
		for(int j=0;j<=r-mid;j++) t2[j]=v[i<<1|1][j];
		ntt(t1,up,0),ntt(t2,up,0);
		for(int j=0;j<up;j++) t2[j]=1ll*t1[j]*t2[j]%mod;
		ntt(t2,up,1);
		for(int j=max(len-mid+l,0);j<=len;j++) f1.push_back(t2[j]);
		fill(t2,t2+up,0);
		for(int j=0;j<=mid-l+1;j++) t2[j]=v[i<<1][j];
		ntt(t2,up,0);
		for(int j=0;j<up;j++) t2[j]=1ll*t1[j]*t2[j]%mod;
		ntt(t2,up,1);
		for(int j=max(len-r+mid+1,0);j<=len;j++) f2.push_back(t2[j]);
		fill(t2,t2+up,0),fill(t1,t1+up,0);
		solve2(i<<1,l,mid,f1),solve2(i<<1|1,mid+1,r,f2);
	}
}
int main(){
	poly::init();
	cin>>n>>m;
	cin>>ans;for(int i=n-1;~i;i--) scanf("%d",f+i);
	for(int i=1;i<=m;i++) scanf("%d",q+i);
	poly::solve1(1,1,m);
	for(int i=0;i<=m;i++) t1[i]=poly::v[1][i];
	poly::inv(t1,n-1,t2);
	poly::mul(f,n-1,t2,n-1,f,n-1);
	vector<int> g;
	for(int i=max(n-m,0);i<n;i++) g.push_back(f[i]);
	poly::solve2(1,1,m,g);
}

详细

answer.code: In function ‘void poly::ntt(int*, int, bool)’:
answer.code:37:16: error: ‘len’ was not declared in this scope
   37 |   static ull t[len], x, y;
      |                ^~~
answer.code:40:5: error: ‘t’ was not declared in this scope
   40 |     t[i] = x + y, t[i + 1] = x + mod - y;
      |     ^
answer.code:44:21: error: ‘t’ was not declared in this scope
   44 |       for (ull *f = t; f != t + n; f++)
      |                     ^
answer.code:47:19: error: ‘t’ was not declared in this scope
   47 |     for (ull *f = t; f != t + n; f += l)
      |                   ^
answer.code:55:21: error: ‘t’ was not declared in this scope
   55 |       for (ull *f = t; f != t + n; f++)
      |                     ^
answer.code:58:14: error: ‘t’ was not declared in this scope
   58 |       a[i] = t[i] * x % mod;
      |              ^
answer.code:62:14: error: ‘t’ was not declared in this scope
   62 |       a[i] = t[i] % mod;
      |              ^
answer.code: In function ‘int main()’:
answer.code:127:45: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  127 |         cin>>ans;for(int i=n-1;~i;i--) scanf("%d",f+i);
      |                                        ~~~~~^~~~~~~~~~
answer.code:128:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  128 |         for(int i=1;i<=m;i++) scanf("%d",q+i);
      |                               ~~~~~^~~~~~~~~~