QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#314321#8133. When Anton Saw This Task He Reacted With 😩bachbeo2007AC ✓546ms92560kbC++235.2kb2024-01-25 15:36:362024-01-25 15:36:37

Judging History

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

  • [2024-01-25 15:36:37]
  • 评测
  • 测评结果:AC
  • 用时:546ms
  • 内存:92560kb
  • [2024-01-25 15:36:36]
  • 提交

answer

// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/

#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int maxn=200005;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=25;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
const int iroot=power(3,mod-2);
const int base=131;

struct matrix{
    int v[3][3],n,m;
    matrix(int n=0,int m=0):n(n),m(m){
        memset(v,0,sizeof(v));
    }
    void init(int x,int y,int z,int t){
        v[0][1]=-z;
        v[0][2]=y;
        v[1][0]=z;
        v[1][2]=-x;
        v[2][0]=-y;
        v[2][1]=x;
        if(t) for(int i=0;i<3;i++) for(int j=0;j<3;j++) v[i][j]=-v[i][j];
    }
    friend matrix operator*(matrix a,matrix b){
        matrix res(a.n,b.m);
        for(int i=0;i<a.n;i++) for(int j=0;j<b.m;j++){
            for(int k=0;k<a.m;k++) res.v[i][j]=(res.v[i][j]+a.v[i][k]*b.v[k][j])%mod;
        }
        return res;
    }
};

struct path{
    int N;
    matrix M;
    vector<matrix> tree;
    void init(int x=0,int y=0,int z=0,int nn=0){
        N=nn;M=matrix(1,3);
        M.v[0][0]=x;M.v[0][1]=y;M.v[0][2]=z;
        tree.resize(4*N);
    }
    void change(int x,int y,int z){
        M.v[0][0]=x;M.v[0][1]=y;M.v[0][2]=z;
    }
    matrix get(){
        if(tree.empty()) return M;
        return M*tree[1];
    }
    void update(int l,int r,int id,int p,matrix x){
        if(l==r){
            tree[id]=x;
            return;
        }
        int mid=(l+r)>>1;
        if(p<=mid) update(l,mid,id<<1,p,x);
        else update(mid+1,r,id<<1|1,p,x);
        tree[id]=tree[id<<1]*tree[id<<1|1];
    }

}P[maxn];

int n,q,a[maxn][3];
vector<int> edge[maxn];

int child[maxn],son[maxn];
int par[maxn],head[maxn],col[maxn];
int L[maxn],pos;

void pre_dfs(int u){
    child[u]=1;
    for(int v:edge[u]){
        pre_dfs(v);
        child[u]+=child[v];
        if(child[son[u]]<child[v]) son[u]=v;
    }
}

void dfs(int u,int p,int t){
    L[u]=++pos;
    if(t) head[u]=head[p];
    else head[u]=u;

    if(son[u]) dfs(son[u],u,1);
    for(int v:edge[u]) if(v!=son[u]) dfs(v,u,0);
}

void update(int v){
    while(head[v]>1){
        v=head[v];
        matrix cur=P[v].get();
        matrix nxt(3,3);
        nxt.init(cur.v[0][0],cur.v[0][1],cur.v[0][2],col[v]);
        int p=par[v];v=head[p];
        //cout << v << ' ' << p << ' ' << P[v].N << endl;
        P[v].update(1,P[v].N,1,P[v].N-(L[p]-L[v]),nxt);
    }
}

