QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#385747#5696. 时空旅行bachbeo2007100 ✓1197ms240732kbC++174.5kb2024-04-11 01:30:002024-04-11 01:30:01

Judging History

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

  • [2024-04-11 01:30:01]
  • 评测
  • 测评结果:100
  • 用时:1197ms
  • 内存:240732kb
  • [2024-04-11 01:30:00]
  • 提交

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=500005;
const int B=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=101;

struct line{
    int a,b,p;
    bool operator<(line l){return a>l.a;}
    bool operator<(int k){return p<k;}
};
struct cvht{
    int k=0;
    vector<line> x;
    int div(int a,int b){
        return a/b-((a^b)<0 && a%b);
    }
    bool isect(line &l,line y){
        if(l.a==y.a) l.p=(l.b<y.b)?inf:-inf;
        else l.p=div(y.b-l.b,l.a-y.a);
        return l.p>=y.p;
    }
    void add(line l){
        if(!x.empty()) isect(x.back(),l);
        while((int)x.size()>=2 && x[(int)x.size()-2].p>=x.back().p){
            x.pop_back();
            isect(x.back(),l);
        }
        x.push_back(l);
    }
    int query(int v){
        if(x.empty()) return inf;
        while(k<(int)x.size() && v>x[k].p) k++;
        return v*x[k].a+x[k].b;
    }
}cht[4*maxn];

int n,p[maxn],x[maxn],c[maxn];
vector<int> edge[maxn],del[maxn];
int L[maxn],R[maxn],T,pos[maxn];
int m,res[maxn],S[maxn],X[maxn];

void dfs(int u){
    L[u]=++T;
    for(int v:edge[u]) dfs(v);
    R[u]=T;
    //cout << u << ' ' << L[u] << ' ' << R[u] << '\n';
}

void update(int l,int r,int id,int tl,int tr,int i){
    //if(id==1) cout << tl << ' ' << tr << ' ' << i << '\n';
    if(tr<l || r<tl) return;
    if(tl<=l && r<=tr){
        cht[id].add({-2*x[i],x[i]*x[i]+c[i],inf});
        return;
    }
    int mid=(l+r)>>1;
    update(l,mid,id<<1,tl,tr,i);update(mid+1,r,id<<1|1,tl,tr,i);
}
int query(int l,int r,int id,int p,int val){
    int res=val*val+cht[id].query(val);
    if(l==r) return res;
    int mid=(l+r)>>1;
    if(p<=mid) res=min(res,query(l,mid,id<<1,p,val));
    else res=min(res,query(mid+1,r,id<<1|1,p,val));
    return res;
}

