QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#91402#622. 多项式多点求值Minion#0 0ms0kbC++235.0kb2023-03-28 20:08:182023-03-28 20:08:22

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-28 20:08:22]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-03-28 20:08:18]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#include<vector>
#define fo(i,x,y) for(int i = x;i <= y;++i)
#define fd(i,x,y) for(int i = x;i >= y;--i)
#define _is 1048576 * 20
#define _os 1048576 * 10
#define gc() ib[++bi]
#define pc(ch) ob[++bo] = ch
using namespace std;
char ib[_is],ob[_os];int bi = -1,bo = -1;
int rd()
{
	int x = 0;char ch = gc();
	while(ch < 48 || ch > 57) ch = gc();
	while(ch >= 48 && ch <= 57) x = x * 10 + ch - 48,ch = gc();
	return x;
}
void pr(int x)
{
	char ch[20];int w = -1;
	if(x == 0) ch[++w] = 48;
	while(x) ch[++w] = x % 10 + 48,x /= 10;
	fd(i,w,0) pc(ch[i]);pc('\n');
}
namespace Polyint
{
	#define sz(x) int(x.size())
	#define add(x,y) (x >= p - y ? x + y - p : x + y)
	#define sub(x,y) (x < y ? x - y + p : x - y)
	#define p 998244353
	
	int max(int x,int y) {return y < x ? x : y;}
	inline int ksm(int x,int y) {int res = 1;for(;y;y >>= 1,x = 1ll * x * x % p) if(y & 1) res = 1ll * res * x % p;return res;}
	vector<int> w;
	int pN = 0;
	void pre(int N,int lg)
	{
		w.resize((N >> 1) + 1);
		w[0] = 1,w[1ll << (lg - 1)] = ksm(3,(p - 1) >> (lg + 1));
		fd(i,lg - 1,1) w[1ll << (i - 1)] = 1ll * w[1ll << i] * w[1ll << i] % p;
		fo(i,1,1 << (lg - 1)) w[i] = 1ll * w[i & i - 1] * w[i & -i] % p;
	}
	struct poly
	{
		vector<int> a;

		poly() {}
		poly(int sz) {a.resize(sz);}
		poly(vector<int> b) {a = b;}
		poly(int *itl,int *itr) {a = vector<int>(itl,itr);}
		poly(poly &b) {a = b.a;}

		int &operator [](int x) {return a[x];}
		void resize(int x) {a.resize(x);}
		int at(int x) {return x >= sz(a) ? 0 : a[x];}
		void clear() {a.clear(),a.shrink_to_fit();}
		int size() {return a.size();}

		void DIF()
		{
			int N = sz(a);
			for(int l = N >> 1;l;l >>= 1) for(int i = 0,k = 0;i < N;i += l << 1,++k) fo(j,0,l - 1)
			{
				int x = a[i + j],y = 1ll * a[i + j + l] * w[k] % p;
				a[i + j] = add(x,y),a[i + j + l] = sub(x,y);
			}
		}
		void DIT()
		{
			int N = sz(a);
			for(int l = 1;l < N;l <<= 1) for(int i = 0,k = 0;i < N;i += (l << 1),++k) fo(j,0,l - 1)
			{
				int x = a[i + j],y = a[i + j + l];
				a[i + j] = add(x,y),a[i + j + l] = 1ll * sub(x,y) * w[k] % p;
			}
			fo(i,1,(N - 1) >> 1) a[i] ^= a[N - i] ^= a[i] ^= a[N - i];
            int ny = ksm(N,p - 2);
			fo(i,0,N - 1) a[i] = 1ll * a[i] * ny % p;
		}
		void plus(poly &b)
		{
			resize(max(sz(a),sz(b.a)));
			fo(i,0,sz(a) - 1) a[i] = add(a[i],b.at(i));
		}
		void minus(poly &b)
		{
			resize(max(sz(a),sz(b.a)));
			fo(i,0,sz(a) - 1) a[i] = sub(a[i],b.at(i));
		}
		void mul(poly &b)
		{
			poly c(b);
			int N = 1,lg = 0,n = sz(a) + sz(b);
			if(sz(a) <= 50 || sz(c) <= 50)
			{
				poly d(*this);clear(),resize(n - 1);
				fo(i,0,sz(d) - 1)
				{
					if(d.a[i] == 0) continue;
					fo(j,0,sz(c) - 1) a[i + j] = (a[i + j] + 1ll * d[i] * c[j]) % p;
				}
			}
			else
			{
				while(N < n) N <<= 1,++lg;
				if(N > pN) pre(N,lg),pN = N;
				resize(N),c.resize(N),DIF(),c.DIF();
				fo(i,0,N - 1) a[i] = 1ll * a[i] * c[i] % p;
				DIT();
			}
			a.resize(n - 1);
		}
		void inv()
		{
			poly res,f,g;res.resize(1),res[0] = ksm(a[0],p - 2);
			for(int i = 1,lg = 0;i < sz(a);i <<= 1,++lg)
			{
				f = res,f.resize(i << 1),g.resize(i << 1),res.resize(i << 1);
				if((i << 1) > pN) pre(i << 1,lg + 1),pN = i << 1;
				fo(j,0,(i << 1) - 1) g[j] = (*this).at(j);
				f.DIF(),g.DIF();
				fo(j,0,(i << 1) - 1) g[j] = 1ll * g[j] * f[j] % p;
				g.DIT();
				fo(j,0,i - 1) g[j] = 0;
				g.DIF();
				fo(j,0,(i << 1) - 1) g[j] = 1ll * g[j] * f[j] % p;
				g.DIT();
				fo(j,i,(i << 1) - 1) res[j] = (p - g[j]) % p;
			}
			res.resize(sz(a)),(*this) = res;
		}
	};
}
using Polyint::poly;
int n,m;
poly g[4050010];
void getg(int x,int l,int r,const vector<int> &b)
{
	if(l == r)
	{
		if(l >= b.size()) g[x].resize(1),g[x][0] = 1;
		else g[x].resize(2),g[x][0] = (p - b[l]) % p,g[x][1] = 1;
		return;
	}
	int m = (l + r) >> 1;
	getg(x << 1,l,m,b),getg(x << 1 | 1,m + 1,r,b);
	g[x] = g[x << 1],g[x].mul(g[x << 1 | 1]);
}
void Getv(poly &a,int x,int l,int r,int bm,vector<int> &ans)
{
	if(l == r) {ans[l] = a[0];return;}
	int m = (l + r) >> 1;
	poly ta(a);
	ta.mul(g[x << 1 | 1]);
	fo(i,0,sz(ta) - sz(g[x << 1 | 1])) ta[i] = ta[i + sz(g[x << 1 | 1]) - 1];
	ta.resize(sz(g[x << 1])),Getv(ta,x << 1,l,m,bm,ans);
	if(m + 1 < bm)
	{
		ta = a,ta.mul(g[x << 1]);
		fo(i,0,sz(ta) - sz(g[x << 1])) ta[i] = ta[i + sz(g[x << 1]) - 1];
		ta.resize(sz(g[x << 1 | 1])),Getv(ta,x << 1 | 1,m + 1,r,bm,ans);
	}
}
vector<int> getv(poly a,const vector<int> &b)
{
	int n = max(a.size(),int(b.size()));
	getg(1,0,n - 1,b);
	poly ig = g[1];reverse(ig.a.begin(),ig.a.end()),ig.resize(n),ig.inv(),reverse(ig.a.begin(),ig.a.end());
	a.resize(n),a.mul(ig);
	fo(i,0,n - 1) a[i] = a[i + n - 1];a.resize(n);
	vector<int> ans(m);
	return Getv(a,1,0,n - 1,sz(b),ans),ans;
}
int main()
{
	fread(ib,1,_is,stdin);
	n = rd(),m = rd();
	poly a(n + 1);
	fo(i,0,n) a[i] = rd();
	vector<int> b(m);
	fo(i,0,m - 1) b[i] = rd();
	vector<int> v = getv(a,b);
	fo(i,0,m - 1) pr(v[i]);
	fwrite(ob,1,bo + 1,stdout);
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

100 94
575336069 33153864 90977269 80162592 25195235 334936051 108161572 14050526 356949084 797375084 805865808 286113858 995555121 938794582 458465004 379862532 563357556 293989886 273730531 13531923 113366106 126368162 405344025 443053020 475686818 734878619 338356543 661401660 834651229 527993675...

output:


result:


Test #2:

score: 0
Runtime Error

input:

5000 4999
410683245 925831211 726803342 144364185 955318244 291646122 334752751 893945905 484134283 203760731 533867267 813509277 491860093 413174124 584582617 594704162 976489328 978500071 196938934 628117769 169796671 858963950 562124570 582491326 647830593 238623335 20782490 674939336 656529076 2...

output:


result:


Test #3:

score: 0
Runtime Error

input:

30000 29995
536696866 881441742 356233606 594487396 991820796 695996817 7219464 149265950 843761437 329761701 260625152 80366362 598729314 133794090 12808683 67477659 320740422 878134577 879383179 940923483 660160621 18082378 886078389 524050341 35092018 137623841 988429688 258507355 138475726 75726...

output:


result:


Test #4:

score: 0
Runtime Error

input:

100000 99989
703908936 826436271 431732352 607460686 960390248 897906950 506352459 662618885 172508812 713410533 704313866 156459539 879660919 98030681 46358006 400134234 121190289 498201666 616888945 210891377 39623412 687350951 269444705 980768130 381802923 553892268 644461704 287608268 554761733 ...

output:


result:


Test #5:

score: 0
Runtime Error

input:

1000000 999998
326289172 459965021 432610030 381274775 890620650 133203219 755508578 820410129 100497878 978894337 34545975 484258543 341383383 556328539 705716773 985485996 201697555 806763870 456757110 445252781 501965590 655584951 516373423 475444481 554722275 106826011 433893131 385018453 687541...

output:


result: