QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#252520 | #7620. Yet Another Subsequence Problem | do_while_true | WA | 1ms | 3616kb | C++14 | 2.8kb | 2023-11-15 20:30:56 | 2023-11-15 20:30:56 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef __int128 i128;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=998244353;
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
int s=1;
while(y){
if(y&1)s=1ll*s*x%mod;
x=1ll*x*x%mod;
y>>=1;
}
return s;
}
struct ele{
int a[3][3];
void mem(){memset(a,0,sizeof(a));}
ele operator*(const ele y){
ele z;z.mem();
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
for(int k=0;k<3;k++)
cadd(z.a[i][k],1ll*a[i][j]*y.a[j][k]%mod);
return z;
}
}I({1,0,0,0,1,0,0,0,1});
ele qpow(ele x,ll y){
ele s=I;
while(y){
if(y&1)s=s*x;
x=x*x;
y>>=1;
}
return s;
}
ele solve(ll n,ll a,ll b,ll c,ele U,ele R){
if(n<=0)return I;
if(a>=c)return solve(n,a%c,b,c,U,qpow(U,a/c)*R);
ll m=((i128)a*n+b)/c;
if(!m)return qpow(R,n);
return qpow(R,(c-b-1)/a)*U*solve(m-1,c,(c-b-1)%a,a,R,U)*qpow(R,n-(c*m-b-1)/a);
}
void solve(){
i128 a,b;
read(a,b);
ele U({1,0,0,1,1,0,1,0,1});
ele R({1,1,0,0,1,0,0,1,1});
ele IU({1,0,0,998244352,1,0,998244352,0,1});
ele IR({1,998244352,0,0,1,0,0,998244352,1});
ele ans=U*R*solve(b,a,0,b,U,R)*IR*IU;
cout<<add(1,add(ans.a[2][0],ans.a[2][1]))<<'\n';
}
signed main(){
#ifdef do_while_true
assert(freopen("data.in","r",stdin));
// assert(freopen("data.out","w",stdout));
#endif
int T;read(T);
while(T--)solve();
#ifdef do_while_true
// cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
6 1 1 3 5 4 7 8 20 4 10 27 21
output:
4 70 264 196417 609 667131122
result:
ok 6 numbers
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3616kb
input:
18 5 9 23 30 820 483 5739 9232 86494 55350 606 13336 2768848 1124639 47995594 66053082 1069395 7177 7801842511 4390103762 47882886553 82678306054 193410894 6189355686 51594638 19992922190 59 110 422735115778072 658356435030265 9125338158530266 5328357177709583 60743352262021049 95595862538791630 629...
output:
988 220693002 133474535 202371605 778839228 282057418 935955056 943144752 409056617 56554322 50289129 917438628 24364208 109943645 685294134 739713840 284989796 764213847
result:
wrong answer 10th numbers differ - expected: '627433544', found: '56554322'