QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#312181 | #8010. Hierarchies of Judges | kkio | WA | 12ms | 18244kb | C++17 | 15.7kb | 2024-01-23 16:02:41 | 2024-01-23 16:02:41 |
Judging History
answer
#include <bits/stdc++.h>
//#define Kachang 1
#ifdef Kachang
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize("Ofast","unroll-loops","inline","no-stack-protector")
#else
#pragma GCC optmize("2")
#endif
using namespace std;
namespace Def{
#define fir first
#define sec second
#define lson(i) (tr[i].ls)
#define rson(i) (tr[i].rs)
#define FIO(file) freopen(file".in","r",stdin), freopen(file".out","w",stdout)
#define Untie() ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef __int128_t i128;
typedef __uint128_t u128;
}
using namespace Def;
namespace FastIO {
struct IO {
char ibuf[(1 << 20) + 1], *iS, *iT, obuf[(1 << 20) + 1], *oS;
IO() : iS(ibuf), iT(ibuf), oS(obuf) {} ~IO() { fwrite(obuf, 1, oS - obuf, stdout); }
#if ONLINE_JUDGE
#define gh() (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), (iS == iT ? EOF : *iS++) : *iS++)
#else
#define gh() getchar()
#endif
inline bool eof (const char &ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == EOF; }
inline long long read() {
char ch = gh();
long long x = 0;
bool t = 0;
while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gh();
return t ? ~(x - 1) : x;
}
inline void read (char *s) {
char ch = gh(); int l = 0;
while (eof(ch)) ch = gh();
while (!eof(ch)) s[l++] = ch, ch = gh();
s[l] = 0;
}
inline void read (double &x) {
char ch = gh(); bool t = 0;
while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = gh();
if (ch != '.') return t && (x = -x), void(); ch = gh();
for (double cf = 0.1; '0' <= ch && ch <= '9'; ch = gh(), cf *= 0.1) x += cf * (ch ^ 48);
t && (x = -x);
}
inline void pc (char ch) {
#ifdef ONLINE_JUDGE
if (oS == obuf + (1 << 20) + 1) fwrite(obuf, 1, oS - obuf, stdout), oS = obuf;
*oS++ = ch;
#else
putchar(ch);
#endif
}
inline void write (char *s)
{
int len = strlen(s);
for(int i = 0; i < len; i++)pc(s[i]);
}
template<typename _Tp>
inline void write (_Tp x) {
static char stk[64], *tp = stk;
if (x < 0) x = ~(x - 1), pc('-');
do *tp++ = x % 10, x /= 10;
while (x);
while (tp != stk) pc((*--tp) | 48);
}
inline void puts(const char *s){
int len = strlen(s);
for (int i = 0; i < len; i++)pc(s[i]);
}
} io;
inline long long read () { return io.read(); }
template<typename Tp>
inline void read (Tp &x) { io.read(x); }
template<typename _Tp>
inline void write (_Tp x) { io.write(x); }
}
using namespace FastIO;
namespace misc{
constexpr int infi=1e9;
constexpr int minfi=0x3f3f3f3f;
constexpr ll infl=1e18;
constexpr ll minfl=0x3f3f3f3f3f3f3f3f;
constexpr int MOD=998244353;
constexpr int inv2=(MOD+1)/2;
constexpr int inv3=(MOD+1)/3;
constexpr double eps=1e-6;
mt19937_64 rnd(0x3408532);
template<typename T,typename E>
inline T ksm(T b,E p){T ret=1;while(p){if(p&1)ret=1ll*ret*b%MOD;b=1ll*b*b%MOD;p>>=1;}return ret;}
template<typename T,typename E,typename R>
inline T ksm(T b,E p,R mod){T ret=1;while(p){if(p&1)ret=1ll*ret*b%mod;b=1ll*b*b%mod;p>>=1;}return ret;}
template<typename T>
inline T ginv(T v){return ksm(v,MOD-2);}
template<typename T,typename E>
inline void cmax(T &a,E b){a<b?(a=b,1):0;}
template<typename T,typename E>
inline void cmin(T &a,E b){a>b?(a=b,1):0;}
template<typename T,typename E>
inline void cadd(T &a,E b){(a+=b)>=MOD?(a-=MOD):0;}
template<typename T,typename E>
inline void csub(T &a,E b){(a-=b)<0?(a+=MOD):0;}
template<typename T,typename E>
inline void cmul(T &a,E b){a=(ll)a*b%MOD;}
template<typename T,typename E>
inline T madd(T a,E b){return (a+=b)>=MOD?(a-MOD):a;}
template<typename T,typename E>
inline T msub(T a,E b){return (a-=b)<0?(a+MOD):a;}
template<typename T,typename E>
inline T mmul(T a,E b){return (ll)a*b%MOD;}
template<typename T>
struct dseg{T *first,*last;dseg(T* _l,T* _r):first(_l),last(_r){}};
inline void debug(void){cerr<<'\n';}
template<typename T,typename... arg>
inline void debug(dseg<T> A,arg... v){cerr<<"[ ";for(T* i=A.first;i!=A.last;++i)cerr<<*i<<' ';cerr<<"] ";debug(v...);}
template<typename T,typename... arg>
inline void debug(T x,arg... r){cerr<<x<<' ';debug(r...);}
template<typename T>
inline T randseg(T l,T r){assert(l<=r);return rnd()%(r-l+1)+l;}
template<typename T>
inline bool gbit(T v,int bit){return v>>bit&1;}
template<typename T>
inline void FWTXor(T *a,int n){for(int i=2;i<=n;i<<=1)for(int p=i>>1,j=0;j<n;j+=i)for(int k=j;k<j+p;k++){T x=a[k],y=a[k+p];a[k]=madd(x,y),a[k+p]=msub(x,y);}}
template<typename T>
inline void iFWTXor(T *a,int n){for(int i=2;i<=n;i<<=1)for(int p=i>>1,j=0;j<n;j+=i)for(int k=j;k<j+p;k++){T x=a[k],y=a[k+p];a[k]=mmul(madd(x,y),inv2),a[k+p]=mmul(msub(x,y),inv2);}}
int timest=0;
inline void record(){timest=clock()*1000/CLOCKS_PER_SEC;}
inline int timegap(){int nowtime=clock()*1000/CLOCKS_PER_SEC;return nowtime-timest;}
inline ll gcd(ll a,ll b){if(!b||!a) return a+b;ll az=__builtin_ctz(a),bz=__builtin_ctz(b),z=(az>bz)?bz:az,t;b>>=bz;while(a) a>>=az,t=a-b,az=__builtin_ctz(t),b=a<b?a:b,a=t<0?-t:t;return b<<z;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1,y=0;return a;}ll g=exgcd(b,a%b,y,x);y-=x*(a/b);return g;}
inline ll Sum1(ll n){return n*(n+1)/2;}
inline ll Sum2(ll n){return n*(n+1)*(2*n+1)/6;}
inline ll Sqr(ll n){return n*n;}
#define binom(n,m) ((n)<0||(m)<0||(n)<(m)?0:1ll*fac[(n)]*ifac[(m)]%mod*ifac[(n)-(m)]%mod)
#define likely(x) (__builtin_expect(!!(x),1))
#define unlikely(x) (__builtin_expect(!!(x),0))
}
using namespace misc;
namespace Barret
{
class reduction
{
private:
__uint128_t brt;
int mod;
public:
reduction(){};
reduction(int __mod):brt(((__uint128_t)1<<64)/__mod),mod(__mod){}
inline void setmod(int __mod){brt=((__uint128_t)1<<64)/__mod,mod=__mod;}
template<typename T> inline void fix(T& val){val-=mod*(brt*val>>64);while(val>=mod)val-=mod;}
template<typename T> inline int fixv(T val){val-=mod*(brt*val>>64);return val>=mod?val-mod:val;}
};
}
using namespace Barret;
namespace ZPoly
{
using LL=long long;
constexpr int MOD=998244353,G=114514,MAXN=1<<21;
inline int qpow(LL a,LL b) { int r=1;for(;b;(b&1)?r=r*a%MOD:0,a=a*a%MOD,b>>=1);return r; }
inline int madd(int x) { return x; }
inline int mmul(int x) { return x; }
inline int msub(int x,int y) { return (x-=y)<0?x+=MOD:x; }
inline int mdiv(int x,int y) { return (LL)x*qpow(y,MOD-2)%MOD; }
template<typename ...Args>inline int madd(int x,Args ...y) { return (x+=madd(y...))>=MOD?x-=MOD:x; }
template<typename ...Args>inline int mmul(int x,Args ...y) { return (LL)x*mmul(y...)%MOD; }
class Polynomial
{
private:
static constexpr int NTT_LIM=180;
static int g[MAXN+5],c1[MAXN+5],c2[MAXN+5];
int deg;
vector<int> c;
public:
static void init()
{
for(int i=2,gn;i<=MAXN;i<<=1)
{
g[i>>1]=1,gn=qpow(G,(MOD-1)/i);
for(int j=(i>>1)+1;j<i;j++) g[j]=mmul(g[j-1],gn);
}
}
static void DIT(int *a,int len)
{
for(int i=len>>1;i;i>>=1)
for(int j=0;j<len;j+=i<<1)
for(int k=0,x,y;k<i;k++)
x=a[j+k],y=a[i+j+k],a[j+k]=madd(x,y),a[i+j+k]=mmul(g[i+k],msub(x,y));
}
static void DIF(int *a,int len)
{
for(int i=1;i<len;i<<=1)
for(int j=0;j<len;j+=i<<1)
for(int k=0,x,y;k<i;k++)
x=a[j+k],y=mmul(g[i+k],a[i+j+k]),a[j+k]=madd(x,y),a[i+j+k]=msub(x,y);
int x=qpow(len,MOD-2);
for(int i=0;i<len;i++) a[i]=mmul(a[i],x);
reverse(a+1,a+len);
}
private:
static void __polyinv(const int *a,int *b,int len)
{
if(len==1) return b[0]=qpow(a[0],MOD-2),void();
__polyinv(a,b,(len+1)>>1);
int nn=1<<(__lg((len<<1)-1)+1);
memcpy(c1,a,len<<2);
memset(b+len,0,(nn-len)<<2);
memset(c1+len,0,(nn-len)<<2);
DIT(b,nn),DIT(c1,nn);
for(int i=0;i<nn;i++) b[i]=mmul(b[i],msub(2,mmul(b[i],c1[i])));
DIF(b,nn),memset(b+len,0,(nn-len)<<2);
}
static void __polyln(const int *a,int *b,int len)
{
__polyinv(a,b,len);
for(int i=1;i<len;i++) c1[i-1]=mmul(i,a[i]);
int nn=1<<(__lg((len<<1)-1)+1);
memset(b+len,0,(nn-len)<<2);
memset(c1+len,0,(nn-len)<<2);
DIT(b,nn),DIT(c1,nn);
for(int i=0;i<nn;i++) b[i]=mmul(b[i],c1[i]);
DIF(b,nn),memset(b+len,0,(nn-len)<<2);
for(int i=len-1;i>0;i--) b[i]=mdiv(b[i-1],i);
b[0]=0;
}
static void __polyexp(const int *a,int *b,int l,int r)
{
if(l==r-1) return b[l]=(l?mdiv(b[l],l):1),void();
int len=r-l,mid=(l+r)>>1;
__polyexp(a,b,l,mid);
for(int i=0;i<len;i++) c1[i]=a[i];
memcpy(c2,b+l,(mid-l)<<2);
memset(c2+mid-l,0,(r-mid)<<2);
if(len<=NTT_LIM) for(int i=len-1;i>=0;i--)
{
c1[i]=mmul(c1[i],c2[0]);
for(int j=0;j<i;j++) c1[i]=madd(c1[i],mmul(c1[j],c2[i-j]));
}
else
{
DIT(c1,len),DIT(c2,len);
for(int i=0;i<len;i++) c1[i]=mmul(c1[i],c2[i]);
DIF(c1,len);
}
for(int i=mid;i<r;i++) b[i]=madd(b[i],c1[i-l]);
__polyexp(a,b,mid,r);
}
public:
Polynomial(): deg(1),c(1){}
Polynomial(const Polynomial &p): deg(p.deg),c(p.c){}
Polynomial(Polynomial &&p): deg(p.deg),c(move(p.c)){}
explicit Polynomial(int d): deg(d),c(d){}
explicit Polynomial(const vector<int> &v): deg(v.size()),c(v){}
explicit Polynomial(const initializer_list<int> &l): deg(l.size()),c(l){}
inline int &operator [](int i) { return c[i]; }
inline int operator [](int i)const { return c[i]; }
inline int degree()const { return deg; }
inline void resize(int d) { c.resize(deg=d); }
inline Polynomial &operator +=(const Polynomial &p)
{
if(deg<p.deg) resize(p.deg);
for(int i=0;i<deg;i++) c[i]=madd(c[i],p[i]);
return *this;
}
inline Polynomial &operator -=(const Polynomial &p)
{
if(deg<p.deg) resize(p.deg);
for(int i=0;i<deg;i++) c[i]=msub(c[i],p[i]);
return *this;
}
inline Polynomial &operator *=(const Polynomial &p)
{
int n=deg,m=p.deg;resize(n+m-1);
if(n+m<NTT_LIM)
{
memcpy(c1,c.data(),n<<2);
memset(c2,0,(n+m-1)<<2);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
c2[i+j]=madd(c2[i+j],mmul(c1[i],p[j]));
memcpy(c.data(),c2,(n+m-1)<<2);
}
else
{
int nn=1<<(__lg(n+m-1)+1);
memcpy(c1,c.data(),n<<2),memcpy(c2,p.c.data(),m<<2);
memset(c1+n,0,(nn-n)<<2),memset(c2+m,0,(nn-m)<<2);
DIT(c1,nn),DIT(c2,nn);
for(int i=0;i<nn;i++) c1[i]=mmul(c1[i],c2[i]);
DIF(c1,nn),memcpy(c.data(),c1,deg<<2);
}
return *this;
}
friend inline Polynomial derivative(const Polynomial &p)
{
Polynomial q(p.deg-1);
for(int i=1;i<p.deg;i++) q[i-1]=mmul(p[i],i);
return q;
}
friend inline Polynomial integral(const Polynomial &p)
{
Polynomial q(p.deg+1);
for(int i=1;i<p.deg;i++) q[i+1]=mdiv(p[i],i+1);
return q;
}
inline Polynomial inv()const
{
if(c[0]==0) cerr<<"[x^0]f(x)=0, f(x)^-1 doesn't exist.\n",abort();
int nn=1<<(__lg((deg<<1)-1)+1);
Polynomial q(nn);
__polyinv(c.data(),q.c.data(),deg);
return q.resize(deg),q;
}
friend inline Polynomial ln(const Polynomial &p)
{
if(p[0]!=1) cerr<<"[x^0]f(x)!=1, ln(f(x)) doesn't exist.\n",abort();
int nn=1<<(__lg((p.deg<<1)-1)+1);
Polynomial q(nn);
__polyln(p.c.data(),q.c.data(),p.deg);
return q.resize(p.deg),q;
}
friend inline Polynomial exp(const Polynomial &p)
{
if(p[0]!=0) cerr<<"[x^0]f(x)!=0, exp(f(x)) doesn't exist.\n",abort();
static int c[MAXN];
int nn=1<<(__lg(p.deg-1)+1);
for(int i=0;i<p.deg;i++) c[i]=mmul(i,p[i]);
Polynomial q(nn);
__polyexp(c,q.c.data(),0,nn);
return q.resize(p.deg),q;
}
friend inline pair<Polynomial,Polynomial> div(const Polynomial &f,const Polynomial &g)
{
if(f.deg<g.deg) return make_pair(Polynomial{0},f);
int n=f.deg-1,m=g.deg-1;
Polynomial fr(n+1),gr(m+1);
for(int i=0;i<=n;i++) fr[i]=f[n-i];
for(int i=0;i<=m;i++) gr[i]=g[m-i];
fr.resize(n-m+1),gr.resize(n-m+1),fr*=gr.inv();
fr.resize(n-m+1),reverse(fr.c.begin(),fr.c.end());
gr=f-fr*g,gr.resize(m);
return make_pair(fr,gr);
}
inline Polynomial &operator =(const Polynomial &p)
{ return deg=p.deg,c=p.c,*this; }
inline Polynomial &operator =(Polynomial &&p)
{ return deg=p.deg,c=move(p.c),*this; }
inline Polynomial &operator *=(int k)
{ for(auto &i: c) i=mmul(i,k);return *this; }
inline Polynomial &operator /=(const Polynomial &rhs)
{ return (*this)*=rhs.inv(); }
inline Polynomial &operator %=(const Polynomial &rhs)
{ return (*this)=div(*this,rhs).second; }
inline Polynomial operator +(const Polynomial &rhs)const
{ return Polynomial(*this)+=rhs; }
inline Polynomial operator -(const Polynomial &rhs)const
{ return Polynomial(*this)-=rhs; }
inline Polynomial operator *(const Polynomial &rhs)const
{ return Polynomial(*this)*=rhs; }
inline Polynomial operator /(const Polynomial &rhs)const
{ return Polynomial(*this)/=rhs; }
inline Polynomial operator %(const Polynomial &rhs)const
{ return div(*this,rhs).second; }
friend inline Polynomial operator *(const Polynomial &p,int k)
{ return Polynomial(p)*=k; }
friend inline Polynomial operator *(int k,const Polynomial &p)
{ return Polynomial(p)*=k; }
};
int Polynomial::g[]={},Polynomial::c1[]={},Polynomial::c2[]={};
}
const int mod=998244353;
using Poly=ZPoly::Polynomial;
Poly x1({0,1}),x0({1});
Poly G0(Poly F0,Poly F1,Poly e01,Poly e1)
{return x1*(e01-e1)-F0*F0+F0;}
Poly G1(Poly F0,Poly F1,Poly e01,Poly e1)
{return x1*(F0*F0*e01-e1)-F0*F1+F1;}
Poly dr00(Poly F0,Poly F1,Poly e01,Poly e1)
{return x1*F1*e01-F0*2+x0;}
Poly dr01(Poly F0,Poly F1,Poly e01,Poly e1)
{return x1*(F0*e01-e1);}
Poly dr10(Poly F0,Poly F1,Poly e01,Poly e1)
{return x1*(2*F0*e01+F0*F0*F1*e01)-F1;}
Poly dr11(Poly F0,Poly F1,Poly e01,Poly e1)
{return x1*(F0*F0*F0*e01-e1)-F0+x0;}
void print(Poly A)
{
for(int i=0;i<A.degree();i++)cout<<(1ll*A[i]%mod+mod)%mod<<' ';
cout<<'\n';
}
pair<Poly,Poly> newton(int n)
{
if(n==1)return {Poly({0}),Poly({0})};
int m=(n+1)/2;
Poly F0,F1;
tie(F0,F1)=newton(m);F0.resize(n);F1.resize(n);
x0.resize(n);x1.resize(n);
Poly e01=exp(F0*F1);e01.resize(n);
Poly e1=exp(F1);e1.resize(n);
Poly d00=dr00(F0,F1,e01,e1),d01=dr01(F0,F1,e01,e1),d10=dr10(F0,F1,e01,e1),d11=dr11(F0,F1,e01,e1);
Poly g0=G0(F0,F1,e01,e1),g1=G1(F0,F1,e01,e1);
d00.resize(n);d01.resize(n);d11.resize(n);d10.resize(n);g0.resize(n);g1.resize(n);
Poly det=d00*d11-d01*d10;
det.resize(n);
Poly invd=(det).inv();
invd.resize(n);
Poly nxtF0=F0-(g0*d11-g1*d01)*invd;
Poly nxtF1=F1-(g1*d00-g0*d10)*invd;
nxtF0.resize(n),nxtF1.resize(n);
return {nxtF0,nxtF1};
}
int main()
{
Poly::init();
Poly F0,F1;
int n;
cin>>n;
tie(F0,F1)=newton(n+1);
int sum=(F0[n]+F1[n])%mod;
sum=(sum+mod)%mod;
for(int i=1;i<=n;i++)cmul(sum,i);
cout<<sum<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 17980kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 7ms
memory: 18244kb
input:
3
output:
24
result:
ok 1 number(s): "24"
Test #3:
score: 0
Accepted
time: 9ms
memory: 17924kb
input:
5
output:
3190
result:
ok 1 number(s): "3190"
Test #4:
score: -100
Wrong Answer
time: 12ms
memory: 18032kb
input:
100
output:
13969868
result:
wrong answer 1st numbers differ - expected: '413875584', found: '13969868'