QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#203389#4646. Photosyiyiyi#AC ✓238ms5176kbC++141.7kb2023-10-06 17:07:482023-10-06 17:07:49

Judging History

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

  • [2023-10-06 17:07:49]
  • 评测
  • 测评结果:AC
  • 用时:238ms
  • 内存:5176kb
  • [2023-10-06 17:07:48]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define re register
#define N 120203
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int mod=998244353;
struct node{
	int a[3][3],n,m;
	void init(int x,int nn,int mm){
		n=nn,m=mm;
		for (int i=1;i<=n;++i)
			for (int j=1;j<=m;++j)
				a[i][j]=x?i==j:0;
	}
	friend node operator *(node a,node b){
		node res;res.init(0,a.n,b.m);
		for (int i=1;i<=a.n;++i)
			for (int j=1;j<=b.m;++j)
				for (int k=1;k<=b.n;++k)
					res.a[i][j]=(res.a[i][j]+1ll*a.a[i][k]*b.a[k][j])%mod;
		return res;
	}
	friend node operator ^(node x,int p){
		node res;res.init(1,x.n,x.m);
		for (;p;x=x*x,p>>=1)if (p&1)res=res*x;
		return res;
	}
}x,y,z;
inline int read(){
    int x=0,w=0;char ch=getchar();
    while (!isdigit(ch))w|=ch=='-',ch=getchar();
    while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
    return w?-x:x;
}
pii a[N],b[N];
void solve(){
	int n=read(),m=read(),k=0;
	for (int i=1;i<=m;++i){
		int x=read(),y=read();
		a[i]={min(x,y),max(x,y)};
	}
	sort(a+1,a+1+m);
	for (int i=1;i<=m;++i)
		if (a[i].fi>b[k].se)
			b[++k]={a[i].fi,a[i].se};
		else b[k].se=max(b[k].se,a[i].se);
	x.init(0,1,2);
	x.a[1][1]=1;
	x.a[1][2]=1;
	y.init(0,2,2);
	y.a[1][1]=0,y.a[1][2]=-1;
	y.a[2][1]=1,y.a[2][2]=3;
	z.init(0,2,2);
	z.a[1][1]=0,z.a[1][2]=-1;
	z.a[2][1]=0,z.a[2][2]=2;
	for (int i=1;i<=k;++i){
		if (i>1)assert(b[i].fi>b[i-1].se);
		x=x*(y^(b[i].fi-b[i-1].se-1));
		x=x*z;//cout<<k<<"!"<<endl;
	}
	x=x*(y^(n-b[k].se));
	cout<<(x.a[1][2]+mod)%mod<<endl;
}
signed main(){
	int T=read();
	while (T--)solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 238ms
memory: 5176kb

input:

1408
999999987 100000
793040645 793040645
405719679 405719686
109446201 109446201
966244831 966244831
649934379 649934388
270235074 270235080
475603749 475603754
517746359 517746359
692479018 692479026
620056281 620056289
479316573 479316580
99301874 99301874
197649180 197649188
266341447 266341449
...

output:

991600316
319234130
93841910
206794274
263051780
82690092
131084460
239778094
709347248
326810262
294182113
972258718
740886273
876778123
908531500
401101074
43928585
129509578
494010178
667853498
702904367
522176720
720297418
956798992
931058784
227927814
489184304
815395422
760542660
383948722
138...

result:

ok 1408 lines