QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#487303#9120. Huge Segment TreeXY_ElevenWA 1396ms159024kbC++236.7kb2024-07-22 20:01:562024-07-22 20:01:56

Judging History

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

  • [2024-07-22 20:01:56]
  • 评测
  • 测评结果:WA
  • 用时:1396ms
  • 内存:159024kb
  • [2024-07-22 20:01:56]
  • 提交

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=22,L=1<<H|11,UP=14;
vct <LL> z[H+1];
LL z2[H+1];
void main_init()
{
    For(i,0,H)
    {
        z2[i]=inv(1ll<<i);
        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=z2[d];
        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);
    }
};
int hhh=0;
void Inv(Poly &C,int n)
{
    int ttt=clock();
    int m=1,n2=sz(C.v);
    Poly x={{inv(C.v[0])}};
    while(m<=n)
    {
        m<<=1;
        Poly x2=x,C2={{}};
        For_(i,0,min(m,n2)) C2.v.pb(C.v[i]);
        x.Mul(C2);
        x.v.resize(m);
        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;
    hhh+=clock()-ttt;
}
void pw(Poly &x,int w,int m)
{
    Poly s={{1ll}};
    while(w)
    {
        if(w&1)
        {
            // for(auto i:x.v) printf("%lld ",i); printf("\n");
            Poly x2=x;
            s.Mul(x2);
            if(sz(s.v)>m) s.v.resize(m);
        }
        w>>=1;
        x.Mul2();
        if(sz(x.v)>m) x.v.resize(m);
    }
    x=s;
}
cint N=5.01e5;
LL ans[N<<1],d1[N],d2[N];
void main_solve()
{
    int n,m;
    // n=500000; //E
    inint(n); //E
    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]);
    d1[0]=1ll; For(i,1,n) d1[i]=d1[i-1]*i%mod;
    d2[n]=inv(d1[n]); Rof(i,1,n) d2[i-1]=d2[i]*i%mod;
    LL t=pw(iv2,1ll*n);
    w.v.clear();
    For(i,0,n) w.v.pb(t*(d1[n]*(d2[i]*d2[n-i]%mod)%mod)%mod);
    For_(i,n+1,m) w.v.pb(0ll);
    add(w.v[0],-1ll);
    for(auto &i:w.v) mul(i,4ll);
    For_(i,0,m) add(ans[i],w.v[i]);
    t=pw(2ll,1ll*(n-1));
    For(i,0,m) mul(ans[i],t);
    add(ans[1],1ll),add(ans[0],t*2ll-1ll);
    For_(i,1,m-1) outll2_(ans[i],i,m-2); //E
    // outint(hhh); //E
    // outint(clock()); //E
}
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: 24ms
memory: 87048kb

input:

2

output:

7 3

result:

ok 2 tokens

Test #2:

score: 0
Accepted
time: 38ms
memory: 87088kb

input:

3

output:

15 14 6 1

result:

ok 4 tokens

Test #3:

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

input:

4

output:

31 43 36 19 6 1

result:

ok 6 tokens

Test #4:

score: 0
Accepted
time: 36ms
memory: 87184kb

input:

5

output:

63 110 132 114 70 30 8 1

result:

ok 8 tokens

Test #5:

score: 0
Accepted
time: 26ms
memory: 86968kb

input:

6

output:

127 255 384 448 400 272 136 47 10 1

result:

ok 10 tokens

Test #6:

score: 0
Accepted
time: 40ms
memory: 86956kb

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: 28ms
memory: 86900kb

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: 44ms
memory: 87080kb

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: 40ms
memory: 87136kb

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: 40ms
memory: 87276kb

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
Wrong Answer
time: 1396ms
memory: 159024kb

input:

500000

output:

411329960 553707895 908025481 925068834 698467560 570693691 319937913 104661008 421637897 561919933 773269940 975087555 968126031 161592645 754904885 742554982 309908793 713103106 151780212 70956017 873582013 627674139 118624018 393194117 972232669 723210790 673347423 851259466 110195415 604503785 7...

result:

wrong answer 1st words differ - expected: '390220183', found: '411329960'