QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#443429 | #6960. Make 2 | Acoipp | AC ✓ | 23ms | 5760kb | C++14 | 2.0kb | 2024-06-15 15:32:35 | 2024-06-15 15:32:36 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define N 105
using namespace std;
inline char nc(){
static char buf[1000000],*p=buf,*q=buf;
return p==q&&(q=(p=buf)+fread(buf,1,1000000,stdin),p==q)?EOF:*p++;
}
inline ll read(){
ll res = 0;
char c = nc();
while(c<'0'||c>'9')c=nc();
while(c<='9'&&c>='0')res=res*10+c-'0',c=nc();
return res;
}
char obuf[1<<21],*p3=obuf;
inline void pc(char c){
p3-obuf<=(1<<20)?(*p3++=c):(fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=c);
}
inline void write(ll x){
if(x<0) pc('-'),x=-x;
if(x>9) write(x/10);
pc(x%10+'0');
}
struct node{ll x,y;}p[N];
ll T,n,m,i,a[6][6],b[6][6],t[6][6],g[6][6],las;
inline void times(ll a[6][6],ll b[6][6],ll n1,ll n2,ll n3){
for(ll i=0;i<=n1;i++){
for(ll j=0;j<=n3;j++){
for(ll k=0;k<=n2;k++) t[i][j]=(t[i][j]+a[i][k]*b[k][j])%mod;
}
}
for(ll i=0;i<=n1;i++) for(ll j=0;j<=n3;j++) a[i][j]=t[i][j],t[i][j]=0;
}
inline void calc(ll pos){
for(ll i=0;i<=5;i++) for(ll j=0;j<=5;j++) g[i][j]=b[i][j];
while(pos){
if(pos&1) times(a,g,0,5,5);
times(g,g,5,5,5);
pos>>=1;
}
}
inline void solve(){
memset(a,0,sizeof(a));
n=read(),m=read();
for(i=1;i<=m;i++) p[i].x=read(),p[i].y=read();
a[0][0] = 1;
for(i=1,las=0;i<=m;i++){
calc(p[i].x-las-1),las=p[i].x;
if(p[i].y>=4||p[i].y==0) memset(a,0,sizeof(a));
else{
if(p[i].y==1){
t[0][1] += a[0][0],t[0][2] += a[0][1],t[0][4] += a[0][3],t[0][0] += a[0][4],t[0][5] += a[0][5];
}
else if(p[i].y==2){
t[0][0] += a[0][0],t[0][5] += a[0][1],t[0][4] += a[0][5],t[0][3] += a[0][2];
}
else{
t[0][4] += a[0][1];
}
a[0][0] = t[0][0]%mod,a[0][1] = t[0][1]%mod,a[0][2] = t[0][2]%mod,a[0][3] = t[0][3]%mod;
a[0][4] = t[0][4]%mod,a[0][5] = t[0][5]%mod;
memset(t,0,sizeof(t));
}
}
calc(n-las);
write(a[0][0]),pc('\n');
}
int main(){
b[0][0]++,b[0][1]++,b[1][5]++,b[1][2]++,b[1][4]++,b[2][3]++,b[3][4]++,b[5][4]++,b[5][5]++,b[4][0]++;
T=read();
while(T--) solve();
return fwrite(obuf,p3-obuf,1,stdout),0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 23ms
memory: 5760kb
input:
10 461852149215451876 100 2606377861630340 1 4900099439792445 2 8529469964880646 1 10971270259972783 2 15192703197468854 2 21935781810578068 3 29971403782119190 1 34501042417520226 3 40359003874545562 3 46480157006014501 2 52478331952908009 1 55428584949575246 3 62368645204551626 3 69112449621347466...
output:
577575014 614065891 304260321 891916472 0 382938711 27287182 0 11286050 939192368
result:
ok 10 lines