# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1106520 |
2024-10-30T14:12:52 Z |
Noname_1900 |
Nile (IOI24_nile) |
C++17 |
|
94 ms |
22068 KB |
#include "nile.h"
using namespace std;
#include<bits/stdc++.h>
const int NMAX = 100000;
#define int long long
const int INFINI = 1000000000000ll;
struct T {
int poid, normal, enPair;
T(int prem = 0, int a = 0, int b = 0)
{
poid = prem;
normal = a;
enPair = b;
}
bool operator<(const T &other) const {
return poid < other.poid;
}
};
vector<pair<int, pair<int, int>>> aretes;
int boss[NMAX];
int minRouge[NMAX], minNoir[NMAX];
T infos[NMAX];//W, A, B
int sommeB[NMAX];
int sommeTotal;
int taille[NMAX];
int sommeComposante[NMAX];
int findBoss(int noeud)
{
if(boss[noeud] == noeud)
{
return noeud;
}
return boss[noeud] = findBoss(boss[noeud]);
}
void comparerBalance(int noeud)
{
minRouge[findBoss(noeud)] = min(minRouge[findBoss(noeud)], (infos[noeud].normal-infos[noeud].enPair));
minNoir[findBoss(noeud)] = min(minNoir[findBoss(noeud)], (infos[noeud].normal-infos[noeud].enPair));
}
void faire(int bossA, int bossB, bool inverserCouleur)
{
if(inverserCouleur)
{
minRouge[bossA] = min(minRouge[bossA], minNoir[bossB]);
minNoir[bossA] = min(minNoir[bossA], minRouge[bossB]);
}
else
{
minRouge[bossA] = min(minRouge[bossA], minRouge[bossB]);
minNoir[bossA] = min(minNoir[bossA], minNoir[bossB]);
}
}
void merge(int a, int b)
{
int bossA = findBoss(a), bossB = findBoss(b);
if(bossA == bossB)
{
int balance = a+1;
comparerBalance(balance);
sommeTotal -= sommeComposante[bossA];
}
else
{
int debutB = bossB%2;
int debutA = bossA%2;
int finA = (debutA + taille[bossA]-1)%2;
if(finA == debutB)
faire(bossA, bossB, 1);
else
{
faire(bossA, bossB, 0);
}
sommeB[bossA] += sommeB[bossB];
taille[bossA] += taille[bossB];
sommeTotal -= sommeComposante[bossA] + sommeComposante[bossB];
boss[bossB] = bossA;
}
int noeud = bossA;
if(taille[noeud]%2 == 0)
{
sommeComposante[noeud] = sommeB[noeud];
}
else if(bossA%2 == 0)
{
sommeComposante[noeud] = sommeB[noeud]+minRouge[noeud];
}
else
{
sommeComposante[noeud] = sommeB[noeud]+minNoir[noeud];
}
sommeTotal += sommeComposante[noeud];
}
pair<int, int> requetes[NMAX];
#undef int
std::vector<long long> calculate_costs(std::vector<int> W, std::vector<int> A,
std::vector<int> B, std::vector<int> E) {
#define int long long
sommeTotal = 0;
int Q = (int)E.size();
int N = W.size();
for(int i = 0; i < Q; i++)
{
requetes[i] = {E[i], i};
}
sort(requetes, requetes+Q);
for(int i = 0; i < N; i++)
{
infos[i] = {W[i], A[i], B[i]};
}
sort(infos, infos+N);
for(int i = 1; i < N; i++)
{
aretes.push_back({2*(infos[i].poid-infos[i-1].poid), pair<int, int>(i-1, i)});
if(i >= 2)
aretes.push_back({2*(infos[i].poid-infos[i-2].poid)+1, pair<int, int>(i-2, i)});
}
sort(aretes.begin(), aretes.end());
//aVoir
for(int i = 0; i < N; i++)
{
boss[i] = i;
taille[i] = 1;
sommeTotal += infos[i].normal;
sommeB[i] = infos[i].enPair;
sommeComposante[i] = infos[i].normal;
if(i % 2 == 0)
{
minRouge[i] = (infos[i].normal - infos[i].enPair);
minNoir[i] = INFINI;
}
else
{
minNoir[i] = (infos[i].normal- infos[i].enPair);
minRouge[i] = INFINI;
}
}
std::vector<long long> R(Q);
int iEnlever = 0;
for(int i = 0; i < Q; i++)
{
int D = requetes[i].first;
while((iEnlever < aretes.size()) && (aretes[iEnlever].first <= 2 * D + 1))
{
merge(aretes[iEnlever].second.first, aretes[iEnlever].second.second);
iEnlever++;
}
R[requetes[i].second] = sommeTotal;
}
return R;
}
/** */
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:151:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
151 | while((iEnlever < aretes.size()) && (aretes[iEnlever].first <= 2 * D + 1))
| ~~~~~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8784 KB |
Output is correct |
2 |
Correct |
2 ms |
8784 KB |
Output is correct |
3 |
Correct |
2 ms |
8784 KB |
Output is correct |
4 |
Correct |
2 ms |
8784 KB |
Output is correct |
5 |
Correct |
2 ms |
8784 KB |
Output is correct |
6 |
Correct |
2 ms |
8784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
17344 KB |
Output is correct |
2 |
Correct |
37 ms |
17344 KB |
Output is correct |
3 |
Correct |
37 ms |
17336 KB |
Output is correct |
4 |
Correct |
40 ms |
17336 KB |
Output is correct |
5 |
Correct |
37 ms |
17336 KB |
Output is correct |
6 |
Correct |
39 ms |
17344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
17340 KB |
Output is correct |
2 |
Correct |
37 ms |
17344 KB |
Output is correct |
3 |
Correct |
47 ms |
17336 KB |
Output is correct |
4 |
Correct |
45 ms |
17336 KB |
Output is correct |
5 |
Correct |
47 ms |
17292 KB |
Output is correct |
6 |
Correct |
57 ms |
17336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8784 KB |
Output is correct |
2 |
Correct |
2 ms |
8784 KB |
Output is correct |
3 |
Correct |
2 ms |
8784 KB |
Output is correct |
4 |
Correct |
2 ms |
8784 KB |
Output is correct |
5 |
Correct |
2 ms |
8784 KB |
Output is correct |
6 |
Correct |
2 ms |
8784 KB |
Output is correct |
7 |
Correct |
2 ms |
8784 KB |
Output is correct |
8 |
Correct |
2 ms |
8784 KB |
Output is correct |
9 |
Correct |
3 ms |
8784 KB |
Output is correct |
10 |
Correct |
3 ms |
8784 KB |
Output is correct |
11 |
Correct |
3 ms |
8784 KB |
Output is correct |
12 |
Correct |
2 ms |
8784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8784 KB |
Output is correct |
2 |
Correct |
2 ms |
8784 KB |
Output is correct |
3 |
Correct |
2 ms |
8784 KB |
Output is correct |
4 |
Correct |
2 ms |
8784 KB |
Output is correct |
5 |
Correct |
2 ms |
8784 KB |
Output is correct |
6 |
Correct |
2 ms |
8784 KB |
Output is correct |
7 |
Correct |
36 ms |
17344 KB |
Output is correct |
8 |
Correct |
37 ms |
17344 KB |
Output is correct |
9 |
Correct |
37 ms |
17336 KB |
Output is correct |
10 |
Correct |
40 ms |
17336 KB |
Output is correct |
11 |
Correct |
37 ms |
17336 KB |
Output is correct |
12 |
Correct |
39 ms |
17344 KB |
Output is correct |
13 |
Correct |
38 ms |
17340 KB |
Output is correct |
14 |
Correct |
37 ms |
17344 KB |
Output is correct |
15 |
Correct |
47 ms |
17336 KB |
Output is correct |
16 |
Correct |
45 ms |
17336 KB |
Output is correct |
17 |
Correct |
47 ms |
17292 KB |
Output is correct |
18 |
Correct |
57 ms |
17336 KB |
Output is correct |
19 |
Correct |
2 ms |
8784 KB |
Output is correct |
20 |
Correct |
2 ms |
8784 KB |
Output is correct |
21 |
Correct |
3 ms |
8784 KB |
Output is correct |
22 |
Correct |
3 ms |
8784 KB |
Output is correct |
23 |
Correct |
3 ms |
8784 KB |
Output is correct |
24 |
Correct |
2 ms |
8784 KB |
Output is correct |
25 |
Correct |
45 ms |
19044 KB |
Output is correct |
26 |
Correct |
54 ms |
19148 KB |
Output is correct |
27 |
Correct |
54 ms |
18328 KB |
Output is correct |
28 |
Correct |
58 ms |
19128 KB |
Output is correct |
29 |
Correct |
52 ms |
18876 KB |
Output is correct |
30 |
Correct |
58 ms |
17340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
17340 KB |
Output is correct |
2 |
Correct |
37 ms |
17344 KB |
Output is correct |
3 |
Correct |
47 ms |
17336 KB |
Output is correct |
4 |
Correct |
45 ms |
17336 KB |
Output is correct |
5 |
Correct |
47 ms |
17292 KB |
Output is correct |
6 |
Correct |
57 ms |
17336 KB |
Output is correct |
7 |
Correct |
67 ms |
18888 KB |
Output is correct |
8 |
Correct |
60 ms |
19140 KB |
Output is correct |
9 |
Correct |
66 ms |
18932 KB |
Output is correct |
10 |
Correct |
66 ms |
19024 KB |
Output is correct |
11 |
Correct |
68 ms |
18872 KB |
Output is correct |
12 |
Correct |
66 ms |
18888 KB |
Output is correct |
13 |
Correct |
68 ms |
19128 KB |
Output is correct |
14 |
Correct |
64 ms |
19128 KB |
Output is correct |
15 |
Correct |
70 ms |
19136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8528 KB |
Output is correct |
2 |
Correct |
2 ms |
8784 KB |
Output is correct |
3 |
Correct |
2 ms |
8784 KB |
Output is correct |
4 |
Correct |
2 ms |
8784 KB |
Output is correct |
5 |
Correct |
2 ms |
8784 KB |
Output is correct |
6 |
Correct |
2 ms |
8784 KB |
Output is correct |
7 |
Correct |
2 ms |
8784 KB |
Output is correct |
8 |
Correct |
36 ms |
17344 KB |
Output is correct |
9 |
Correct |
37 ms |
17344 KB |
Output is correct |
10 |
Correct |
37 ms |
17336 KB |
Output is correct |
11 |
Correct |
40 ms |
17336 KB |
Output is correct |
12 |
Correct |
37 ms |
17336 KB |
Output is correct |
13 |
Correct |
39 ms |
17344 KB |
Output is correct |
14 |
Correct |
38 ms |
17340 KB |
Output is correct |
15 |
Correct |
37 ms |
17344 KB |
Output is correct |
16 |
Correct |
47 ms |
17336 KB |
Output is correct |
17 |
Correct |
45 ms |
17336 KB |
Output is correct |
18 |
Correct |
47 ms |
17292 KB |
Output is correct |
19 |
Correct |
57 ms |
17336 KB |
Output is correct |
20 |
Correct |
2 ms |
8784 KB |
Output is correct |
21 |
Correct |
2 ms |
8784 KB |
Output is correct |
22 |
Correct |
3 ms |
8784 KB |
Output is correct |
23 |
Correct |
3 ms |
8784 KB |
Output is correct |
24 |
Correct |
3 ms |
8784 KB |
Output is correct |
25 |
Correct |
2 ms |
8784 KB |
Output is correct |
26 |
Correct |
45 ms |
19044 KB |
Output is correct |
27 |
Correct |
54 ms |
19148 KB |
Output is correct |
28 |
Correct |
54 ms |
18328 KB |
Output is correct |
29 |
Correct |
58 ms |
19128 KB |
Output is correct |
30 |
Correct |
52 ms |
18876 KB |
Output is correct |
31 |
Correct |
58 ms |
17340 KB |
Output is correct |
32 |
Correct |
67 ms |
18888 KB |
Output is correct |
33 |
Correct |
60 ms |
19140 KB |
Output is correct |
34 |
Correct |
66 ms |
18932 KB |
Output is correct |
35 |
Correct |
66 ms |
19024 KB |
Output is correct |
36 |
Correct |
68 ms |
18872 KB |
Output is correct |
37 |
Correct |
66 ms |
18888 KB |
Output is correct |
38 |
Correct |
68 ms |
19128 KB |
Output is correct |
39 |
Correct |
64 ms |
19128 KB |
Output is correct |
40 |
Correct |
70 ms |
19136 KB |
Output is correct |
41 |
Correct |
65 ms |
19128 KB |
Output is correct |
42 |
Correct |
68 ms |
20920 KB |
Output is correct |
43 |
Correct |
94 ms |
21148 KB |
Output is correct |
44 |
Correct |
79 ms |
19128 KB |
Output is correct |
45 |
Correct |
75 ms |
20920 KB |
Output is correct |
46 |
Correct |
73 ms |
20408 KB |
Output is correct |
47 |
Correct |
74 ms |
20284 KB |
Output is correct |
48 |
Correct |
76 ms |
18872 KB |
Output is correct |
49 |
Correct |
94 ms |
22068 KB |
Output is correct |