void solve(){
    /*
    matrix cur(1,3);
    cur.v[0][0]=0;cur.v[0][1]=2;cur.v[0][2]=1;
    matrix mul(3,3);
    mul.init(1,1,1,0);
    cur=cur*mul;
    cout << cur.v[0][0] << ' ' << cur.v[0][1] << ' ' << cur.v[0][2] << '\n';

    mul=matrix(3,3);
    mul.init(1,0,1,1);
    cur=cur*mul;

    cout << cur.v[0][0] << ' ' << cur.v[0][1] << ' ' << cur.v[0][2] << '\n';
    */
    cin >> n >> q;
    vector<int> leaf;
    for(int i=1;i<=n;i++){
        char c;cin >> c;
        if(c=='x'){
            int l,r;cin >> l >> r;
            edge[i].push_back(l);
            edge[i].push_back(r);
            par[l]=par[r]=i;
            col[l]=1;col[r]=0;
        }
        else{
            cin >> a[i][0] >> a[i][1] >> a[i][2];
            leaf.push_back(i);
        }
    }
    pre_dfs(1);
    dfs(1,0,0);
    for(int v:leaf){
        P[head[v]].init(a[v][0],a[v][1],a[v][2],L[v]-L[head[v]]);
    }
    for(int v:leaf){
        //cout << '*' << v << endl;
        update(v);
    }
    matrix res=P[1].get();
    //cout << res.v[0][0] << ' ' << res.v[0][1] << ' ' << res.v[0][2] << '\n';
    for(int i=1;i<=q;i++){
        int v,x,y,z;
        cin >> v >> x >> y >> z;
        P[head[v]].change(x,y,z);
        update(v);
        matrix res=P[1].get();
        cout << res.v[0][0] << ' ' << res.v[0][1] << ' ' << res.v[0][2] << '\n';
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 37348kb

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: 546ms
memory: 84320kb

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:

-605123795 -224477738 387297348
-238284787 -16469853 128012497
-703632542 -18232745 533642029
-593864779 -252947501 53493560
-593678852 -169374593 78021156
-405749495 -350493049 881427733
-808225886 -483001218 518180555
-370063853 -488259799 257430135
-984507108 -646156562 917410487
-66193044 -63165...

result:

ok 300000 numbers

Test #3:

score: 0
Accepted
time: 506ms
memory: 84180kb

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 -1730057 -549077502
810403092 -740047511 -144784620
410756156 -744895835 -85579882
327134890 -478998570 -75715594
317367558 -461355816 -492030244
484753530 -119198571 -225839405
422920052 -846159695 -480903896
1207902 -649457191 -677423276
776293878 -298769427 -287129823
871858473 -5297467...

result:

ok 300000 numbers

Test #4:

score: 0
Accepted
time: 462ms
memory: 84140kb

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 380448367 629159667
-237565933 539369190 611778104
-883317666 653692915 939877414
-324044883 304745735 544123803
-44444241 186017361 49200537
-670961571 871001677 293980713
-409461196 502130649 190564297
-895563447 993889016 963478755
-488231872 105416897 281770975
-187161547 367139818 49...

result:

ok 300000 numbers

Test #5:

score: 0
Accepted
time: 450ms
memory: 84104kb

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
-600893251 -120282751 429046190
-409876008 -178818454 502148739
-477665442 -811836281 484373545
-355756 -181710037 338411279
-664078084 -710032769 608252640
-488963508 -635271961 286415695
-634847393 -119363102 3658455
-286973481 -903427...

result:

ok 300000 numbers

Test #6:

score: 0
Accepted
time: 412ms
memory: 84312kb

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 190218414 -927685092
-336478455 266356472 -516614332
-587276683 613729303 -194236197
-905606033 37926778 -915320148
-640374470 232766711 -418635821
-306542271 124868602 -810877141
-760633664 608489848 -417139943
-149627621 907873139 -138436462
-383619738 454674844 -324614686
-512459622 74...

result:

ok 300000 numbers

Test #7:

score: 0
Accepted
time: 410ms
memory: 84312kb

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:

-632986028 105829774 -385846523
-266735298 576900445 -334467153
-444725676 415454275 -990560546
-530113104 577225931 -484650068
-782654117 861146274 -185423961
-328258557 229486834 -433552590
-69012487 520228049 -223634605
-968294064 569366391 -277172238
-353671246 513714638 -443786200
-270237152 42...

result:

ok 300000 numbers

Test #8:

score: 0
Accepted
time: 396ms
memory: 85296kb

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:

-568527314 -129935757 -823225834
-31998235 -465792513 -225112347
-541158255 -366456073 -8555110
-447669502 -991537585 -581628454
-713103269 -492917864 -81725651
-540778964 -344714109 -46638582
-384032521 -230416296 -953970559
-300047713 -503306580 -898906555
-279741119 -576166316 -846865302
-9777240...

result:

ok 300000 numbers

Test #9:

score: 0
Accepted
time: 429ms
memory: 85956kb

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:

433293962 336914247 747368803
992117520 9180464 159616244
483825959 496735833 964507719
912495370 737285784 595438897
467123496 44306423 562070292
903488238 42971643 61415659
269853145 336741491 565138878
926999098 134871683 277614816
644727031 476324825 69621281
984868613 112590560 688626178
657736...

result:

ok 300000 numbers

Test #10:

score: 0
Accepted
time: 10ms
memory: 37124kb

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: 450ms
memory: 87316kb

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:

627210517 -357298462 -597759713
305641486 -105185528 -898351186
735729088 -192648820 -715206562
377070714 -640281451 -661458804
835938680 -363549622 -975855419
493696932 -385691560 -481299119
963890355 -480713478 -950021127
215318080 -255660608 -618453331
135074745 -27793541 -76420073
86572382 -5165...

result:

ok 300000 numbers

Test #12:

score: 0
Accepted
time: 408ms
memory: 92560kb

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 177437016 653646802
-949384144 883514812 764698776
-493156041 585962448 546090395
-83998326 540944167 682989725
-32409202 803706423 302298107
-545247818 714783487 961852197
-115526544 425959754 886391042
-794577049 454663502 78105722
-486048218 727218227 418204527
-723309552 270977361 824...

result:

ok 300000 numbers

Extra Test:

score: 0
Extra Test Passed