QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#555919#9238. Treebachbeo20070 63ms39304kbC++231.4kb2024-09-10 12:30:532024-09-10 12:30:53

Judging History

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

  • [2024-09-10 12:30:53]
  • 评测
  • 测评结果:0
  • 用时:63ms
  • 内存:39304kb
  • [2024-09-10 12:30:53]
  • 提交

answer

#include "tree.h"
#include<bits/stdc++.h>
using namespace std;
using i32 = int;
#define int long long
const int maxn = 2e5+5;
const int inf = 1e6;

vector<pair<int,int>> val;
int n,p[maxn],w[maxn],total;
vector<int> edge[maxn];

int par[maxn],d[maxn],pos[maxn];
void init(std::vector<i32> P, std::vector<i32> W) {
  n = (int)P.size();
  vector<pair<int,int>> X;
  for(int i=0;i<n;i++){
    p[i]=P[i],w[i]=W[i];
    X.push_back({w[i],i});
  }
  for(int i=1;i<n;i++){
    d[p[i]]++;
    edge[p[i]].push_back(i);
    edge[i].push_back(p[i]);
  }
  for(int i=0;i<n;i++) if(!d[i]) d[i]++,total+=w[i];
  sort(X.begin(),X.end());
  memset(par,-1,sizeof(par));
  function<int(int)> findpar = [&](int u){
    if(u!=par[u]) return par[u]=findpar(par[u]);
    return u;
  };
  while(!X.empty()){
    auto [x,u]=X.back();X.pop_back();
    par[u]=u;
    for(int v:edge[u]) if(par[v]!=-1){
      v=findpar(v);par[v]=u;d[u]+=d[v]-1;
      val.push_back({d[v],d[v]*(pos[v]-x)});
    }
    pos[u]=x;
  }
  int u=findpar(1);
  val.push_back({d[u],d[u]*pos[u]});
  sort(val.begin(),val.end());
  for(int i=(int)val.size()-2;i>=0;i--) val[i].second+=val[i+1].second;
}

int query(i32 _L, i32 _R) {
  int L=_L,R=_R;
  int x=upper_bound(val.begin(),val.end(),make_pair(R/L,inf))-val.begin();
  int res=L*total;
  if(x<(int)val.size()) res+=L*val[x].second-R*((int)val.size()-x);
  return res;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 53ms
memory: 34776kb

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
1030500043536
1267388225950
158401102870
950661141462
872050339856
1900660591896
1980730737824
633815494998
554604923396
1980114407552

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #11:

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

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
270514345051
972590144038
1256231246811
60475534322
1593983734294
930393989728
250541689238
49246607242
195469872090
409713117526

result:

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

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #33:

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

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
-78562393152
16182776028
532515372
333380064
-1468842426
7596999566
-35633659836
-781275194
10274814578
-22749256056
-744826062
-42352505636
-23384946944
-39917664908
-62116293272
-43988271320
-59251195270
-1321788942
2719196804
-45944590354
-6579641626
-827946981...

result:

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

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Wrong Answer

Test #47:

score: 0
Wrong Answer
time: 44ms
memory: 39304kb

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
63798323394
63659403542
64765925583
64741664099
63639869728
63996596000
64309717473
64171611811
64502137617
63556674659
63777876972
63889814937
63558276636
64720521861
64131229872
64510062540
63708583604
64737434836
64361824611
65235089924
64341799907
64299241247
...

result:

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

Subtask #7:

score: 0
Skipped

Dependency #1:

0%