void solve(){
    cin >> n >> m >> c[0];
    for(int i=1;i<n;i++){
        int op,fr;cin >> op >> fr;
        edge[fr].push_back(i);
        //cout << "*" << fr << ' ' << i << '\n';
        if(!op){
            cin >> p[i] >> x[i] >> fr >> fr >> c[i];
            pos[p[i]]=i;
        }
        else{
            cin >> p[i],c[i]=-1;
            del[pos[p[i]]].push_back(i);
        }
    }
    dfs(0);
    vector<int> ord(n);
    iota(ord.begin(),ord.end(),0);
    sort(ord.begin(),ord.end(),[](int a,int b){
        return x[a]<x[b];
    });
    for(int i:ord){
        if(c[i]==-1) continue;
        sort(del[i].begin(),del[i].end(),[](int a,int b){
            return L[a]<L[b];
        });
        int l=L[i];
        for(int j:del[i]){
            if(l<L[j]) update(1,n,1,l,L[j]-1,i);
            l=R[j]+1;
        }
        if(l<=R[i]) update(1,n,1,l,R[i],i);
    }
    for(int i=1;i<=m;i++) cin >> S[i] >> X[i];
    ord.assign(m,0);
    iota(ord.begin(),ord.end(),1);
    sort(ord.begin(),ord.end(),[](int a,int b){
        return X[a]<X[b];
    });
    for(int i:ord) res[i]=query(1,n,1,L[S[i]],X[i]);
    for(int i=1;i<=m;i++) cout << res[i] << '\n';
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 4ms
memory: 90956kb

input:

100 100 1000004499
0 0 1 71139 12101 26676 1000002621
0 1 2 -388974 29267 3476 1000003458
0 2 3 717215 32379 13949 1000002483
0 3 4 -102846 14876 26114 1000004602
0 4 5 -623116 28528 562 1000000064
0 5 6 322377 4595 24356 1000000158
0 6 7 18175 25622 15156 1000001174
0 7 8 -365353 10113 32371 100000...

output:

4241956644
238137836482
5396490615
1659824452
49755292257
159807611
149696295
4144630087
506817535
1171087128
1003882937
478788676
6146863707
4794071846
1106338763
1915248639
1097971007
764285371
2693984312
1208749203
4022364829
2251181984
1793043685
2286227224
1070359224
7916254354
624426476
777477...

result:

ok 100 numbers

Test #2:

score: 5
Accepted
time: 177ms
memory: 118284kb

input:

100000 100000 1000002978
0 0 1 347020 317 26353 1000001834
0 1 2 452248 20085 9869 1000000053
0 2 3 88459 19993 29155 1000004823
0 3 4 408702 5984 24103 1000003587
0 4 5 154047 3585 26940 1000000592
0 5 6 -502738 31814 22490 1000001346
0 6 7 290918 11997 18888 1000003876
0 7 8 -534624 10237 23803 10...

output:

329118324
51003573
324784662
1000001788
4995331
1000036024
130412734
1000004054
1000009737
1000006368
1000001711
84362543
176864615
409025186
1000003720
70942481
1000032818
86013872
124120706
1000003542
106479459
152523067
389751358
1000000760
1000006493
1005264307
404936319
46997913
1000003917
1000...

result:

ok 100000 numbers

Test #3:

score: 5
Accepted
time: 187ms
memory: 119612kb

input:

100000 100000 1000000878
0 0 1 -952170 9287 22191 1000003732
0 1 2 -274534 16036 12281 1000001125
0 2 3 -404210 11647 4046 1000001045
0 3 4 -871605 29181 18123 1000003271
0 4 5 611274 1020 24724 1000001800
0 5 6 -200646 5240 19761 1000003891
0 6 7 -414769 18480 24157 1000004621
0 7 8 51036 21570 33 ...

output:

98997808
205244946
1000003353
33849053
1000097495
1000000667
1000003130
58602325
68078473
1000028241
8778840
1000001932
270743544
143710992
1000004172
82039752
1000000635
157660411
324274338
204188473
19740049
145593422
749646962
97671818
1000006174
51342694
404651220
45205977
104304451
748200731
30...

result:

ok 100000 numbers

Test #4:

score: 5
Accepted
time: 172ms
memory: 119196kb

input:

100000 100000 1000000614
0 0 1 155661 12105 18662 1000002227
0 1 2 411835 32120 32651 1000001243
0 2 3 997709 1036 3270 1000002437
0 3 4 -171196 18434 11609 1000004001
0 4 5 126520 22747 10378 1000000213
0 5 6 88917 23026 26587 1000003502
0 6 7 -578524 32600 27031 1000003599
0 7 8 -230133 25256 1963...

output:

1000003975
15145903
1000000334
24735331
615326000
54324931
245171352
546226413
825653202
308952950
1000194490
133416762
1000002735
1000002128
1000005520
1000000855
1000001874
369503897
1000029930
1000001934
1000003178
82342643
1000003161
37331106
1000002615
1000294658
1000002849
1000011107
100002071...

result:

ok 100000 numbers

Test #5:

score: 5
Accepted
time: 162ms
memory: 120136kb

input:

100000 100000 1000000489
0 0 1 -700834 3972 9939 1000001167
0 1 2 -512710 13506 21571 1000002213
0 2 3 297678 330 17792 1000003926
0 3 4 -674450 2751 13776 1000001342
0 4 5 -236428 29299 30173 1000002441
0 5 6 987829 22388 4052 1000000745
0 6 7 -742860 32276 21950 1000000576
0 7 8 -605162 182 29539 ...

output:

47889958
27284557
837115895
47889958
1000003863
94659930
126628180
837115895
1000003863
27284557
837115895
45287043
1000003863
1000003863
27284557
1000003863
1000010120
201535068
123858753
1005113305
837115895
1000003863
1000003863
1000003863
101123987
1000003863
837115895
203744943
1000003863
10112...

result:

ok 100000 numbers

Test #6:

score: 5
Accepted
time: 148ms
memory: 118844kb

input:

100000 100000 1000003819
0 0 1 668497 9175 24793 1000004457
0 1 2 -29071 20738 7926 1000002958
0 2 3 -222928 18653 16790 1000000208
0 3 4 432545 10294 8304 1000004331
0 4 5 850693 4288 8537 1000000904
0 5 6 50586 25567 19849 1000002002
0 6 7 682803 28863 12731 1000001730
0 7 8 -713971 6221 26712 100...

output:

1000001610
1000001610
1000001610
81384128
1000001610
1000001610
1000001610
700472905
1000001610
1000001610
1000060507
1000001610
265444467
1000001610
1000001610
1000001610
1000001610
934248670
1000001610
1000001610
1000001610
265444467
1000001610
1000001610
1000001610
1000001610
1000001610
94175997
...

result:

ok 100000 numbers

Test #7:

score: 5
Accepted
time: 188ms
memory: 120064kb

input:

100000 100000 1000000263
0 0 1 381961 17121 24677 1000000369
0 1 2 -882895 30991 32450 1000003465
0 2 3 -291669 1646 14473 1000000461
0 3 4 -513350 1319 29046 1000001855
0 4 5 651223 31111 4843 1000003264
0 5 6 -142415 2637 5802 1000001334
0 6 7 925939 13394 21616 1000002952
0 7 8 -81339 7284 4478 1...

output:

272546498
122876442
44038703
1000007450
57659961
1000003750
790404366
3366413
1000005903
337220378
1000003145
272785020
30733002
112682930
166795683
83406370
88558097
1000007621
1000006883
1000002117
93897981
62728719
1000008863
1000000242
437605322
1000002155
229026742
1000022704
1000001407
1000001...

result:

ok 100000 numbers

Test #8:

score: 5
Accepted
time: 190ms
memory: 120392kb

input:

100000 100000 1000004558
0 0 1 469550 6836 11332 1000004792
0 1 2 -435120 18633 4592 1000004068
0 2 3 -197345 25270 25090 1000003541
0 3 4 876062 10491 10863 1000002840
0 4 5 411305 12923 21154 1000001411
0 5 6 -693785 21021 22135 1000002888
0 6 7 -829958 16030 20937 1000004049
0 7 8 299768 13772 10...

output:

62848378
1000007279
3636525
1000703024
1000006248
1000002923
116636307
1000001495
258248643
1000002997
91461307
1000004527
173616675
1000000538
1000011435
1000000765
1000003500
1000001703
1000004264
1000014412
331415880
58470528
1000001422
67316851
1000046260
78023416
1000378931
499184892
1010612181...

result:

ok 100000 numbers

Test #9:

score: 5
Accepted
time: 1045ms
memory: 231360kb

input:

500000 500000 1000003241
0 0 1 -408344 16417 24891 1000002566
0 1 2 905197 28804 21421 1000002394
0 2 3 983860 16964 6910 1000003907
0 3 4 273351 6904 6980 1000001705
0 4 5 470878 9785 22065 1000003117
0 5 6 -181349 28769 24313 1000003842
0 6 7 10103 11314 9887 1000002976
0 7 8 195837 8874 11138 100...

output:

125819441
1000000741
458817667
1000002923
19027330
1000000741
1000002923
1000001750
956470103
257947575
81343830
37352688
1000000741
419893179
1000000741
217716883
809013777
935641892
1000000741
74835556
455688009
1000000741
1000000741
1000001750
1000001750
1000000741
1000000741
809013777
1000002923...

result:

ok 500000 numbers

Test #10:

score: 5
Accepted
time: 1037ms
memory: 231328kb

input:

500000 500000 1000003565
0 0 1 441249 8786 28661 1000002799
0 1 2 -339582 19178 15869 1000000401
0 2 3 -617710 15350 23495 1000000434
0 3 4 558152 16199 30210 1000000775
0 4 5 -753221 25210 10160 1000004836
0 5 6 748945 24605 21495 1000002258
0 6 7 192699 9902 1862 1000001090
0 7 8 558176 5333 25281...

output:

1000002388
1000001540
1000001540
1000001540
407404347
429398700
1000001602
1000001602
1000001540
828034801
1000002388
82708228
1000001602
1000001540
470149340
1000001540
1000001540
1000002388
279784312
1000001540
168391090
1000001602
1000001602
83372841
1000071291
82708228
1000001540
1000002388
1000...

result:

ok 500000 numbers

Test #11:

score: 5
Accepted
time: 1110ms
memory: 240580kb

input:

500000 500000 1000000694
0 0 1 -197399 28743 22363 1000002386
0 1 2 674400 8539 32509 1000002275
0 2 3 -655397 20397 32236 1000001346
0 3 4 -437867 17510 19651 1000001799
0 4 5 638836 24628 32506 1000002623
0 5 6 216428 26717 26970 1000002140
0 6 7 443425 17874 31011 1000001838
0 7 8 -276149 3469 10...

output:

1000003413
551994
651117
1000001054
395236
1024545
1000005276
776822
170447
1000003659
1330606
709148
572798
1347153
1000000362
2369847
287470
779358
658830
1000003180
1000000757
1000000798
1000000466
356110
1068126
1000001786
226235
43818
318264
4507878
1000001969
125552
981116
2059843
5687969
1736...

result:

ok 500000 numbers

Test #12:

score: 5
Accepted
time: 1070ms
memory: 240624kb

input:

500000 500000 1000000911
0 0 1 703011 21219 25858 1000004146
0 1 2 -450509 23942 26500 1000004224
0 2 3 -904492 19568 13252 1000002473
0 3 4 386250 8179 9129 1000003587
0 4 5 388518 28583 13345 1000003544
0 5 6 -912741 27178 23384 1000002533
0 6 7 -830324 9 500 1000004822
0 7 8 145641 31437 16095 10...

output:

1000001875
1000001812
1084580
1000000917
683307
2106644
1000018148
1000003123
1000002691
363750
656740
986471
487651
604433
318365
4888810
603473
1000002191
234172
1424185
617244
757264
3155963
217627
1362233
118142
2448673
1000002981
897145
1000000510
1000004307
1000000953
7158246
1032471
100000055...

result:

ok 500000 numbers

Test #13:

score: 5
Accepted
time: 1090ms
memory: 240732kb

input:

500000 500000 1000004104
0 0 1 -627834 5936 31727 1000002050
0 1 2 -376309 24185 18306 1000000792
0 2 3 -653653 21438 22329 1000004342
0 3 4 419718 31952 2773 1000003233
0 4 5 43232 490 18832 1000003290
0 5 6 -756714 32656 10493 1000004554
0 6 7 457687 23674 9186 1000000438
0 7 8 374416 27597 10491 ...

output:

1000004626
1478268
171252
881308
1308174
1000008643
1000000535
1544809
2361561
1057572
542134
1189778
1000001042
335707
1000001352
1000003678
1000000909
204740
1000004487
811307
1000001792
1000002516
860772
1000001934
1000002678
1000000196
463040
1000002484
1000883187
202150
1000015830
1000002166
64...

result:

ok 500000 numbers

Test #14:

score: 5
Accepted
time: 1065ms
memory: 232044kb

input:

500000 500000 1000002705
0 0 1 41321 24456 19015 1000002721
0 1 2 -560286 22994 15579 1000002361
0 2 3 -370045 1584 32651 1000001211
0 3 4 195011 15308 447 1000001056
0 4 5 -527463 876 13803 1000003444
0 5 6 -375278 1805 2362 1000001983
0 6 7 -287070 4893 4427 1000000517
0 7 8 312247 24234 26870 100...

output:

205582568
278134552
136483851
150764004
1000006580
256940054
640387038
311768504
209451755
167960124
1000017380
1000000031
322928518
939141799
1000000553
529183891
86099648
93656921
1000000706
1000000918
359543266
1000000242
1000000839
1000002429
262928990
1000019658
246569258
1000000689
195871681
6...

result:

ok 500000 numbers

Test #15:

score: 5
Accepted
time: 1058ms
memory: 232084kb

input:

500000 500000 1000003130
0 0 1 677709 24173 22392 1000000624
0 1 2 -777031 18590 6784 1000003929
0 2 3 -86438 23762 22452 1000000312
0 3 4 3071 4006 31305 1000000703
0 4 5 -872749 8885 27064 1000000422
0 5 6 -219250 27939 8468 1000004004
0 6 7 -773652 28030 10726 1000001132
0 7 8 250079 6089 24320 1...

output:

1000002042
92529117
593338104
1000001896
64561575
185758082
166485147
559360263
226343520
1000000262
470641022
392844080
1000017979
60064884
482734540
1000000475
1000001165
1000001165
21547974
1000000812
1000003448
1000004084
1000001690
1000003476
1000001930
1000003441
1000002427
119922573
230614013...

result:

ok 500000 numbers

Test #16:

score: 5
Accepted
time: 1064ms
memory: 232316kb

input:

500000 500000 1000004708
0 0 1 -691751 6559 2221 1000002439
0 1 2 -278251 14398 16841 1000000118
0 2 3 471695 15793 18487 1000004210
0 3 4 762306 25076 11973 1000004561
0 4 5 461587 15302 1112 1000004809
0 5 6 -618153 19942 605 1000001237
0 6 7 817942 14121 7058 1000001075
0 7 8 -263282 25692 22079 ...

output:

846698232
32062122
1000001017
86308887
30350470
81007413
1000001571
83646146
1000035399
1000001612
1000000608
1000007935
73766114
355347695
1000002219
1000000953
1000001552
176881709
209039510
1000001341
1000000442
638204074
1000000707
1000001532
384016527
1000002124
521519676
3020177
166361534
1927...

result:

ok 500000 numbers

Test #17:

score: 5
Accepted
time: 1081ms
memory: 232156kb

input:

500000 500000 1000001286
0 0 1 4326 9806 9297 1000002021
0 1 2 478704 21169 5142 1000001306
0 2 3 -937404 19976 5498 1000000341
0 3 4 -220283 8076 27537 1000000243
0 4 5 -204077 2254 30533 1000003252
0 5 6 -984288 32021 28422 1000003470
0 6 7 602175 30903 7473 1000003786
0 7 8 -809410 24628 8835 100...

output:

1000000894
1000000359
471723018
1000012108
418141886
109911391
340725653
1000000213
130008400
1000001806
948663647
499601984
167585451
1000001886
500747790
667215550
224162763
349220634
1000000601
1000000964
540224432
1000001365
1000001758
163521357
1000000998
1000001893
256484740
1000000567
6047981...

result:

ok 500000 numbers

Test #18:

score: 5
Accepted
time: 1141ms
memory: 232028kb

input:

500000 500000 1000001795
0 0 1 361324 2552 7408 1000000472
0 1 2 348988 30279 16996 1000001032
0 2 3 544966 31580 28698 1000000425
0 3 4 570122 28243 983 1000001834
0 4 5 851074 10398 23304 1000001453
0 5 6 -240461 9817 31784 1000004590
0 6 7 -263551 29737 27720 1000004769
0 7 8 600263 20798 6630 10...

output:

1000004598
1000000987
238311701
1000000516
364289476
1000001417
1000000912
869506996
149486670
1000003486
1000003043
1000000995
137450671
1000000321
1000000056
214224765
113226827
1000006260
1000003171
1000000446
134674460
1000000178
853299472
1000001888
1000000875
74917243
1000001910
82372170
10000...

result:

ok 500000 numbers

Test #19:

score: 5
Accepted
time: 1186ms
memory: 231220kb

input:

500000 500000 1000002538
0 0 1 -465573 289 5627 1000003715
0 1 2 -588592 31641 5312 1000003118
0 2 3 -738800 13520 16158 1000000104
0 3 4 568747 17751 22949 1000001564
0 4 5 460981 29409 28639 1000000010
0 5 6 884205 32393 16313 1000001623
0 6 7 -284901 3613 7487 1000004596
0 7 8 -898881 20708 31024...

output:

1000001406
64585843
41809852
978403812
1000001230
1000001462
162160141
1000001022
1000000995
167294163
1000000647
152615564
1000002048
1000001139
1000000303
1000000620
171784504
410118225
1000001320
497000280
1000001691
573036450
690131539
235677244
1000000988
1000001212
43563830
1000006787
10000015...

result:

ok 500000 numbers

Test #20:

score: 5
Accepted
time: 1197ms
memory: 231456kb

input:

500000 500000 1000002484
0 0 1 -966219 3481 6107 1000004544
0 1 2 591638 31287 19822 1000003873
0 2 3 -107979 4526 178 1000002820
0 3 4 -216181 24714 20640 1000004516
0 4 5 948520 14768 9024 1000000544
0 5 6 -419429 6489 30939 1000003565
0 6 7 171666 8402 11662 1000000239
0 7 8 -532670 31008 17553 1...

output:

67849346
1000000967
1000000434
555407561
1000003301
1000001548
272345963
1000002544
82590310
65082557
229774011
37959199
1000000848
1000000241
1000001585
1000006671
854882940
511587016
1000001187
1000001630
103066336
1000001547
1000003433
1000002302
346745268
53660310
75097648
1000001336
1000002808
...

result:

ok 500000 numbers

Extra Test:

score: 0
Extra Test Passed