# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
500243 |
2021-12-30T13:59:33 Z |
Mounir |
Klasika (COCI20_klasika) |
C++14 |
|
1311 ms |
524292 KB |
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define pb push_back
#define pii pair<int, int>
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define x first
#define y second
#define int long long
using namespace std;
const int OO = 1e9, N = 3e5, T = 30;
bitset<T> AXOR = (1 << 30) - 1;
//Plus petit dans le plus grand
struct Trie {
vector<vector<int>> arbre;
vector<int> dateMin, dateDico;
vector<bitset<T>> dico;
void init(){
for (int i = 0; i < 2; ++i){
arbre.pb({0, 0});
dateMin.pb(OO);
}
}
void ajouter(bitset<30> line, int dateAjout){
// cout << "ajouter " << line << " " << dateAjout << endl;
dico.pb(line);
string str = line.to_string();
reverse(all(str));
line = (bitset<T>)str;
dateDico.pb(dateAjout);
int noeud = 1;
for (int i = 0; i < T; ++i){
int cara = line[i];
// cout << noeud << " " << cara << endl;
if (arbre[noeud][cara] == 0){
arbre[noeud][cara] = sz(arbre);
arbre.pb({0, 0});
dateMin.pb(OO);
}
noeud = arbre[noeud][cara];
chmin(dateMin[noeud], dateAjout);
}
}
bitset<T> search(bitset<30> cible, int borneSup){
/* string str = cible.to_string();
reverse(all(str));
cible = (bitset<T>)str;
*/
int noeud = 1;
bitset<T> retour;
// cout << "recherche " << (cible^AXOR).to_ulong() << endl;
for (int i = 0; i < T; ++i){
int cara = cible[i];
if (arbre[noeud][cara] != 0 && dateMin[arbre[noeud][cara]] <= borneSup){
noeud = arbre[noeud][cara];
retour[i] = cara;
}
else {
noeud = arbre[noeud][1 - cara];
retour[i] = 1 - cara;
}
// cout << retour[i];
}
// cout << endl;
return retour;
}
void fusionner(Trie autre){
for (int i = 0; i < sz(autre.dico); ++i)
ajouter(autre.dico[i], autre.dateDico[i]);
}
};
vector<Trie> parcours;
int fusion(int pere, int fils){
if (sz(parcours[pere].dico) < sz(parcours[fils].dico))
return fusion(fils, pere);
parcours[pere].fusionner(parcours[fils]);
return pere;
}
vector<int> enfants[N];
int dateAjout[N];
bitset<T> xorPref[N];
struct Req {
int iReq;
bitset<T> cste;
};
vector<Req> reqs[N];
bitset<T> ans[N];
vector<bitset<T>> poids[N];
void calcPref(int noeud, bitset<T> cur){
// cout << "calc pref" << noeud << " " << cur << endl;
xorPref[noeud] = cur;
for (int i = 0; i < sz(enfants[noeud]); ++i)
calcPref(enfants[noeud][i], cur^poids[noeud][i]);
}
int dfs(int noeud){
// cout << "dfs " << noeud << endl;
int id = sz(parcours);
parcours.pb({});
parcours[id].init();
for (int enfant : enfants[noeud])
id = fusion(id, dfs(enfant));
//cout << "ppf" << noeud << endl;
parcours[id].ajouter(xorPref[noeud], dateAjout[noeud]);
// cout << "pf " << noeud << endl;
for (Req req : reqs[noeud]){
ans[req.iReq] = req.cste^parcours[id].search(AXOR^req.cste, req.iReq);
string str = ans[req.iReq].to_string();
reverse(all(str));
ans[req.iReq] = (bitset<T>)str;
}
return id;
}
bool estReq[N];
int deb[N], daron[N];
signed main(){
int nReqs; cin >> nReqs;
int nNoeuds = 2;
for (int iReq = 0; iReq < nReqs; ++iReq){
string nature;
int x, y; cin >> nature >> x >> y;
if (nature == "Add"){
dateAjout[nNoeuds] = iReq;
enfants[x].pb(nNoeuds++);
poids[x].pb(y);
}
else {
estReq[iReq] = true;
deb[iReq] = x;
daron[iReq] = y;
}
}
//cout << "bonsoir" << endl;
// cout << AXOR << endl;
calcPref(1, 0);
for (int iReq = 0; iReq < nReqs; ++iReq){
if (!estReq[iReq]) continue;
bitset<T> cste = xorPref[deb[iReq]];
string str = cste.to_string();
reverse(all(str));
cste = (bitset<T>)str;
reqs[daron[iReq]].pb({iReq, cste});
}
// cout << "salut" << endl;
dfs(1);
// for (int noeud = 1; noeud <= nNoeuds; ++noeud)
// cout << "xor " << noeud << " : " << xorPref[noeud] << endl;
for (int iReq = 0; iReq < nReqs; ++iReq){
if (estReq[iReq])
cout << ans[iReq].to_ulong() << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
21580 KB |
Output is correct |
2 |
Correct |
12 ms |
21580 KB |
Output is correct |
3 |
Correct |
11 ms |
21740 KB |
Output is correct |
4 |
Correct |
13 ms |
21796 KB |
Output is correct |
5 |
Correct |
14 ms |
21584 KB |
Output is correct |
6 |
Correct |
14 ms |
21836 KB |
Output is correct |
7 |
Correct |
12 ms |
21924 KB |
Output is correct |
8 |
Correct |
13 ms |
22356 KB |
Output is correct |
9 |
Correct |
11 ms |
21708 KB |
Output is correct |
10 |
Correct |
12 ms |
21964 KB |
Output is correct |
11 |
Correct |
15 ms |
22048 KB |
Output is correct |
12 |
Correct |
12 ms |
22220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
21580 KB |
Output is correct |
2 |
Correct |
12 ms |
21580 KB |
Output is correct |
3 |
Correct |
11 ms |
21740 KB |
Output is correct |
4 |
Correct |
13 ms |
21796 KB |
Output is correct |
5 |
Correct |
14 ms |
21584 KB |
Output is correct |
6 |
Correct |
14 ms |
21836 KB |
Output is correct |
7 |
Correct |
12 ms |
21924 KB |
Output is correct |
8 |
Correct |
13 ms |
22356 KB |
Output is correct |
9 |
Correct |
11 ms |
21708 KB |
Output is correct |
10 |
Correct |
12 ms |
21964 KB |
Output is correct |
11 |
Correct |
15 ms |
22048 KB |
Output is correct |
12 |
Correct |
12 ms |
22220 KB |
Output is correct |
13 |
Correct |
17 ms |
22476 KB |
Output is correct |
14 |
Correct |
18 ms |
23448 KB |
Output is correct |
15 |
Correct |
18 ms |
23940 KB |
Output is correct |
16 |
Correct |
18 ms |
25348 KB |
Output is correct |
17 |
Correct |
20 ms |
23892 KB |
Output is correct |
18 |
Correct |
27 ms |
26516 KB |
Output is correct |
19 |
Correct |
32 ms |
29708 KB |
Output is correct |
20 |
Correct |
43 ms |
31472 KB |
Output is correct |
21 |
Correct |
20 ms |
23456 KB |
Output is correct |
22 |
Correct |
25 ms |
25224 KB |
Output is correct |
23 |
Correct |
28 ms |
26596 KB |
Output is correct |
24 |
Correct |
29 ms |
28048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
749 ms |
99500 KB |
Output is correct |
2 |
Correct |
768 ms |
168848 KB |
Output is correct |
3 |
Correct |
840 ms |
211316 KB |
Output is correct |
4 |
Correct |
820 ms |
307156 KB |
Output is correct |
5 |
Correct |
1311 ms |
351232 KB |
Output is correct |
6 |
Runtime error |
1139 ms |
524292 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
21580 KB |
Output is correct |
2 |
Correct |
12 ms |
21580 KB |
Output is correct |
3 |
Correct |
11 ms |
21740 KB |
Output is correct |
4 |
Correct |
13 ms |
21796 KB |
Output is correct |
5 |
Correct |
14 ms |
21584 KB |
Output is correct |
6 |
Correct |
14 ms |
21836 KB |
Output is correct |
7 |
Correct |
12 ms |
21924 KB |
Output is correct |
8 |
Correct |
13 ms |
22356 KB |
Output is correct |
9 |
Correct |
11 ms |
21708 KB |
Output is correct |
10 |
Correct |
12 ms |
21964 KB |
Output is correct |
11 |
Correct |
15 ms |
22048 KB |
Output is correct |
12 |
Correct |
12 ms |
22220 KB |
Output is correct |
13 |
Correct |
17 ms |
22476 KB |
Output is correct |
14 |
Correct |
18 ms |
23448 KB |
Output is correct |
15 |
Correct |
18 ms |
23940 KB |
Output is correct |
16 |
Correct |
18 ms |
25348 KB |
Output is correct |
17 |
Correct |
20 ms |
23892 KB |
Output is correct |
18 |
Correct |
27 ms |
26516 KB |
Output is correct |
19 |
Correct |
32 ms |
29708 KB |
Output is correct |
20 |
Correct |
43 ms |
31472 KB |
Output is correct |
21 |
Correct |
20 ms |
23456 KB |
Output is correct |
22 |
Correct |
25 ms |
25224 KB |
Output is correct |
23 |
Correct |
28 ms |
26596 KB |
Output is correct |
24 |
Correct |
29 ms |
28048 KB |
Output is correct |
25 |
Correct |
749 ms |
99500 KB |
Output is correct |
26 |
Correct |
768 ms |
168848 KB |
Output is correct |
27 |
Correct |
840 ms |
211316 KB |
Output is correct |
28 |
Correct |
820 ms |
307156 KB |
Output is correct |
29 |
Correct |
1311 ms |
351232 KB |
Output is correct |
30 |
Runtime error |
1139 ms |
524292 KB |
Execution killed with signal 9 |
31 |
Halted |
0 ms |
0 KB |
- |