QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#735855#9120. Huge Segment Treeucup-team134TL 21ms20488kbC++173.2kb2024-11-11 22:06:112024-11-11 22:06:13

Judging History

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

  • [2024-11-11 22:06:13]
  • 评测
  • 测评结果:TL
  • 用时:21ms
  • 内存:20488kb
  • [2024-11-11 22:06:11]
  • 提交

answer

#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128

using namespace std;

mt19937 rng(time(NULL));
const int mod=998244353;
inline int add(int x,int y){int ret=x+y;if(ret>=mod)ret-=mod;return ret;}
inline int sub(int x,int y){int ret=x-y;if(ret<0)ret+=mod;return ret;}
inline int mul(int x,int y){return ((ll)x*y)%mod;}
inline int step(int base,int pw){int ret=1;while(pw){if(pw&1)ret=mul(ret,base);base=mul(base,base);pw>>=1;}return ret;}
inline int invv(int x){return step(x,mod-2);}
namespace fft{
const int maxn=(1<<22);
int proot=step(3,7*17*2);
int prekw[maxn];
bool isprek=false;
void prek(){
    if(isprek)return;
    isprek=true;
    prekw[0]=1;
    for(int i=1;i<maxn;i++){
        prekw[i]=mul(prekw[i-1],proot);
    }
}
void fft(vector<int>&a,bool invert){

    prek();

    int n=a.size();
    int j=0;
    for(int i=1;i<n;i++){
        int bit=n>>1;
        for(;bit&j;bit>>=1)j^=bit;
        j^=bit;
        if(i<j)swap(a[i],a[j]);
    }

    for(int len=2;len<=n;len<<=1){
        int hlen=len>>1;
        for(int i=0;i<n;i+=len){
            int curr=0;
            int d=maxn/len;
            if(invert)d=maxn-d;
            for(int j=0;j<hlen;j++){
                int pom1=a[i+j];
                int pom2=mul(a[i+j+hlen],prekw[curr]);

                a[i+j]=add(pom1,pom2);
                a[i+j+hlen]=sub(pom1,pom2);

                curr+=d;
                if(curr>=maxn)curr-=maxn;
            }
        }
    }

    if(invert){
        int invn=invv(n);
        for(int i=0;i<n;i++)a[i]=mul(a[i],invn);
    }

}

}

void print(vector<int> a){
	printf("[ ");
	for(int i=0;i<sz(a);i++){
		printf("%i",a[i]);
		if(i==sz(a)-1)printf(" ]");
		else printf(", ");
	}
}
vector<int> mul(vector<int> ain,vector<int> bin){
	vector<int> a=ain,b=bin;
    int sz=1;
    while(sz<a.size()+b.size())sz*=2;
    sz*=2;
    a.resize(sz);
    b.resize(sz);
    fft::fft(a,false);
    fft::fft(b,false);
    for(int i=0;i<sz;i++)a[i]=mul(a[i],b[i]);
    fft::fft(a,true);
    while(a.size() && a.back()==0)a.pop_back();
    return a;
}
vector<int> add(vector<int> a,vector<int> b){
	vector<int> c(max(sz(a),sz(b)));
	for(int i=0;i<sz(a);i++)c[i]=add(c[i],a[i]);
	for(int i=0;i<sz(b);i++)c[i]=add(c[i],b[i]);
    return c;
}
int main()
{
	int k;
	cin >> k;
	vector<int> p0={0,1},p1={0,1};
	vector<int> f0={0,1},f1={0,2},f2={0,0};
	vector<int> np0,np1,nf0,nf1,nf2;
	auto trans1=[&](){
		np0=add(mul(p0,{1,1}),{0,1,-1});
		np1=mul(p1,{1,1});
		nf0=add(mul(p0,p0),add(mul(f0,{2}),{0,1,-1}));
		nf1=add(mul(mul(p0,p1),{2}),mul(f1,{2}));
		nf2=add(mul(p1,p1),mul(f2,{2}));
		p0=np0;p1=np1;f0=nf0;f1=nf1;f2=nf2;
	};
	for(int i=1;i<k;i++){
		trans1();
		/*printf("p0: ");print(p0);
		printf("\np1: ");print(p1);
		printf("\nf0: ");print(f0);
		printf("\nf1: ");print(f1);
		printf("\nf2: ");print(f2);*/
	}
	vector<int> ans=add(f0,add(f1,f2));
	for(int i=0;i<2*k-2;i++){
		printf("%i ",ans[i+1]);
	}
	printf("\n");
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 21ms
memory: 20456kb

input:

2

output:

7 3 

result:

ok 2 tokens

Test #2:

score: 0
Accepted
time: 17ms
memory: 20208kb

input:

3

output:

15 14 6 1 

result:

ok 4 tokens

Test #3:

score: 0
Accepted
time: 14ms
memory: 20236kb

input:

4

output:

31 43 36 19 6 1 

result:

ok 6 tokens

Test #4:

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

input:

5

output:

63 110 132 114 70 30 8 1 

result:

ok 8 tokens

Test #5:

score: 0
Accepted
time: 21ms
memory: 20212kb

input:

6

output:

127 255 384 448 400 272 136 47 10 1 

result:

ok 10 tokens

Test #6:

score: 0
Accepted
time: 21ms
memory: 20240kb

input:

7

output:

255 558 978 1401 1610 1478 1066 589 240 68 12 1 

result:

ok 12 tokens

Test #7:

score: 0
Accepted
time: 17ms
memory: 20200kb

input:

8

output:

511 1179 2292 3803 5250 5987 5576 4183 2482 1137 388 93 14 1 

result:

ok 14 tokens

Test #8:

score: 0
Accepted
time: 13ms
memory: 20208kb

input:

9

output:

1023 2438 5088 9398 14896 20038 22632 21250 16406 10282 5144 2006 588 122 16 1 

result:

ok 16 tokens

Test #9:

score: 0
Accepted
time: 16ms
memory: 20488kb

input:

10

output:

2047 4975 10896 21772 38360 58724 77184 86312 81448 64324 42112 22576 9744 3304 848 155 18 1 

result:

ok 18 tokens

Test #10:

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

input:

11

output:

4095 10070 22782 48209 92140 156292 232068 298744 330926 313422 252186 171122 97008 45368 17200 5155 1176 192 20 1 

result:

ok 20 tokens

Test #11:

score: -100
Time Limit Exceeded

input:

500000

output:


result: