QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#429783#8133. When Anton Saw This Task He Reacted With 😩lmeowdnAC ✓1297ms183172kbC++144.0kb2024-06-02 20:43:092024-06-02 20:43:09

Judging History

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

  • [2024-06-02 20:43:09]
  • 评测
  • 测评结果:AC
  • 用时:1297ms
  • 内存:183172kb
  • [2024-06-02 20:43:09]
  • 提交

answer

//Shirasu Azusa 2024.6
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;  
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} 
  return x*w;
}

const int N=1e6+5,mod=998244353;
struct Vec {
  int a[3];
  Vec(int x=0) {rep(i,0,2) a[i]=x;}
};
struct Mat {
  int a[3][3];
  Mat(int x=0) {
    memset(a,0,sizeof(a));
    a[0][0]=a[1][1]=a[2][2]=x;
  }
  Mat(Vec x,int t) {
    rep(i,0,2) a[(i+2)%3][(i+1)%3]=t*x.a[i];
    rep(i,0,2) a[(i+1)%3][(i+2)%3]=-t*x.a[i];
    rep(i,0,2) a[i][i]=0;
  }
};
Mat operator * (const Mat x,const Mat y) {
  Mat z;
  rep(i,0,2) rep(j,0,2) rep(k,0,2)
    z.a[i][k]=(z.a[i][k]+x.a[i][j]*y.a[j][k])%mod;
  return z;
}
Vec operator * (const Vec x,const Mat y) {
  Vec z;
  rep(i,0,2) rep(j,0,2)
    z.a[j]=(z.a[j]+x.a[i]*y.a[i][j])%mod;
  return z;
}

int n,q,pos[N],id[N],top[N],sz[N],son[N],fa[N],tick,l[N],r[N],w[N];
Vec a[N]; vi e[N];

namespace SegT {
  #define ls ((p)<<1)
  #define rs ((p)<<1|1)
  pair<Vec,Mat> f[N];
  auto operator + (pair<Vec,Mat> a,pair<Vec,Mat> b) {
    return mp(a.fi*b.se,a.se*b.se);
  }
  void build(int p,int l,int r) {
    if(l==r) {f[p].fi=a[id[l]],f[p].se=Mat(a[id[l]],w[id[l]]); return;}
    int mid=l+r>>1; build(ls,l,mid), build(rs,mid+1,r);
    f[p]=f[ls]+f[rs];
  }
  void mdf(int p,int l,int r,int x) {
    if(l==r) {f[p].fi=a[id[l]],f[p].se=Mat(a[id[l]],w[id[l]]); return;}
    int mid=l+r>>1; x<=mid?mdf(ls,l,mid,x):mdf(rs,mid+1,r,x);
    f[p]=f[ls]+f[rs];
  }
  auto qry(int p,int l,int r,int x,int y) {
    if(l==x&&r==y) return f[p]; int mid=l+r>>1;
    if(y<=mid) return qry(ls,l,mid,x,y);
    else if(x>mid) return qry(rs,mid+1,r,x,y);
    else return qry(ls,l,mid,x,mid)+qry(rs,mid+1,r,mid+1,y);
  }
}

void dfs1(int u) {
  for(int v:e[u]) {
    dfs1(v); fa[v]=u;
    if(sz[v]>sz[son[u]]) son[u]=v; sz[u]+=sz[v];
  } sz[u]++;
}
void dfs2(int u,int tp) {
  if(!e[u].size()) {
    ++tick; id[tick]=u; top[u]=tp;
    chmin(l[tp],tick), chmax(r[tp],tick);
  } else {
    for(int v:e[u]) if(v!=son[u]) {
      ++tick; id[tick]=v; top[v]=tp;
      chmin(l[tp],tick), chmax(r[tp],tick);
    }
    dfs2(son[u],tp);
    for(int v:e[u]) if(v!=son[u]) {
      if(e[v].size()) dfs2(v,v);
    }
  }
  if(e[u].size()) {
    a[u]=a[e[u][0]]*Mat(a[e[u][1]],1);
  }
}
Vec mdf(int u,Vec t) {
  for(;u!=1;) {
    a[u]=t; SegT::mdf(1,1,n,pos[u]);
    u=top[u]; t=SegT::qry(1,1,n,l[u],r[u]).fi;
  }
  return t;
}

