# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1105446 |
2024-10-26T12:38:43 Z |
LaMatematica14 |
Nile (IOI24_nile) |
C++17 |
|
126 ms |
34924 KB |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1<<18;
vector<int> par(1e6);
int fr(int a) {
if (a == par[a]) return a;
return par[a] = fr(par[a]);
}
void unite(int a, int b) {
if (fr(a) == fr(b)) return;
par[par[a]] = b;
}
long long qq(int a, int l, int r, int lq, int rq, vector<long long> &s) {
if (l >= lq && r <= rq) return s[a];
int m = (l+r)/2;
long long p = 1000000000LL;
if (m > lq) p = min(p, qq(a<<1, l, m, lq, rq, s));
if (m < rq) p = min(p, qq(a<<1|1, m, r, lq, rq, s));
return p;
}
vector<long long> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
int N = W.size();
vector<array<long long, 3>> stt(N);
for (int i = 0; i < N; i++) stt[i] = {W[i], B[i], A[i]-B[i]};
sort(stt.begin(), stt.end());
int Q = E.size();
par.resize(N); iota(par.begin(), par.end(), 0);
vector<array<long long, 3>> od;
for (int i = 0; i < Q; i++) od.push_back({E[i], 3, i});
for (int i = 0; i < N-1; i++) {
if (i < N-2) od.push_back({stt[i+2][0]-stt[i][0], 2, i});
od.push_back({stt[i+1][0]-stt[i][0], 1, i});
}
sort(od.begin(), od.end());
vector<long long> mn(N, 1000000000LL); //pari, dispari, ci sono solo quelli centrali i bordi sono a mano
vector<long long> s(N);
for (int i = 0; i < N; i++) {
s[i] = stt[i][1]+stt[i][2];
}
vector<array<long long, 2>> infn(N);
for (int i = 0; i < N; i++) infn[i][0] = i;
for (int i = 0; i < N; i++) infn[i][1] = i+1;
vector<long long> sp(maxn<<1, 1000000000LL), sd(maxn<<1, 1000000000LL);
for (int i = 0; i < N; i+=2) sp[i+maxn] = stt[i][2];
for (int i = 1; i < N; i+=2) sd[i+maxn] = stt[i][2];
for (int i = maxn-1; i > 0; i--) {
sp[i] = min(sp[i<<1], sp[i<<1|1]);
sd[i] = min(sd[i<<1], sd[i<<1|1]);
}
vector<long long> ris(Q);
long long sum = 0;
for (int i = 0; i < N; i++) sum += A[i];
vector<long long> pr(N+1, 0);
for (int i = 1; i <= N; i++) pr[i] = pr[i-1]+stt[i-1][1];
for (int k = 0; k < od.size(); k++) {
array<long long, 3> att = od[k];
if (att[1] == 1) {
long long a = fr(att[2]), b = fr(att[2]+1);
sum -= s[a]; sum -= s[b];
mn[b] = min(mn[a], mn[b]);
infn[b] = {min(infn[a][0], infn[b][0]), max(infn[a][1], infn[b][1])};
s[b] = pr[infn[b][1]]-pr[infn[b][0]];
if ((infn[b][1]-infn[b][0])%2) {
long long md;
if (infn[b][0] % 2) md = qq(1, 0, maxn, infn[b][0], infn[b][1], sd);
else md = qq(1, 0, maxn, infn[b][0], infn[b][1], sp);
s[b] += min(mn[b], md);
}
sum += s[b];
unite(a, b);
}
else if (att[1] == 2) {
int r = fr(att[2]+1);
sum -= s[r];
mn[r] = min(mn[r], stt[att[2]+1][2]);
s[r] = pr[infn[r][1]]-pr[infn[r][0]];
if ((infn[r][1]-infn[r][0])%2) {
long long md;
if (infn[r][0] % 2) md = qq(1, 0, maxn, infn[r][0], infn[r][1], sd);
else md = qq(1, 0, maxn, infn[r][0], infn[r][1], sp);
s[r] += min(mn[r], md);
}
sum += s[r];
}
else ris[att[2]] = sum;
}
return ris;
}
Compilation message
nile.cpp: In function 'std::vector<long long int> calculate_costs(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
nile.cpp:64:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for (int k = 0; k < od.size(); k++) {
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12624 KB |
Output is correct |
2 |
Correct |
5 ms |
12880 KB |
Output is correct |
3 |
Correct |
5 ms |
12880 KB |
Output is correct |
4 |
Correct |
5 ms |
12880 KB |
Output is correct |
5 |
Correct |
5 ms |
12880 KB |
Output is correct |
6 |
Correct |
5 ms |
12880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
28180 KB |
Output is correct |
2 |
Correct |
66 ms |
30832 KB |
Output is correct |
3 |
Correct |
61 ms |
30648 KB |
Output is correct |
4 |
Correct |
78 ms |
30572 KB |
Output is correct |
5 |
Correct |
77 ms |
30648 KB |
Output is correct |
6 |
Correct |
62 ms |
30648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
27828 KB |
Output is correct |
2 |
Correct |
75 ms |
27836 KB |
Output is correct |
3 |
Correct |
76 ms |
27136 KB |
Output is correct |
4 |
Correct |
86 ms |
27312 KB |
Output is correct |
5 |
Correct |
73 ms |
27632 KB |
Output is correct |
6 |
Correct |
83 ms |
27332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12624 KB |
Output is correct |
2 |
Correct |
5 ms |
12880 KB |
Output is correct |
3 |
Correct |
5 ms |
12880 KB |
Output is correct |
4 |
Correct |
5 ms |
12880 KB |
Output is correct |
5 |
Correct |
5 ms |
12880 KB |
Output is correct |
6 |
Correct |
5 ms |
12880 KB |
Output is correct |
7 |
Correct |
5 ms |
12624 KB |
Output is correct |
8 |
Correct |
5 ms |
12880 KB |
Output is correct |
9 |
Correct |
5 ms |
12880 KB |
Output is correct |
10 |
Correct |
5 ms |
13060 KB |
Output is correct |
11 |
Correct |
6 ms |
12896 KB |
Output is correct |
12 |
Correct |
5 ms |
12880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12624 KB |
Output is correct |
2 |
Correct |
5 ms |
12880 KB |
Output is correct |
3 |
Correct |
5 ms |
12880 KB |
Output is correct |
4 |
Correct |
5 ms |
12880 KB |
Output is correct |
5 |
Correct |
5 ms |
12880 KB |
Output is correct |
6 |
Correct |
5 ms |
12880 KB |
Output is correct |
7 |
Correct |
60 ms |
28180 KB |
Output is correct |
8 |
Correct |
66 ms |
30832 KB |
Output is correct |
9 |
Correct |
61 ms |
30648 KB |
Output is correct |
10 |
Correct |
78 ms |
30572 KB |
Output is correct |
11 |
Correct |
77 ms |
30648 KB |
Output is correct |
12 |
Correct |
62 ms |
30648 KB |
Output is correct |
13 |
Correct |
66 ms |
27828 KB |
Output is correct |
14 |
Correct |
75 ms |
27836 KB |
Output is correct |
15 |
Correct |
76 ms |
27136 KB |
Output is correct |
16 |
Correct |
86 ms |
27312 KB |
Output is correct |
17 |
Correct |
73 ms |
27632 KB |
Output is correct |
18 |
Correct |
83 ms |
27332 KB |
Output is correct |
19 |
Correct |
5 ms |
12624 KB |
Output is correct |
20 |
Correct |
5 ms |
12880 KB |
Output is correct |
21 |
Correct |
5 ms |
12880 KB |
Output is correct |
22 |
Correct |
5 ms |
13060 KB |
Output is correct |
23 |
Correct |
6 ms |
12896 KB |
Output is correct |
24 |
Correct |
5 ms |
12880 KB |
Output is correct |
25 |
Correct |
88 ms |
30388 KB |
Output is correct |
26 |
Correct |
70 ms |
30648 KB |
Output is correct |
27 |
Correct |
82 ms |
30136 KB |
Output is correct |
28 |
Correct |
81 ms |
30196 KB |
Output is correct |
29 |
Correct |
80 ms |
30384 KB |
Output is correct |
30 |
Correct |
82 ms |
30188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
27828 KB |
Output is correct |
2 |
Correct |
75 ms |
27836 KB |
Output is correct |
3 |
Correct |
76 ms |
27136 KB |
Output is correct |
4 |
Correct |
86 ms |
27312 KB |
Output is correct |
5 |
Correct |
73 ms |
27632 KB |
Output is correct |
6 |
Correct |
83 ms |
27332 KB |
Output is correct |
7 |
Correct |
88 ms |
31400 KB |
Output is correct |
8 |
Correct |
87 ms |
31404 KB |
Output is correct |
9 |
Correct |
103 ms |
30888 KB |
Output is correct |
10 |
Correct |
106 ms |
30900 KB |
Output is correct |
11 |
Correct |
101 ms |
30888 KB |
Output is correct |
12 |
Correct |
112 ms |
30716 KB |
Output is correct |
13 |
Correct |
109 ms |
30840 KB |
Output is correct |
14 |
Correct |
96 ms |
31144 KB |
Output is correct |
15 |
Correct |
104 ms |
30888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12368 KB |
Output is correct |
2 |
Correct |
5 ms |
12624 KB |
Output is correct |
3 |
Correct |
5 ms |
12880 KB |
Output is correct |
4 |
Correct |
5 ms |
12880 KB |
Output is correct |
5 |
Correct |
5 ms |
12880 KB |
Output is correct |
6 |
Correct |
5 ms |
12880 KB |
Output is correct |
7 |
Correct |
5 ms |
12880 KB |
Output is correct |
8 |
Correct |
60 ms |
28180 KB |
Output is correct |
9 |
Correct |
66 ms |
30832 KB |
Output is correct |
10 |
Correct |
61 ms |
30648 KB |
Output is correct |
11 |
Correct |
78 ms |
30572 KB |
Output is correct |
12 |
Correct |
77 ms |
30648 KB |
Output is correct |
13 |
Correct |
62 ms |
30648 KB |
Output is correct |
14 |
Correct |
66 ms |
27828 KB |
Output is correct |
15 |
Correct |
75 ms |
27836 KB |
Output is correct |
16 |
Correct |
76 ms |
27136 KB |
Output is correct |
17 |
Correct |
86 ms |
27312 KB |
Output is correct |
18 |
Correct |
73 ms |
27632 KB |
Output is correct |
19 |
Correct |
83 ms |
27332 KB |
Output is correct |
20 |
Correct |
5 ms |
12624 KB |
Output is correct |
21 |
Correct |
5 ms |
12880 KB |
Output is correct |
22 |
Correct |
5 ms |
12880 KB |
Output is correct |
23 |
Correct |
5 ms |
13060 KB |
Output is correct |
24 |
Correct |
6 ms |
12896 KB |
Output is correct |
25 |
Correct |
5 ms |
12880 KB |
Output is correct |
26 |
Correct |
88 ms |
30388 KB |
Output is correct |
27 |
Correct |
70 ms |
30648 KB |
Output is correct |
28 |
Correct |
82 ms |
30136 KB |
Output is correct |
29 |
Correct |
81 ms |
30196 KB |
Output is correct |
30 |
Correct |
80 ms |
30384 KB |
Output is correct |
31 |
Correct |
82 ms |
30188 KB |
Output is correct |
32 |
Correct |
88 ms |
31400 KB |
Output is correct |
33 |
Correct |
87 ms |
31404 KB |
Output is correct |
34 |
Correct |
103 ms |
30888 KB |
Output is correct |
35 |
Correct |
106 ms |
30900 KB |
Output is correct |
36 |
Correct |
101 ms |
30888 KB |
Output is correct |
37 |
Correct |
112 ms |
30716 KB |
Output is correct |
38 |
Correct |
109 ms |
30840 KB |
Output is correct |
39 |
Correct |
96 ms |
31144 KB |
Output is correct |
40 |
Correct |
104 ms |
30888 KB |
Output is correct |
41 |
Correct |
114 ms |
34728 KB |
Output is correct |
42 |
Correct |
101 ms |
34924 KB |
Output is correct |
43 |
Correct |
118 ms |
34216 KB |
Output is correct |
44 |
Correct |
113 ms |
34216 KB |
Output is correct |
45 |
Correct |
126 ms |
34216 KB |
Output is correct |
46 |
Correct |
117 ms |
34272 KB |
Output is correct |
47 |
Correct |
113 ms |
34216 KB |
Output is correct |
48 |
Correct |
114 ms |
34468 KB |
Output is correct |
49 |
Correct |
116 ms |
34272 KB |
Output is correct |