# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
500246 |
2021-12-30T14:02:23 Z |
Mounir |
Klasika (COCI20_klasika) |
C++14 |
|
2981 ms |
310328 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]);
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(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
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 |
14 ms |
21580 KB |
Output is correct |
2 |
Correct |
15 ms |
21580 KB |
Output is correct |
3 |
Correct |
16 ms |
21752 KB |
Output is correct |
4 |
Correct |
12 ms |
21708 KB |
Output is correct |
5 |
Correct |
11 ms |
21580 KB |
Output is correct |
6 |
Correct |
11 ms |
21580 KB |
Output is correct |
7 |
Correct |
12 ms |
21700 KB |
Output is correct |
8 |
Correct |
13 ms |
21748 KB |
Output is correct |
9 |
Correct |
11 ms |
21580 KB |
Output is correct |
10 |
Correct |
12 ms |
21796 KB |
Output is correct |
11 |
Correct |
12 ms |
21836 KB |
Output is correct |
12 |
Correct |
12 ms |
21856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
21580 KB |
Output is correct |
2 |
Correct |
15 ms |
21580 KB |
Output is correct |
3 |
Correct |
16 ms |
21752 KB |
Output is correct |
4 |
Correct |
12 ms |
21708 KB |
Output is correct |
5 |
Correct |
11 ms |
21580 KB |
Output is correct |
6 |
Correct |
11 ms |
21580 KB |
Output is correct |
7 |
Correct |
12 ms |
21700 KB |
Output is correct |
8 |
Correct |
13 ms |
21748 KB |
Output is correct |
9 |
Correct |
11 ms |
21580 KB |
Output is correct |
10 |
Correct |
12 ms |
21796 KB |
Output is correct |
11 |
Correct |
12 ms |
21836 KB |
Output is correct |
12 |
Correct |
12 ms |
21856 KB |
Output is correct |
13 |
Correct |
20 ms |
22352 KB |
Output is correct |
14 |
Correct |
17 ms |
23228 KB |
Output is correct |
15 |
Correct |
17 ms |
23640 KB |
Output is correct |
16 |
Correct |
20 ms |
24876 KB |
Output is correct |
17 |
Correct |
20 ms |
22604 KB |
Output is correct |
18 |
Correct |
23 ms |
23304 KB |
Output is correct |
19 |
Correct |
28 ms |
24588 KB |
Output is correct |
20 |
Correct |
31 ms |
24416 KB |
Output is correct |
21 |
Correct |
19 ms |
22476 KB |
Output is correct |
22 |
Correct |
20 ms |
23388 KB |
Output is correct |
23 |
Correct |
22 ms |
24008 KB |
Output is correct |
24 |
Correct |
28 ms |
24380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
629 ms |
87728 KB |
Output is correct |
2 |
Correct |
700 ms |
148800 KB |
Output is correct |
3 |
Correct |
678 ms |
180288 KB |
Output is correct |
4 |
Correct |
717 ms |
269308 KB |
Output is correct |
5 |
Correct |
1083 ms |
100428 KB |
Output is correct |
6 |
Correct |
1715 ms |
175476 KB |
Output is correct |
7 |
Correct |
2324 ms |
200064 KB |
Output is correct |
8 |
Correct |
2885 ms |
278284 KB |
Output is correct |
9 |
Correct |
884 ms |
98204 KB |
Output is correct |
10 |
Correct |
1140 ms |
167652 KB |
Output is correct |
11 |
Correct |
1299 ms |
212712 KB |
Output is correct |
12 |
Correct |
1611 ms |
307036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
21580 KB |
Output is correct |
2 |
Correct |
15 ms |
21580 KB |
Output is correct |
3 |
Correct |
16 ms |
21752 KB |
Output is correct |
4 |
Correct |
12 ms |
21708 KB |
Output is correct |
5 |
Correct |
11 ms |
21580 KB |
Output is correct |
6 |
Correct |
11 ms |
21580 KB |
Output is correct |
7 |
Correct |
12 ms |
21700 KB |
Output is correct |
8 |
Correct |
13 ms |
21748 KB |
Output is correct |
9 |
Correct |
11 ms |
21580 KB |
Output is correct |
10 |
Correct |
12 ms |
21796 KB |
Output is correct |
11 |
Correct |
12 ms |
21836 KB |
Output is correct |
12 |
Correct |
12 ms |
21856 KB |
Output is correct |
13 |
Correct |
20 ms |
22352 KB |
Output is correct |
14 |
Correct |
17 ms |
23228 KB |
Output is correct |
15 |
Correct |
17 ms |
23640 KB |
Output is correct |
16 |
Correct |
20 ms |
24876 KB |
Output is correct |
17 |
Correct |
20 ms |
22604 KB |
Output is correct |
18 |
Correct |
23 ms |
23304 KB |
Output is correct |
19 |
Correct |
28 ms |
24588 KB |
Output is correct |
20 |
Correct |
31 ms |
24416 KB |
Output is correct |
21 |
Correct |
19 ms |
22476 KB |
Output is correct |
22 |
Correct |
20 ms |
23388 KB |
Output is correct |
23 |
Correct |
22 ms |
24008 KB |
Output is correct |
24 |
Correct |
28 ms |
24380 KB |
Output is correct |
25 |
Correct |
629 ms |
87728 KB |
Output is correct |
26 |
Correct |
700 ms |
148800 KB |
Output is correct |
27 |
Correct |
678 ms |
180288 KB |
Output is correct |
28 |
Correct |
717 ms |
269308 KB |
Output is correct |
29 |
Correct |
1083 ms |
100428 KB |
Output is correct |
30 |
Correct |
1715 ms |
175476 KB |
Output is correct |
31 |
Correct |
2324 ms |
200064 KB |
Output is correct |
32 |
Correct |
2885 ms |
278284 KB |
Output is correct |
33 |
Correct |
884 ms |
98204 KB |
Output is correct |
34 |
Correct |
1140 ms |
167652 KB |
Output is correct |
35 |
Correct |
1299 ms |
212712 KB |
Output is correct |
36 |
Correct |
1611 ms |
307036 KB |
Output is correct |
37 |
Correct |
661 ms |
93624 KB |
Output is correct |
38 |
Correct |
704 ms |
154704 KB |
Output is correct |
39 |
Correct |
688 ms |
185832 KB |
Output is correct |
40 |
Correct |
748 ms |
275272 KB |
Output is correct |
41 |
Correct |
1030 ms |
108720 KB |
Output is correct |
42 |
Correct |
1669 ms |
172232 KB |
Output is correct |
43 |
Correct |
2198 ms |
178068 KB |
Output is correct |
44 |
Correct |
2981 ms |
272408 KB |
Output is correct |
45 |
Correct |
773 ms |
100696 KB |
Output is correct |
46 |
Correct |
1055 ms |
171236 KB |
Output is correct |
47 |
Correct |
1200 ms |
214576 KB |
Output is correct |
48 |
Correct |
1557 ms |
310328 KB |
Output is correct |