# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
1104950 |
2024-10-24T21:55:55 Z |
jerzyk |
트리 (IOI24_tree) |
C++17 |
|
145 ms |
58920 KB |
#include <bits/stdc++.h>
#include "tree.h"
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 2 * 1000 * 1000 * 1000;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
const int N = 1<<18;
int drz[2 * N];
vector<int> aktv;
int pre[N], pos[N], rev[N];
ll wei[N];
ll inc[N * 5], sum[N * 5];
int il[N];
vector<int> ed[N];
void Change(int v, int x)
{
v += N;
drz[v] = x;
v /= 2;
while(v > 0)
{
drz[v] = max(drz[v * 2], drz[v * 2 + 1]);
v /= 2;
}
}
void Find(int v, int p, int k, int pz, int kz, int x)
{
if(drz[v] <= x) return;
if(p > kz || k < pz) return;
if(v >= N)
{
drz[v] = -1;
aktv.pb(rev[v - N]);
return;
}
Find(v * 2, p, (p + k) / 2, pz, kz, x);
Find(v * 2 + 1, (p + k) / 2 + 1, k, pz, kz, x);
drz[v] = max(drz[v * 2], drz[v * 2 + 1]);
}
bool C(int a, int b)
{
return (wei[a] > wei[b]);
}
void DFS(int v, int &cnt)
{
++cnt; rev[cnt] = v; pre[v] = cnt; pos[v] = cnt;
il[v] = max(0, (int)ed[v].size() - 1);
Change(pre[v], wei[v]);
if(ed[v].size() == 0)
sum[0] += wei[v];
else
sum[0] += (ll)il[v] * wei[v];
//cerr << "DFS: " << v << " " << wei[v] << "\n";
for(int i = 0; i < (int)ed[v].size(); ++i)
{
DFS(ed[v][i], cnt);
pos[v] = pos[ed[v][i]];
Find(1, 0, N - 1, pre[ed[v][i]], pos[ed[v][i]], wei[v]);
sort(aktv.begin(), aktv.end(), C);
int s = 0;
for(int j = 0; j < (int)aktv.size(); ++j)
{
int ne = aktv[j];
//cout << "R: " << v << " " << ne << "\n";
inc[1 + s] += wei[v] - wei[ne];
inc[1 + s + il[ne]] -= wei[v] - wei[ne];
s += il[ne];
}
aktv.clear();
il[v] += s;
}
}
void init(vector<int> P, vector<int> W)
{
for(int i = 1; i < 2 * N; ++i) drz[i] = -1;
int n = (int)P.size() + 1;
for(int i = 1; i < (int)P.size(); ++i)
ed[P[i] + 1].pb(i + 1);
for(int i = 0; i < n; ++i)
wei[i + 1] = W[i];
ed[0].pb(1);
int xd = 0;
DFS(0, xd);
for(int i = 1; i <= 1000'000; ++i)
inc[i] += inc[i - 1];
for(int i = 1; i <= 1000'000; ++i)
sum[i] = sum[i - 1] + inc[i - 1];
}
long long query(int L, int R)
{
ll ans = sum[R / L] * (ll)L + inc[R / L] * (ll)(R % L);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
34384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
53444 KB |
Output is correct |
2 |
Correct |
73 ms |
55896 KB |
Output is correct |
3 |
Correct |
95 ms |
48460 KB |
Output is correct |
4 |
Correct |
94 ms |
44616 KB |
Output is correct |
5 |
Correct |
91 ms |
44652 KB |
Output is correct |
6 |
Correct |
67 ms |
44664 KB |
Output is correct |
7 |
Correct |
97 ms |
44624 KB |
Output is correct |
8 |
Correct |
110 ms |
44616 KB |
Output is correct |
9 |
Correct |
103 ms |
43856 KB |
Output is correct |
10 |
Correct |
76 ms |
40708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
34640 KB |
Output is correct |
2 |
Correct |
10 ms |
34336 KB |
Output is correct |
3 |
Correct |
10 ms |
34412 KB |
Output is correct |
4 |
Correct |
10 ms |
34384 KB |
Output is correct |
5 |
Correct |
10 ms |
34384 KB |
Output is correct |
6 |
Correct |
10 ms |
34384 KB |
Output is correct |
7 |
Correct |
10 ms |
34384 KB |
Output is correct |
8 |
Correct |
9 ms |
34416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
34640 KB |
Output is correct |
2 |
Correct |
10 ms |
34336 KB |
Output is correct |
3 |
Correct |
10 ms |
34412 KB |
Output is correct |
4 |
Correct |
10 ms |
34384 KB |
Output is correct |
5 |
Correct |
10 ms |
34384 KB |
Output is correct |
6 |
Correct |
10 ms |
34384 KB |
Output is correct |
7 |
Correct |
10 ms |
34384 KB |
Output is correct |
8 |
Correct |
9 ms |
34416 KB |
Output is correct |
9 |
Correct |
39 ms |
41164 KB |
Output is correct |
10 |
Correct |
43 ms |
41448 KB |
Output is correct |
11 |
Correct |
37 ms |
40644 KB |
Output is correct |
12 |
Correct |
37 ms |
40784 KB |
Output is correct |
13 |
Correct |
35 ms |
39776 KB |
Output is correct |
14 |
Correct |
36 ms |
39880 KB |
Output is correct |
15 |
Correct |
33 ms |
37180 KB |
Output is correct |
16 |
Correct |
33 ms |
37200 KB |
Output is correct |
17 |
Correct |
37 ms |
37588 KB |
Output is correct |
18 |
Correct |
34 ms |
37200 KB |
Output is correct |
19 |
Correct |
33 ms |
37200 KB |
Output is correct |
20 |
Correct |
33 ms |
36936 KB |
Output is correct |
21 |
Correct |
35 ms |
37324 KB |
Output is correct |
22 |
Correct |
34 ms |
36428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
55160 KB |
Output is correct |
2 |
Correct |
84 ms |
43936 KB |
Output is correct |
3 |
Correct |
90 ms |
44028 KB |
Output is correct |
4 |
Correct |
96 ms |
43940 KB |
Output is correct |
5 |
Correct |
84 ms |
44020 KB |
Output is correct |
6 |
Correct |
84 ms |
46236 KB |
Output is correct |
7 |
Correct |
82 ms |
43260 KB |
Output is correct |
8 |
Correct |
70 ms |
41004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
55160 KB |
Output is correct |
2 |
Correct |
84 ms |
43936 KB |
Output is correct |
3 |
Correct |
90 ms |
44028 KB |
Output is correct |
4 |
Correct |
96 ms |
43940 KB |
Output is correct |
5 |
Correct |
84 ms |
44020 KB |
Output is correct |
6 |
Correct |
84 ms |
46236 KB |
Output is correct |
7 |
Correct |
82 ms |
43260 KB |
Output is correct |
8 |
Correct |
70 ms |
41004 KB |
Output is correct |
9 |
Correct |
105 ms |
46888 KB |
Output is correct |
10 |
Correct |
100 ms |
46120 KB |
Output is correct |
11 |
Correct |
129 ms |
46168 KB |
Output is correct |
12 |
Correct |
101 ms |
46120 KB |
Output is correct |
13 |
Correct |
107 ms |
48332 KB |
Output is correct |
14 |
Correct |
103 ms |
45352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
54156 KB |
Output is correct |
2 |
Correct |
117 ms |
48168 KB |
Output is correct |
3 |
Correct |
125 ms |
46828 KB |
Output is correct |
4 |
Correct |
120 ms |
46684 KB |
Output is correct |
5 |
Correct |
118 ms |
46632 KB |
Output is correct |
6 |
Correct |
145 ms |
46800 KB |
Output is correct |
7 |
Correct |
135 ms |
46632 KB |
Output is correct |
8 |
Correct |
116 ms |
48936 KB |
Output is correct |
9 |
Correct |
125 ms |
45936 KB |
Output is correct |
10 |
Correct |
120 ms |
45864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
34384 KB |
Output is correct |
2 |
Correct |
95 ms |
53444 KB |
Output is correct |
3 |
Correct |
73 ms |
55896 KB |
Output is correct |
4 |
Correct |
95 ms |
48460 KB |
Output is correct |
5 |
Correct |
94 ms |
44616 KB |
Output is correct |
6 |
Correct |
91 ms |
44652 KB |
Output is correct |
7 |
Correct |
67 ms |
44664 KB |
Output is correct |
8 |
Correct |
97 ms |
44624 KB |
Output is correct |
9 |
Correct |
110 ms |
44616 KB |
Output is correct |
10 |
Correct |
103 ms |
43856 KB |
Output is correct |
11 |
Correct |
76 ms |
40708 KB |
Output is correct |
12 |
Correct |
10 ms |
34640 KB |
Output is correct |
13 |
Correct |
10 ms |
34336 KB |
Output is correct |
14 |
Correct |
10 ms |
34412 KB |
Output is correct |
15 |
Correct |
10 ms |
34384 KB |
Output is correct |
16 |
Correct |
10 ms |
34384 KB |
Output is correct |
17 |
Correct |
10 ms |
34384 KB |
Output is correct |
18 |
Correct |
10 ms |
34384 KB |
Output is correct |
19 |
Correct |
9 ms |
34416 KB |
Output is correct |
20 |
Correct |
39 ms |
41164 KB |
Output is correct |
21 |
Correct |
43 ms |
41448 KB |
Output is correct |
22 |
Correct |
37 ms |
40644 KB |
Output is correct |
23 |
Correct |
37 ms |
40784 KB |
Output is correct |
24 |
Correct |
35 ms |
39776 KB |
Output is correct |
25 |
Correct |
36 ms |
39880 KB |
Output is correct |
26 |
Correct |
33 ms |
37180 KB |
Output is correct |
27 |
Correct |
33 ms |
37200 KB |
Output is correct |
28 |
Correct |
37 ms |
37588 KB |
Output is correct |
29 |
Correct |
34 ms |
37200 KB |
Output is correct |
30 |
Correct |
33 ms |
37200 KB |
Output is correct |
31 |
Correct |
33 ms |
36936 KB |
Output is correct |
32 |
Correct |
35 ms |
37324 KB |
Output is correct |
33 |
Correct |
34 ms |
36428 KB |
Output is correct |
34 |
Correct |
95 ms |
55160 KB |
Output is correct |
35 |
Correct |
84 ms |
43936 KB |
Output is correct |
36 |
Correct |
90 ms |
44028 KB |
Output is correct |
37 |
Correct |
96 ms |
43940 KB |
Output is correct |
38 |
Correct |
84 ms |
44020 KB |
Output is correct |
39 |
Correct |
84 ms |
46236 KB |
Output is correct |
40 |
Correct |
82 ms |
43260 KB |
Output is correct |
41 |
Correct |
70 ms |
41004 KB |
Output is correct |
42 |
Correct |
105 ms |
46888 KB |
Output is correct |
43 |
Correct |
100 ms |
46120 KB |
Output is correct |
44 |
Correct |
129 ms |
46168 KB |
Output is correct |
45 |
Correct |
101 ms |
46120 KB |
Output is correct |
46 |
Correct |
107 ms |
48332 KB |
Output is correct |
47 |
Correct |
103 ms |
45352 KB |
Output is correct |
48 |
Correct |
119 ms |
54156 KB |
Output is correct |
49 |
Correct |
117 ms |
48168 KB |
Output is correct |
50 |
Correct |
125 ms |
46828 KB |
Output is correct |
51 |
Correct |
120 ms |
46684 KB |
Output is correct |
52 |
Correct |
118 ms |
46632 KB |
Output is correct |
53 |
Correct |
145 ms |
46800 KB |
Output is correct |
54 |
Correct |
135 ms |
46632 KB |
Output is correct |
55 |
Correct |
116 ms |
48936 KB |
Output is correct |
56 |
Correct |
125 ms |
45936 KB |
Output is correct |
57 |
Correct |
120 ms |
45864 KB |
Output is correct |
58 |
Correct |
145 ms |
58920 KB |
Output is correct |
59 |
Correct |
124 ms |
58276 KB |
Output is correct |
60 |
Correct |
114 ms |
48184 KB |
Output is correct |
61 |
Correct |
124 ms |
52776 KB |
Output is correct |
62 |
Correct |
126 ms |
47728 KB |
Output is correct |
63 |
Correct |
145 ms |
48496 KB |
Output is correct |
64 |
Correct |
116 ms |
47668 KB |
Output is correct |
65 |
Correct |
121 ms |
47656 KB |
Output is correct |
66 |
Correct |
132 ms |
47668 KB |
Output is correct |
67 |
Correct |
126 ms |
47656 KB |
Output is correct |
68 |
Correct |
116 ms |
49916 KB |
Output is correct |
69 |
Correct |
129 ms |
47148 KB |
Output is correct |
70 |
Correct |
120 ms |
45864 KB |
Output is correct |
71 |
Correct |
95 ms |
44772 KB |
Output is correct |