signed main() {
  n=read(), q=read();
  rep(i,1,n) l[i]=N;
  rep(i,1,n) {
    static char op[4]; scanf("%s",op);
    if(op[0]=='x') {
      rep(j,0,1) e[i].eb(read());
      w[e[i][0]]=-1, w[e[i][1]]=1;
    } else {
      rep(j,0,2) a[i].a[j]=read();
    }
  }
  dfs1(1); dfs2(1,1);
  rep(i,1,n) if(l[i]!=N) reverse(id+l[i],id+r[i]+1);
  rep(i,1,n) pos[id[i]]=i;
  SegT::build(1,1,n);
  rep(i,1,q) {
    int u=read(); Vec t; rep(j,0,2) t.a[j]=read();
    t=mdf(u,t); //rep(j,0,2) t.a[j]=(t.a[j]%mod+mod)%mod;
    printf("%lld %lld %lld\n",t.a[0],t.a[1],t.a[2]);
  }
  return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 155688kb

input:

5 3
x 2 3
v 1 0 1
x 4 5
v 0 2 1
v 1 1 1
4 1 2 3
5 0 1 1
4 0 2 2

output:

-2 0 2
1 -2 -1
0 0 0

result:

ok 9 numbers

Test #2:

score: 0
Accepted
time: 1297ms
memory: 171676kb

input:

199999 100000
x 137025 65661
v 572518668 158967010 74946561
x 129836 192657
x 141948 187810
v 574918069 328924434 141474729
x 143312 111002
x 52772 148497
v 922857701 690080961 651915759
v 656198340 28002884 129579416
v 639893144 265359784 646791226
v 796871409 411409966 598676495
v 882562617 224394...

output:

393120558 773766615 -610947005
-238284787 -16469853 128012497
294611811 980011608 -464602324
-593864779 745296852 53493560
-593678852 828869760 78021156
-405749495 647751304 881427733
-808225886 515243135 518180555
628180500 -488259799 -740814218
-984507108 352087791 917410487
-66193044 366591227 47...

result:

ok 300000 numbers

Test #3:

score: 0
Accepted
time: 1098ms
memory: 169652kb

input:

199999 100000
x 154525 80092
v 450407262 725458410 590777520
x 24720 135901
v 719242117 114943104 186796011
v 382530926 89156744 943939337
x 183376 26042
x 109984 157873
x 151637 150600
x 4115 27454
x 163135 92648
x 16764 33212
v 849210403 945083972 689295397
v 471196117 68587428 225597765
x 24643 5...

output:

677067461 996514296 -549077502
810403092 258196842 -144784620
-587488197 -744895835 912664471
327134890 519245783 -75715594
-680876795 -461355816 506214109
-513490823 -119198571 772404948
422920052 152084658 -480903896
-997036451 -649457191 -677423276
776293878 699474926 711114530
-126385880 -529746...

result:

ok 300000 numbers

Test #4:

score: 0
Accepted
time: 817ms
memory: 173368kb

input:

199999 100000
x 72889 193806
x 35339 33069
v 314802407 406980523 492377265
x 108307 60027
x 144922 140917
v 328481079 117663280 644171354
v 482028404 951751561 166221217
v 936461869 436114879 421819757
x 152919 99965
x 61168 150607
v 56403640 743462679 134896557
v 24809217 462947115 966139991
v 7828...

output:

-974534477 -617795986 629159667
760678420 539369190 -386466249
114926687 653692915 -58366939
674199470 304745735 544123803
-44444241 -812226992 -949043816
327282782 871001677 293980713
588783157 502130649 190564297
102680906 993889016 963478755
510012481 105416897 281770975
811082806 367139818 49367...

result:

ok 300000 numbers

Test #5:

score: 0
Accepted
time: 728ms
memory: 175380kb

input:

199999 100000
x 134204 79203
v 152855933 152545887 271660214
v 393332175 182708769 115884220
v 731792305 965028257 676889584
x 89631 14495
x 142016 85686
v 600051847 172947969 906920949
v 846126215 214556203 657929902
x 125721 133526
x 93179 35713
v 330716449 450417250 611411649
v 114397688 58644961...

output:

-858646737 -622769376 14619793
-108915893 -918516919 363703631
397351102 877961602 -569198163
-409876008 -178818454 502148739
-477665442 -811836281 484373545
997888597 816534316 -659833074
-664078084 -710032769 608252640
-488963508 -635271961 286415695
363396960 878881251 -994585898
-286973481 -9034...

result:

ok 300000 numbers

Test #6:

score: 0
Accepted
time: 565ms
memory: 175140kb

input:

199999 100000
x 29842 60343
x 22382 27649
v 148997533 411153785 529195552
v 831453378 856711025 439562917
x 183061 152107
v 208562249 845550020 248974502
x 8708 152913
v 901332053 480035531 424365358
v 120556946 620074725 884675784
v 493886564 455460926 851190410
x 63346 64739
x 35246 36255
v 762936...

output:

-761447031 -808025939 70559261
661765898 266356472 -516614332
410967670 613729303 -194236197
92638320 37926778 -915320148
-640374470 -765477642 579608532
-306542271 -873375751 187367212
-760633664 -389754505 581104410
848616732 907873139 -138436462
-383619738 -543569509 673629667
485784731 743926138...

result:

ok 300000 numbers

Test #7:

score: 0
Accepted
time: 557ms
memory: 174004kb

input:

199999 100000
x 179471 175117
x 189060 178495
x 20142 58065
x 22916 150184
v 704047412 186112247 660817663
v 761554808 199099716 794321264
v 362925435 508140595 251556541
v 65674025 717152823 157775106
v 325965317 977108704 50644678
v 566946741 833186394 771714200
v 996708965 76780827 625429369
v 85...

output:

365258325 -892414579 -385846523
-266735298 576900445 663777200
-444725676 415454275 7683807
468131249 -421018422 -484650068
-782654117 861146274 812820392
669985796 -768757519 -433552590
-69012487 520228049 774609748
29950289 -428877962 -277172238
644573107 -484529715 -443786200
728007201 -574397023...

result:

ok 300000 numbers

Test #8:

score: 0
Accepted
time: 580ms
memory: 175036kb

input:

199999 100000
x 73506 171332
x 135330 187765
v 308206068 679940956 278078069
v 442448744 196158033 738117032
x 194709 115786
v 208526122 936976225 340056181
x 42663 43401
x 55484 199464
v 865443128 131903961 74265613
x 44659 44773
x 32199 18455
v 986118756 284329619 244212114
v 793747964 649179736 4...

output:

429717039 -129935757 -823225834
966246118 -465792513 -225112347
-541158255 631788280 989689243
550574851 -991537585 -581628454
285141084 -492917864 -81725651
457465389 -344714109 -46638582
614211832 -230416296 -953970559
698196640 -503306580 -898906555
-279741119 422078037 151379051
20520347 -291100...

result:

ok 300000 numbers

Test #9:

score: 0
Accepted
time: 587ms
memory: 178212kb

input:

199999 100000
x 109220 170287
v 563361501 367416904 98790213
x 31431 96958
x 99594 159052
x 95382 129615
v 61965807 547448247 405891792
v 443530416 578856323 588763197
v 761021716 795533831 212530056
v 370964907 391812631 255457982
x 49713 153066
x 141543 111694
v 144135957 614962153 284136518
x 416...

output:

-564950391 -661330106 -250875550
-6126833 -989063889 -838628109
-514418394 -501508520 -33736634
912495370 737285784 595438897
-531120857 -953937930 -436174061
-94756115 -955272710 -936828694
269853145 336741491 565138878
926999098 134871683 277614816
-353517322 -521919528 -928623072
984868613 112590...

result:

ok 300000 numbers

Test #10:

score: 0
Accepted
time: 8ms
memory: 156468kb

input:

3 1
x 2 3
v 998244352 998244352 998244352
v 0 0 0
3 1 2 0

output:

-998244351 998244352 -1

result:

ok 3 number(s): "2 998244352 998244352"

Test #11:

score: 0
Accepted
time: 537ms
memory: 178576kb

input:

199999 100000
x 199465 1690
x 70268 106693
v 194793703 729830314 457557419
x 64673 6910
v 755452906 141328541 558160677
v 725017524 158685295 201414156
x 161801 27226
x 181414 47025
v 387724146 819109666 514628998
v 252532326 97757436 828777580
v 200868967 692540096 706977766
v 300419109 2053530 824...

output:

-371033836 640945891 400484640
-692602867 893058825 99893167
-262515265 805595533 283037791
-621173639 357962902 336785549
835938680 -363549622 -975855419
-504547421 612552793 516945234
-34353998 517530875 48223226
-782926273 742583745 379791022
135074745 -27793541 -76420073
86572382 -516548109 -269...

result:

ok 300000 numbers

Test #12:

score: 0
Accepted
time: 534ms
memory: 183172kb

input:

199999 100000
x 37758 141919
v 148792593 369372129 595139892
x 59335 149367
v 452667329 904801829 628919068
v 160106559 532238331 179544300
v 850489754 705167899 265598880
x 120963 167491
x 92157 46815
v 444945978 987276260 843838004
x 189040 28027
v 889755401 760730228 3237333
x 168907 82672
v 2329...

output:

-101058855 -820807337 653646802
-949384144 -114729541 764698776
-493156041 -412281905 546090395
-83998326 -457300186 682989725
965835151 803706423 -695946246
452996535 714783487 -36392156
882717809 425959754 -111853311
203667304 454663502 -920138631
512196135 727218227 -580039826
274934801 270977361...

result:

ok 300000 numbers

Extra Test:

score: 0
Extra Test Passed