// incorrect/agustin-dual-vneg.cpp
#include "tree.h"
#include <vector>
using namespace std;
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) for(int i=int(n)-1;i>=0;i--)
#define dforsn(i,s,n) for(int i=int(n)-1;i>=int(s);i--)
#define SIZE(c) int((c).size())
const int INF = 1000000000;
vector<long long> sumCapL, sumCapR;
long long leafWeights;
int N;
void init(vector<int> P, vector<int> W) {
N = SIZE(P);
vector<int> minNonLeafInSubtree(N, INF);
vector<int> leavesInSubtree(N, 0);
vector<bool> leaf(N, true);
leafWeights = 0;
dforn(i,N)
{
if (leaf[i])
{
leafWeights += W[i];
leavesInSubtree[i]++;
}
else
minNonLeafInSubtree[i] = min(minNonLeafInSubtree[i], W[i]);
if (i > 0)
{
leaf[P[i]] = false;
minNonLeafInSubtree[P[i]] = min(minNonLeafInSubtree[P[i]], minNonLeafInSubtree[i]);
leavesInSubtree[P[i]] += leavesInSubtree[i];
}
}
vector<long long> capByLeafCount(N+1, 0);
forn(i,N)
if (!leaf[i])
{
int parentMin = i == 0 ? 0 : minNonLeafInSubtree[P[i]];
capByLeafCount[leavesInSubtree[i]] += minNonLeafInSubtree[i] - parentMin;
}
sumCapL = sumCapR = vector<long long>(N+2, 0);
dforn(i,N+1)
{
sumCapR[i] = sumCapR[i+1] - capByLeafCount[i];
sumCapL[i] = sumCapL[i+1] + i * capByLeafCount[i];
}
}
long long query(int L, int R) {
int k = min(N+1, (R+L-1)/L);
return leafWeights * L + sumCapL[k] * L + sumCapR[k] * R;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
9808 KB |
Output is correct |
2 |
Correct |
26 ms |
9664 KB |
Output is correct |
3 |
Correct |
31 ms |
9772 KB |
Output is correct |
4 |
Correct |
35 ms |
9812 KB |
Output is correct |
5 |
Correct |
58 ms |
9652 KB |
Output is correct |
6 |
Correct |
30 ms |
9820 KB |
Output is correct |
7 |
Correct |
34 ms |
9668 KB |
Output is correct |
8 |
Correct |
34 ms |
9808 KB |
Output is correct |
9 |
Correct |
35 ms |
9812 KB |
Output is correct |
10 |
Correct |
27 ms |
9812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
10440 KB |
Output is correct |
2 |
Correct |
52 ms |
10456 KB |
Output is correct |
3 |
Correct |
53 ms |
10580 KB |
Output is correct |
4 |
Correct |
53 ms |
10576 KB |
Output is correct |
5 |
Correct |
49 ms |
10576 KB |
Output is correct |
6 |
Correct |
50 ms |
10580 KB |
Output is correct |
7 |
Correct |
51 ms |
10580 KB |
Output is correct |
8 |
Correct |
45 ms |
10576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
10440 KB |
Output is correct |
2 |
Correct |
52 ms |
10456 KB |
Output is correct |
3 |
Correct |
53 ms |
10580 KB |
Output is correct |
4 |
Correct |
53 ms |
10576 KB |
Output is correct |
5 |
Correct |
49 ms |
10576 KB |
Output is correct |
6 |
Correct |
50 ms |
10580 KB |
Output is correct |
7 |
Correct |
51 ms |
10580 KB |
Output is correct |
8 |
Correct |
45 ms |
10576 KB |
Output is correct |
9 |
Incorrect |
51 ms |
10584 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
9808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
38 ms |
9808 KB |
Output is correct |
3 |
Correct |
26 ms |
9664 KB |
Output is correct |
4 |
Correct |
31 ms |
9772 KB |
Output is correct |
5 |
Correct |
35 ms |
9812 KB |
Output is correct |
6 |
Correct |
58 ms |
9652 KB |
Output is correct |
7 |
Correct |
30 ms |
9820 KB |
Output is correct |
8 |
Correct |
34 ms |
9668 KB |
Output is correct |
9 |
Correct |
34 ms |
9808 KB |
Output is correct |
10 |
Correct |
35 ms |
9812 KB |
Output is correct |
11 |
Correct |
27 ms |
9812 KB |
Output is correct |
12 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |