QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#728738#426. 传统艺能nullptr_qwq100 ✓778ms10644kbC++146.6kb2024-11-09 15:48:482024-11-09 15:48:49

Judging History

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

  • [2024-11-09 15:48:49]
  • 评测
  • 测评结果:100
  • 用时:778ms
  • 内存:10644kb
  • [2024-11-09 15:48:48]
  • 提交

answer

// Problem: P6630 [ZJOI2020] 传统艺能
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P6630
// Memory Limit: 512 MB
// Time Limit: 4000 ms
// Author: nullptr_qwq
// 
// Powered by CP Editor (https://cpeditor.org)

// 私は猫です

#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define inf 1000000000
#define infll 1000000000000000000ll
#define pii pair<int,int>
#define rep(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
#define per(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define dF(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define cmh(sjy) while(sjy--)
#define lowbit(x) (x&(-x))
#define HH printf("\n")
#define eb emplace_back
#define poly vector<int>
#define SZ(x) ((int)x.size())
using namespace std;
ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return x*f;
}
namespace Fastio{struct Reader{template<typename T>Reader&operator>>(T&x){x=0;short f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();x*=f;return*this;}Reader&operator>>(double&x){x=0;double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(long double&x){x=0;long double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(__float128&x){x=0;__float128 t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(char&c){c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();return*this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(string&str){str.clear();char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{const int Setprecision=6;typedef int mxdouble;template<typename T>Writer&operator<<(T x){if(x==0){putchar('0');return*this;}if(x<0)putchar('-'),x=-x;static short sta[40];short top=0;while(x>0)sta[++top]=x%10,x/=10;while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(long double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(long double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(__float128 x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(__float128)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(char c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}using namespace Fastio;
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<typename T>inline void chkmax(T &x,const T &y){ x=std::max(x,y); }
template<typename T>inline void chkmin(T &x,const T &y){ x=std::min(x,y); }
const int mod=998244353,maxn=500005;
inline int qpow(int x,ll y){
	int rt=1;
	for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) rt=1ll*rt*x%mod;
	return rt;
}
inline void inc(int &x,const int y){ x=(x+y>=mod)?(x+y-mod):(x+y); }
inline void dec(int &x,const int y){ x=(x>=y)?(x-y):(x+mod-y); }
inline void mul(int &x,const int y){ x=1ll*x*y%mod; }
inline int add(const int x,const int y){ return (x+y>=mod)?(x+y-mod):(x+y); }
inline int sub(const int x,const int y){ return (x>=y)?(x-y):(x+mod-y); }
inline int prod(const int x,const int y){ return 1ll*x*y%mod; }
int n,k,I;
struct mat{
	int a[3][3];
	void R(){ memset(a,0,sizeof a); }
	int *operator[](int x){ return a[x]; }
};
mat merge(mat x,mat y){
	mat res; res.R();
	F(i,0,2)F(j,0,2)inc(res[i][j],add(1ll*x[i][0]*y[0][j]%mod,add(1ll*x[i][1]*y[1][j]%mod,1ll*x[i][2]*y[2][j]%mod)));
	return res;
}
mat qpow(mat x,int y){
	mat res; res.R(),res[0][0]=res[1][1]=res[2][2]=1;
	for(;y;y>>=1,x=merge(x,x))if(y&1)res=merge(res,x);
	return res;
}
inline int S(int x){ return ((1ll*x*(x-1))>>1)%mod; }
struct seg{
	int x,y,p;
};
seg R(int l,int r){
	seg res;
	res.x=1ll*add(S(l),S(n-r+1))*I%mod;
	res.y=1ll*l*(n-r+1)%mod*I%mod;
	res.p=sub(1,add(res.x,res.y));
	return res;
}
int Solve(int l,int r,seg fa){
	seg o=R(l,r); mat q;
	int c1=fa.x,c2=fa.y,c3=sub(o.x,fa.x),c4=sub(o.y,fa.y),c5=sub(1,add(c1,add(c2,add(c3,c4))));
	q[0][0]=add(c1,add(c3,c5)),q[0][1]=q[0][2]=c5;
	q[1][0]=c4,q[1][1]=add(c1,add(c2,add(c3,c4))),q[1][2]=add(c3,c4);
	q[2][0]=c2,q[2][1]=0,q[2][2]=add(c1,c2);
	int res=qpow(q,k)[1][0];
	if(l==r)return res;
	int mid; cin>>mid;
	inc(res,Solve(l,mid,o)),inc(res,Solve(mid+1,r,o));
	return res;
}
void solve(){
	cin>>n>>k,I=qpow(S(n+1),mod-2);
	seg Root={0,0,1};
	cout<<Solve(1,n,Root);
}
signed main(){
	int zsy=1;
	F(____,1,zsy)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 0ms
memory: 3636kb

input:

10 4
3 2 1 8 6 5 4 7 9

output:

181617343

result:

ok 1 number(s): "181617343"

Test #2:

score: 10
Accepted
time: 0ms
memory: 3624kb

input:

10 91
9 8 5 3 1 2 4 6 7

output:

979294405

result:

ok 1 number(s): "979294405"

Test #3:

score: 10
Accepted
time: 0ms
memory: 3680kb

input:

5 985433385
4 1 3 2

output:

581616517

result:

ok 1 number(s): "581616517"

Test #4:

score: 10
Accepted
time: 48ms
memory: 10644kb

input:

194809 1
194807 3 2 1 12 9 8 4 5 7 6 10 11 14 13 22 21 19 16 15 18 17 20 194798 24 23 194795 194790 194785 27 26 25 31 28 29 30 40 34 33 32 39 38 36 35 37 48 46 45 44 43 41 42 47 194782 50 49 194778 194770 56 55 54 51 52 53 194764 194762 194753 194747 60 57 58 59 67 63 61 62 64 66 65 74 68 69 73 72 ...

output:

67027862

result:

ok 1 number(s): "67027862"

Test #5:

score: 10
Accepted
time: 1ms
memory: 3628kb

input:

32 946189239
16 8 4 2 1 3 6 5 7 12 10 9 11 14 13 15 24 20 18 17 19 22 21 23 28 26 25 27 30 29 31

output:

602568459

result:

ok 1 number(s): "602568459"

Test #6:

score: 10
Accepted
time: 1ms
memory: 3688kb

input:

64 927627601
32 16 8 4 2 1 3 6 5 7 12 10 9 11 14 13 15 24 20 18 17 19 22 21 23 28 26 25 27 30 29 31 48 40 36 34 33 35 38 37 39 44 42 41 43 46 45 47 56 52 50 49 51 54 53 55 60 58 57 59 62 61 63

output:

289230741

result:

ok 1 number(s): "289230741"

Test #7:

score: 10
Accepted
time: 16ms
memory: 3624kb

input:

4096 915714134
2048 1024 512 256 128 64 32 16 8 4 2 1 3 6 5 7 12 10 9 11 14 13 15 24 20 18 17 19 22 21 23 28 26 25 27 30 29 31 48 40 36 34 33 35 38 37 39 44 42 41 43 46 45 47 56 52 50 49 51 54 53 55 60 58 57 59 62 61 63 96 80 72 68 66 65 67 70 69 71 76 74 73 75 78 77 79 88 84 82 81 83 86 85 87 92 90...

output:

246047302

result:

ok 1 number(s): "246047302"

Test #8:

score: 10
Accepted
time: 19ms
memory: 3504kb

input:

4634 906063294
2144 1427 815 694 205 105 55 10 5 1 3 2 4 6 7 8 9 43 41 24 18 16 12 11 13 15 14 17 23 19 21 20 22 34 32 31 29 25 26 27 28 30 33 37 36 35 38 40 39 42 46 45 44 52 47 49 48 50 51 53 54 100 77 72 57 56 64 60 58 59 61 62 63 70 69 65 67 66 68 71 75 74 73 76 85 82 80 78 79 81 84 83 87 86 90 ...

output:

416904570

result:

ok 1 number(s): "416904570"

Test #9:

score: 10
Accepted
time: 352ms
memory: 6976kb

input:

95552 924470405
7 3 1 2 4 6 5 10 8 9 95547 16 11 15 14 12 13 95543 95533 25 24 23 19 17 18 22 21 20 27 26 95528 34 29 28 33 30 32 31 40 35 39 36 38 37 95519 47 44 41 43 42 45 46 95517 95514 56 49 48 55 54 53 52 50 51 59 57 58 64 60 62 61 63 95509 66 65 69 68 67 71 70 78 77 72 75 73 74 76 95504 82 81...

output:

778611049

result:

ok 1 number(s): "778611049"

Test #10:

score: 10
Accepted
time: 778ms
memory: 10412kb

input:

194473 918039998
194469 5 1 2 3 4 10 6 7 9 8 194466 19 12 11 17 13 16 15 14 18 194462 194457 194450 194445 194437 194428 194422 194420 194415 194413 194407 194405 194402 194400 23 21 20 22 194396 194393 194389 194382 31 24 30 29 28 27 26 25 194375 34 32 33 39 36 35 38 37 42 40 41 194372 45 43 44 194...

output:

128548459

result:

ok 1 number(s): "128548459"

Extra Test:

score: 0
Extra Test Passed