QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#799165#9238. Treecocoa_chan7 72ms123216kbC++142.5kb2024-12-04 23:58:432024-12-04 23:58:44

Judging History

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

  • [2024-12-04 23:58:44]
  • 评测
  • 测评结果:7
  • 用时:72ms
  • 内存:123216kb
  • [2024-12-04 23:58:43]
  • 提交

answer

#include "tree.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mx=1000000;
ll n,m,i,j,k,l,r,x,y,z,w,s,t,a[1100000],par[1100000],pr[1100000],leaf[1100000],leftsum[1100000],rightsum[1100000],good[1100000],c[1100000],chk[1100000],h[1100000],created[1100000];
ll lf;
vector<ll> v[1100000],u[1100000];
ll f(ll x)
{
    if(par[x]==x)
        return x;
    par[x]=f(par[x]);
    return par[x];
}
void g(ll x,ll y)
{
    x=f(x);
    y=f(y);
    if(x==y)
        return;
    if(h[x]>h[y])
    {
        swap(x,y);
    }
    h[y]+=h[x];
    par[x]=y;
    leaf[y]+=leaf[x];
}
void add(ll u,ll c)
{
    //printf("(%lld,%lld)\n",u,c);
    leftsum[u]+=c*u;
    rightsum[u]+=c;
}
void add_edge(ll x,ll y)
{
    if(pr[x]!=y)
        swap(x,y);
    leaf[f(y)]-=good[y];
    good[y]=0;
    leaf[f(y)]+=good[y];
}
void connect(ll x,ll t)
{
    ll i,s=1;
    for(i=0;i<v[x].size();i++)
    {
        if(chk[v[x][i]])
        {
            add(leaf[f(v[x][i])],created[f(v[x][i])]-t);
            add_edge(v[x][i],x);
        }
    }
    for(i=0;i<v[x].size();i++)
    {
        if(chk[v[x][i]])
        g(x,v[x][i]);
    }
    x=f(x);
    created[x]=t;

}
ll dfs1(ll x,ll y)
{
    ll i,s=0,z=1;
    pr[x]=y;
    for(i=0;i<v[x].size();i++)
    {
        if(v[x][i]==y)
            continue;
        z=0;
        s+=dfs1(v[x][i],x);
    }
    s+=z;
    return s;
}
void init(std::vector<int> P, std::vector<int> W) {
  n = (int)P.size();
  for(i=1;i<n;i++)
  {
      x=i+1;
      y=P[i]+1;
      v[x].push_back(y);
      v[y].push_back(x);
  }
  for(i=1;i<=n;i++)
  {
      h[i]=1;
      par[i]=i;
      good[i]=1;
  }
  for(i=0;i<n;i++)
  {
      a[i+1]=W[i];
  }
  lf=dfs1(1,0);
  for(i=1;i<=n;i++)
  {
      u[a[i]].push_back(i);
  }
  for(i=1000000;i>=1;i--)
  {
      for(auto xx:u[i])
      {
          chk[xx]=1;
          created[xx]=i;
          leaf[xx]=1;
          connect(xx,i);
      }
  }
  for(i=1;i<=n;i++)
  {
      if(chk[i]==0)
        continue;
      x=f(i);
      if(c[x])
        continue;
      c[x]=1;
      good[x]=1;
      add(leaf[x],created[x]);
  }
  for(i=1;i<=1000000;i++)
  {
      leftsum[i]+=leftsum[i-1];
      rightsum[i]+=rightsum[i-1];
  }
}

long long query(int L, int R) {
  l=L;
  r=R;
  s=l*lf;
  x=(r+l-1)/l;
  //printf("(%lld)",x);
  s+=(leftsum[mx]-leftsum[x-1])*l;
  s-=(rightsum[mx]-rightsum[x-1])*r;
  return s;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 63ms
memory: 123216kb

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:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
110650345646
130054343385
16107276665
98340644517
94219033746
192269609316
206121078094
65836459693
57716014096
202011831262

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 0ms
memory: 87724kb

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
16472023052
60606122910
74860349620
4176586465
96796298036
64809195227
17394170866
3526079084
13762573500
27241215430

result:

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

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 7
Accepted

Test #33:

score: 7
Accepted
time: 58ms
memory: 119956kb

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: 72ms
memory: 112484kb

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: 56ms
memory: 110872kb

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: 71ms
memory: 113036kb

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: 67ms
memory: 110908kb

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: 111720kb

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: 71ms
memory: 111452kb

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: 60ms
memory: 113480kb

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: 71ms
memory: 116932kb

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
48172261217
34052537549
123982708517
81195851500
9259744652
22195764611
19804967274
235818747
19198710648
86443493692
33074386652
130098955887
85324664350
26942822957
47687355815
6746967494
878640000
17394104427
10880038834
4084341863
22607121448
16204784090
99305...

result:

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

Subtask #6:

score: 0
Wrong Answer

Test #47:

score: 0
Wrong Answer
time: 47ms
memory: 121724kb

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:

11XNDQnkdGXK8y3iaqfMvWKu4vqrBbz1
OK
4381111009
4194259594
5772382531
5737167287
4161703172
4656839430
5090703534
4906917696
5379257525
4042561710
4353836689
4503808097
4045565659
5703239760
4846078199
5391716189
4259460619
5730882626
5169925364
6476407120
5140199251
5072775182
5216414761
4760832275
...

result:

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

Subtask #7:

score: 0
Skipped

Dependency #1:

0%