QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#553681#9238. Treechenxinyang2006#20 73ms28888kbC++203.0kb2024-09-08 17:50:442024-09-08 17:50:45

Judging History

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

  • [2024-09-08 17:50:45]
  • 评测
  • 测评结果:20
  • 用时:73ms
  • 内存:28888kb
  • [2024-09-08 17:50:44]
  • 提交

answer

#include "tree.h"
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;

template <class T>
void chkmax(T &x,T y){
  if(x < y) x = y;
}

template <class T>
void chkmin(T &x,T y){
  if(x > y) x = y;
}

inline int popcnt(int x){
  return __builtin_popcount(x);
}

inline int ctz(int x){
  return __builtin_ctz(x);
}


/*ll power(ll p,int k = mod - 2){
  ll ans = 1;
  while(k){
    if(k % 2 == 1) ans = ans * p % mod;
    p = p * p % mod;
    k /= 2; 
  }
  return ans;
}*/

int n,m;
int fa[200005],w[200005];
vector <int> son[200005];

int a[200005],b[200005],c0,c1,cq;
void dfs(int u){
    int ssum = 0;
    if(a[u] == -1){
        for(int v:son[u]) dfs(v);
        ssum += SZ(son[u]);
    } 
    if(!ssum){
        if(a[u] == -1) cq++;
        else if(!a[u]) c0++;
        else c1++;
    }
}

ll cL,cR;
ll cof[200005][2];
void ssolve(int bas,int V){
    if(!bas) return;
    a[0] = (0 > V);
    rep(u,1,n){
        if(V < -w[u]){
            a[u] = 1;
        }else if(w[u] <= V){
            a[u] = 0;
        }else{
            a[u] = -1;
        }
    }    
    rep(u,0,n){
        if(a[u] == -1) continue;
        
        for(int v:son[u]){
            if(a[v] != -1){
                if(a[u] && !a[v]) cL += bas;
                if(!a[u] && a[v]) cR -= bas;
            }else{
                c0 = c1 = cq = 0;
                dfs(v);
                if(!c1 && !a[u]){
                    cof[c0 + cq][0] += bas;
                }else{
                    cL += 1ll * bas * (c0 + cq);
                    cR -= 1ll * bas * (1 - a[u]);
                }
            }
        }
    }
}

void init(std::vector<int> _P, std::vector<int> _W) {
    n = SZ(_P);
    rep(u,2,n) fa[u] = _P[u - 1] + 1;
    rep(u,2,n) son[fa[u]].eb(u);
    son[0].eb(1);
    rep(u,1,n){
        w[u] = _W[u - 1];
        chkmax(m,w[u]);
    }
    rep(i,1,n){
        b[2 * i - 1] = -w[i];
        b[2 * i] = w[i];
    }
    b[2 * n + 1] = 0;
    sort(b + 1,b + 2 * n + 2);
    rep(i,1,2 * n) ssolve(b[i + 1] - b[i],b[i]);
    rep(i,0,n){
        cof[i][1] = cof[i][0];
        cof[i][0] *= i;
    }
    per(i,n,1){
        cof[i - 1][0] += cof[i][0];
        cof[i - 1][1] += cof[i][1];
    }
}

ll query(int L,int R) {
    ll answer = cL * L + cR * R;
    int p = (R + L - 1) / L;
    chkmin(p,n + 1);
//    rep(i,p,n) answer += cof[i][0] * L - cof[]
    answer += cof[p][0] * L - cof[p][1] * R;
//    rep(i,0,n) max(0ll,1ll * i * L - R);
    return answer;
}
/*
g++ grader.cpp tree6.cpp -o grader6.exe -Wall -Wshadow -O2 -std=c++14
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 0 2 2 4 5 4 5 8 9 10 9 8 10 14 15 14 15 18 19 20 21 18 22 21 24 24 27 22 27 30 31 31 33 30 19 20 33 38 38 40 41 41 43 44 43 44 47 48 49 50 49 50 53 54 53 48 54 58 58 60 60 62 62 64 64 66 66 67 67 70 71 72 71 72 75 70 75 78 78 80 81 80 81 84 85 86 86 88 89 90...

output:


result:


Subtask #2:

score: 13
Accepted

Test #11:

score: 13
Accepted
time: 56ms
memory: 8376kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
2000
0 0 1 1 4 4 6 7 6 7 10 10 12 12 14 15 14 15 18 19 19 21 18 21 24 24 26 27 26 27 30 30 32 32 34 34 36 37 38 39 39 41 37 38 36 41 46 47 48 47 48 51 51 53 54 54 56 56 58 58 60 61 61 63 64 64 66 67 66 67 70 71 72 72 74 75 76 76 75 74 70 77 63 60 77 85 85 87 87 89 89...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
175909322571
633257447922
815909942751
39651169609
1036267874610
610572524261
164360385196
32373687020
128373030516
267765616314

result:

ok 

Test #12:

score: 13
Accepted
time: 41ms
memory: 4000kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
2000
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 14 18 16 20 21 22 22 20 25 20 27 28 28 30 29 32 29 34 29 35 29 30 26 40 41 42 41 44 45 46 47 48 49 48 49 49 53 54 54 48 52 55 59 59 61 61 50 64 65 66 64 66 69 70 51 72 72 73 75 76 77 77 78 74 81 82 73 84 74 76 87 87 89 90...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
127351551273446
392923435722048
219438171765380
32284843571130
53163787789189
51772420152188
31965916042830
76059397524120
296729960017452
261260002258578

result:

ok 

Test #13:

score: 13
Accepted
time: 40ms
memory: 3932kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
2000
0 1 2 3 4 5 6 7 8 9 10 10 10 13 14 15 16 15 13 16 17 18 22 22 23 25 25 25 20 29 29 31 32 33 31 35 35 37 38 38 37 41 38 43 43 42 42 47 37 49 45 51 49 52 54 55 55 56 58 59 56 61 54 52 36 58 54 67 67 69 69 71 69 73 73 72 76 74 78 79 80 81 82 83 84 80 84 87 88 89 84...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
42214045518871
72831432357696
590641773997148
38954091559748
2020663055796
127157852441461
181696136766832
72411040396563
494394810335232
267249207833336

result:

ok 

Test #14:

score: 13
Accepted
time: 41ms
memory: 4260kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
2000
0 1 2 3 4 5 6 7 7 7 10 11 11 13 12 15 15 15 15 17 20 21 22 23 21 16 19 23 28 29 30 31 31 31 34 23 36 37 33 23 40 41 42 42 42 43 44 40 48 44 50 51 44 53 46 55 56 47 29 59 60 60 62 62 60 65 63 67 67 69 70 71 52 73 56 75 75 63 78 78 69 81 53 83 51 85 86 87 88 89 86...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
490569818687703
477532014938406
61048882143162
83562557160256
118962344093912
133474637540285
98164499179712
19997276317472
15208959930634
62292505319353

result:

ok 

Test #15:

score: 13
Accepted
time: 41ms
memory: 4068kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
2000
0 1 2 3 4 4 6 7 7 9 7 11 12 12 13 15 16 17 17 18 20 21 21 23 8 25 26 26 28 29 29 31 31 33 34 35 36 34 38 31 34 36 42 43 44 45 46 46 34 49 50 51 52 53 54 54 54 55 58 59 56 51 60 56 57 65 66 65 49 69 70 71 66 73 74 75 76 75 78 79 78 81 75 83 83 85 84 67 88 88 90 8...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
190697287624219
53603131790026
103217577508362
19182529285386
541772654508376
202493818900847
40634954006094
98609882258122
291520925855683
247847606357154

result:

ok 

Test #16:

score: 13
Accepted
time: 41ms
memory: 8040kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
2000
0 1 2 3 4 5 4 5 8 6 10 10 4 8 14 15 7 17 18 18 14 20 15 23 24 24 25 27 27 29 27 30 32 23 33 26 36 37 36 32 24 33 33 43 44 45 45 46 48 48 44 21 38 53 54 54 56 56 33 59 60 61 57 37 64 65 66 65 67 67 70 71 26 73 74 73 76 77 78 78 80 81 82 82 74 85 86 85 88 89 77 91...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
7160442129933
232054458731708
111366705782284
234235829126538
252870268102869
55380890925907
160283559337139
185137158761048
16739690866131
6714786196004

result:

ok 

Test #17:

score: 13
Accepted
time: 35ms
memory: 3900kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
2000
0 0 2 3 4 4 6 6 8 9 9 11 12 13 12 15 15 10 11 19 20 13 18 10 24 25 25 8 28 29 29 31 31 33 28 35 36 35 36 39 38 41 37 30 44 23 41 23 37 24 50 50 33 44 19 55 55 38 58 3 60 61 62 63 64 65 66 64 68 69 69 62 72 73 74 75 74 75 77 73 80 81 81 61 84 85 86 87 88 88 68 91...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
209059603741141
179481179940217
320133949987194
389284374280293
3450473671431
24432829075090
2164055762728
19957133648605
36369151512141
394914390055062

result:

ok 

Test #18:

score: 13
Accepted
time: 36ms
memory: 3928kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
2000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
2405489897539184
2586868257938796
2702940400172773
2629907237390536
2640721392702080
2578972752495714
2727743433629036
2570186048325034
2632300904480169
2266718396003546

result:

ok 

Subtask #3:

score: 0
Time Limit Exceeded

Dependency #2:

100%
Accepted

Test #19:

score: 0
Time Limit Exceeded

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
60000
0 0 2 3 2 3 4 4 8 8 10 11 12 12 14 15 10 15 18 18 20 20 11 14 22 22 26 27 26 27 30 30 32 32 34 35 35 37 34 37 40 41 40 41 44 44 45 45 48 49 49 51 51 53 48 53 56 56 58 58 60 60 62 63 63 65 66 66 68 68 69 69 72 62 65 72 76 76 78 78 80 81 81 83 84 85 80 83 85 89 9...

output:


result:


Subtask #4:

score: 7
Accepted

Test #33:

score: 7
Accepted
time: 49ms
memory: 28888kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 0 1 2 2 6 6 7 7 10 11 11 13 14 13 14 17 10 17 20 21 22 22 23 21 20 23 28 29 28 29 32 33 34 32 33 34 38 39 39 40 42 42 44 45 46 47 48 45 46 48 52 53 53 54 56 56 58 58 60 61 62 63 63 65 61 66 62 66 70 71 71 72 72 75 60 65 75 79 52 44 70 47 40 54 79 87 87 89 ...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
18330254280
114566555886
5123993634
1571790384
1390661403
102887513647
12142338294
532135751
48879256279
74804356884
7047438873
58553215238
26812191362
41269971650
32111371952
8116162880
57784940023
106724111433
93322831828
42829869427
28126687591
28123313538
1525...

result:

ok 

Test #34:

score: 7
Accepted
time: 60ms
memory: 22024kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 21 20 23 25 25 27 28 29 29 30 32 33 33 22 36 33 34 39 39 40 42 43 44 45 39 47 48 49 50 51 52 52 54 51 56 57 58 59 60 60 61 62 59 61 66 67 68 63 70 71 68 58 61 75 76 77 66 73 80 60 60 83 83 58 86 87 86 89 ...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
50233536385
3587514281
5880195973
137570322832
29902093191
26550751346
32639328031
66964630751
25701201292
103130504357
54417568193
90440614687
29659144821
30382916893
3188471716
14164945825
46749986071
1254071200
57249463618
32639228784
26502847608
103554150130
1...

result:

ok 

Test #35:

score: 7
Accepted
time: 40ms
memory: 21956kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 13 16 17 18 19 20 20 22 22 22 24 25 22 28 29 29 29 32 32 32 35 35 37 38 39 38 21 17 41 44 45 30 47 48 48 49 51 52 52 54 55 55 55 50 59 55 54 62 63 64 62 62 64 67 62 59 51 72 73 74 75 76 75 56 79 80 81 80 82 82 85 82 87 88 55 ...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
44679405666
7344895774
71198961182
21219279009
50500461174
7095602694
60932721243
137763754969
17105320274
37016931183
21667892444
8839528376
77671688743
31024367232
89840380380
4873771465
14736820809
142327968181
115923386349
32203682223
9608934637
87739160313
21...

result:

ok 

Test #36:

score: 7
Accepted
time: 60ms
memory: 21944kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 12 10 16 18 19 20 21 22 23 24 25 25 23 28 29 29 31 32 31 32 35 36 37 37 38 40 41 41 35 44 22 46 21 48 49 50 51 23 48 50 32 56 57 58 58 60 61 32 63 9 65 46 62 68 12 42 71 72 73 40 75 63 77 14 79 79 81 82 82 82 82 30 76 88 89 9...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
5521438976
15261272599
10728067067
3645164128
23856372857
446697418
929867368
12088150858
30035383256
7293473665
4359793115
40865552617
55353413089
7616895721
34148444820
2529872987
53772209472
39426040232
3895610150
712023248
5474833320
2807877401
21416591895
366...

result:

ok 

Test #37:

score: 7
Accepted
time: 48ms
memory: 21904kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 1 2 4 5 6 7 8 9 8 7 11 13 14 14 16 17 17 18 20 14 19 23 24 24 26 27 26 29 30 31 29 25 34 34 35 37 32 39 40 41 42 43 42 43 45 46 48 48 49 51 51 51 43 55 55 57 58 58 44 55 39 60 64 64 44 67 68 69 68 71 72 19 74 27 9 77 78 79 80 80 82 83 84 85 86 85 86 89 90 ...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
38153302526
130097547239
52388680982
69184293541
80459218361
14724080527
866710368
18319226622
80908501410
23324019935
32743579203
16938672359
5934264863
52906244180
23716977699
45587337949
14483777583
2954757299
19498267405
24049176238
9117766559
5805218194
21070...

result:

ok 

Test #38:

score: 7
Accepted
time: 47ms
memory: 24320kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 2 3 4 5 6 0 8 8 10 11 12 9 14 15 16 17 18 19 20 21 7 23 24 25 26 27 28 29 30 31 32 33 34 35 22 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
307705295
740817932
103016
93590629
636968552
4207234
494349851
813091070
510525363
215228314
109359791
1042526314
759568979
271550316
293772874
1144161018
4572297
637369864
459711939
148096492
103770009
853464064
22376976
676525710
84286852
399680890
775723872
12...

result:

ok 

Test #39:

score: 7
Accepted
time: 52ms
memory: 21236kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 2 3 4 2 4 7 8 8 10 10 12 13 14 15 16 17 15 16 20 21 22 21 24 18 26 13 28 19 30 14 32 33 34 35 35 37 33 39 40 41 41 26 32 45 46 47 30 49 50 31 52 52 18 55 55 36 48 48 19 49 62 62 31 65 11 67 68 68 9 71 72 73 74 75 76 77 78 78 76 81 82 82 71 36 39 87 88 87 9...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
17606249861
36754536423
31398535922
126896299427
75536620971
124572494315
61770969257
36419022307
25719602834
21613762047
19587768771
90018339815
32518184788
37664052696
132681842175
33458876552
10232954134
55087303729
27438862203
44821277009
63256973538
470954133...

result:

ok 

Test #40:

score: 7
Accepted
time: 40ms
memory: 15152kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
96203127179
56234228902
33659229298
20054091922
292186192729
55908093901
136507199146
37505723434
132422932602
44038197362
134790779646
279535770445
79001683916
226259989838
4703942916
48668597404
166838756150
7495535255
287482795199
38180299940
258644451531
31204...

result:

ok 

Subtask #5:

score: 0
Wrong Answer

Dependency #4:

100%
Accepted

Test #41:

score: 0
Wrong Answer
time: 73ms
memory: 20116kb

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 1 1 1 5 5 5 8 8 10 1 10 13 13 13 16 16 18 19 20 21 21 22 24 21 22 21 21 22 20 19 18 21 19 24 36 36 38 38 40 41 40 41 44 45 45 45 44 45 50 50 50 51 54 55 55 54 44 50 55 61 62 16 38 19 45 40 54 18 8 54 62 73 73 75 76 76 76 79 80 80 75 80 75 80 80 87 87 87 90...

output:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
44400737360
30573160400
105642732800
69749334000
9155768880
20294930480
17837086800
226229200
17551743840
76597845200
29367351760
111099269040
73063486720
23563977440
44265840320
6740649600
879142080
15850612320
10846954720
4085293120
19931422880
14456396080
93563...

result:

wrong answer 3rd lines differ - on the 1st token, expected: '37308016868', found: '44400737360'

Subtask #6:

score: 0
Time Limit Exceeded

Test #47:

score: 0
Time Limit Exceeded

input:

ZYKrr4gCMcKeyfk6kbZU5k4ZyW3sAGT0
200000
0 1 0 1 4 5 5 7 7 9 9 11 12 13 13 11 14 12 14 19 20 19 20 23 24 25 26 26 28 28 30 31 32 33 33 35 35 30 32 31 37 41 42 43 24 44 46 46 48 49 50 51 51 53 54 55 55 56 56 48 50 54 44 59 49 25 59 67 68 67 68 71 71 72 72 75 76 76 78 79 80 37 80 83 83 85 86 85 79 41 8...

output:


result:


Subtask #7:

score: 0
Skipped

Dependency #1:

0%