QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#487240#9120. Huge Segment TreeXY_ElevenTL 22ms45708kbC++236.5kb2024-07-22 19:09:082024-07-22 19:09:08

Judging History

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

  • [2024-07-22 19:09:08]
  • 评测
  • 测评结果:TL
  • 用时:22ms
  • 内存:45708kb
  • [2024-07-22 19:09:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define pii pair<int,int> 
#define pli pair<LL,int> 
#define vct vector 
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 __xx00__
#define y1 __yy11__
#define ffo fflush(stdout)
cLL mod=998244353,G=404;
// cLL mod[2]={1686688681ll,1888686661ll},base[2]={166686661ll,188868881ll};
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; } template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; } template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; } template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_) { if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; } LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); } void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); } template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
template <typename Type> Type bk(vector <Type> &V_) { auto T_=V_.back(); V_.pop_back(); return T_; } template <typename Type> Type tp(stack <Type> &V_) { auto T_=V_.top(); V_.pop(); return T_; } template <typename Type> Type frt(queue <Type> &V_) { auto T_=V_.front(); V_.pop(); return T_; }
template <typename Type> Type bg(set <Type> &V_) { auto T_=*V_.begin(); V_.erase(V_.begin()); return T_; } template <typename Type> Type bk(set <Type> &V_) { auto T_=*prev(V_.end()); V_.erase(*prev(V_.end())); return T_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
cint H=21,L=1<<H|11,UP=14;
vct <LL> z[H+1];
void main_init()
{
    For(i,0,H)
    {
        LL s=1ll,t=pw(G,(mod-1ll)>>i);
        For_(j,0,1<<i) z[i].pb(s),mul(s,t);
    }
}
int rev[L];
int minsz(int w)
{
    return (__lg(w)+(w!=(w&-w)));
}
struct Poly
{
    vct <LL> v;
    void NTT(bool opt)
    {
        int d=minsz(sz(v)),l=1<<d;
        v.resize(l);
        For_(i,1,l)
        {
            rev[i]=(rev[i>>1]>>1)|((i&1)<<d-1);
            if(i<rev[i]) swap(v[i],v[rev[i]]);
        }
        For_(k,0,d)
        {
            for(int i=0;i<l;i+=(1<<k+1))
            For_(j,i,i|(1<<k))
            {
                int j2=(j|(1<<k));
                // printf("%d,%d\n",sz(z[k+1]),(i^j));
                // assert(sz(z[k+1])>(i^j));
                LL t=v[j2]*z[k+1][(i^j)]%mod;
                v[j2]=v[j]-t;
                v[j]+=t;
            }
            if(k==UP) for(auto &i:v) i=md(i);
        }
        if(d!=UP+1) for(auto &i:v) i=md(i);
        ret(!opt);
        LL t=inv(1ll*l);
        for(auto &i:v) mul(i,t);
        reverse(v.begin()+1,v.end());
    }
    void Mul(Poly &A)
    {
        int n=sz(v)+sz(A.v)-1,l=(1<<minsz(n));
        v.resize(l); NTT(false);
        A.v.resize(l); A.NTT(false);
        For_(i,0,l) mul(v[i],A.v[i]);
        // return ;
        NTT(true);
        v.resize(n);
    }
    void Mul2()
    {
        int n=sz(v)*2-1,l=(1<<minsz(n));
        v.resize(l); NTT(false);
        For_(i,0,l) mul(v[i],v[i]);
        NTT(true);
        v.resize(n);
    }
};
void Inv(Poly &C,int n)
{
    int m=1; C.v.resize(n<<2);
    Poly x={{inv(C.v[0])}};
    while(m<=(n<<1))
    {
        m<<=1;
        Poly x2=x,C2={{}};
        For_(i,0,m) C2.v.pb(C.v[i]);
        x.Mul(C2);
        for(auto &i:x.v) i=(i?(mod-i):0ll);
        add(x.v[0],2ll);
        x.Mul(x2);
        x.v.resize(m);
    }
    x.v.resize(n);
    C=x;
}
int fun(int l,int r,int L,int R)
{
    if(L<=l&&r<=R) return 1;
    int mid=l+r>>1,cnt=0;
    if(L<=mid) cnt+=fun(l,mid,L,R);
    if(R>mid) cnt+=fun(mid+1,r,L,R);
    return cnt;
}
void pw(Poly &x,int w,int m)
{
    Poly s={{1ll}};
    x.v.resize(m),s.v.resize(m);
    while(w)
    {
        if(w&1)
        {
            // for(auto i:x.v) printf("%lld ",i); printf("\n");
            Poly x2=x;
            s.Mul(x2); s.v.resize(m);
        }
        w>>=1;
        x.Mul2(); x.v.resize(m);
    }
    x=s;
}
cint N=5.01e5;
int h[N];
LL ans[N];
void main_solve()
{
    int n,m;
    inint(n); m=n<<1;
    Poly w,w2;
    LL iv2=inv(2ll);
    w={{iv2,1ll,iv2}};
    pw(w,n,m); add(w.v[0],-1ll);
    for(auto &i:w.v) mul(i,2ll);
    w2={{mod-1ll,2ll,1ll}};
    Inv(w2,m);
    w.Mul(w2);
    For_(i,0,m) add(ans[i],w.v[i]);
    w={{iv2,iv2}};
    pw(w,n,m); add(w.v[0],-1ll);
    for(auto &i:w.v) mul(i,4ll);
    For_(i,0,m) add(ans[i],w.v[i]);
    LL t=pw(2ll,1ll*(n-1));
    For(i,0,m) mul(ans[i],t);
    t=md(t*2ll-1ll);
    add(ans[2],t-1ll-t+1ll),add(ans[1],-2ll*t+t+1ll+t),add(ans[0],t);
    For_(i,1,m-1) outll2_(ans[i],i,m-2);
}
int main()
{
    // ios::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    // srand(time(NULL));
    main_init();
    // int _; inint(_); For(__,1,_) // T>1 ?
        // printf("\n------------\n\n"),
        main_solve();
    return 0;
}
/*

*/

详细

Test #1:

score: 100
Accepted
time: 12ms
memory: 44848kb

input:

2

output:

7 3

result:

ok 2 tokens

Test #2:

score: 0
Accepted
time: 19ms
memory: 45580kb

input:

3

output:

15 14 6 1

result:

ok 4 tokens

Test #3:

score: 0
Accepted
time: 18ms
memory: 44600kb

input:

4

output:

31 43 36 19 6 1

result:

ok 6 tokens

Test #4:

score: 0
Accepted
time: 21ms
memory: 45404kb

input:

5

output:

63 110 132 114 70 30 8 1

result:

ok 8 tokens

Test #5:

score: 0
Accepted
time: 22ms
memory: 45708kb

input:

6

output:

127 255 384 448 400 272 136 47 10 1

result:

ok 10 tokens

Test #6:

score: 0
Accepted
time: 12ms
memory: 45420kb

input:

7

output:

255 558 978 1401 1610 1478 1066 589 240 68 12 1

result:

ok 12 tokens

Test #7:

score: 0
Accepted
time: 18ms
memory: 44784kb

input:

8

output:

511 1179 2292 3803 5250 5987 5576 4183 2482 1137 388 93 14 1

result:

ok 14 tokens

Test #8:

score: 0
Accepted
time: 22ms
memory: 45248kb

input:

9

output:

1023 2438 5088 9398 14896 20038 22632 21250 16406 10282 5144 2006 588 122 16 1

result:

ok 16 tokens

Test #9:

score: 0
Accepted
time: 16ms
memory: 44892kb

input:

10

output:

2047 4975 10896 21772 38360 58724 77184 86312 81448 64324 42112 22576 9744 3304 848 155 18 1

result:

ok 18 tokens

Test #10:

score: 0
Accepted
time: 20ms
memory: 45564kb

input:

11

output:

4095 10070 22782 48209 92140 156292 232068 298744 330926 313422 252186 171122 97008 45368 17200 5155 1176 192 20 1

result:

ok 20 tokens

Test #11:

score: -100
Time Limit Exceeded

input:

500000

output:


result: