3317 2023. 02. 25 09:20:29 gortomi XORfa visszatér cpp17 Időlimit túllépés 28/100 1.585s 522040 KiB
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > g;
vector<int> v;
void dfs(int n, int p)
{
    for(auto x : g[n])
    {
        int y = x.first, z = x.second;
        if(y != p)
        {
            v[y] = v[n] ^ z;
            dfs(y, n);
        }
    }
}
struct node
{
    int l, r, w, m;
    node *lc, *rc;
    node(int il, int ir)
    {
        l = il;
        r = ir;
        m = (l + r) / 2;
        w = 0;
        lc = nullptr;
        rc = nullptr;
    }
    void extend()
    {
        if(lc == nullptr)
        {
            lc = new node(l, m);
            rc = new node(m + 1, r);
        }
    }
    void upd(int k, int ind, int del)
    {
        w += del;
        if(ind == -1) return;
        extend();
        if((k >> ind) & 1) rc -> upd(k, ind - 1, del);
        else lc -> upd(k, ind - 1, del);
    }
    int get(int k, int ind)
    {
        if(ind == -1) return 0;
        extend();
        if(((k >> ind) & 1))
        {
            if(lc -> w > 0) return lc -> get(k, ind - 1) + (1 << ind);
            else return rc -> get(k, ind - 1);
        }
        else
        {
            if(rc -> w > 0) return rc -> get(k, ind - 1) + (1 << ind);
            else return lc -> get(k, ind - 1);
        }
    }
};
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    g.resize(n + 1);
    v.resize(n + 1);
    for(int i = 0; i < n - 1; i++)
    {
        int x, y, w;
        cin >> x >> y >> w;
        g[x].push_back({y, w});
        g[y].push_back({x, w});
    }
    dfs(1, 0);
    const int b = 300;
    vector<int> no(q);
    vector<int> act(n + 1, -1);
    vector<pair<int, int> > add;
    for(int i = 0; i < q; i++)
    {
        cin >> no[i];
        if(act[no[i]] == -1)
        {
            act[no[i]] = i;
        }
        else
        {
            add.push_back({act[no[i]], i - 1});
            act[no[i]] = -1;
        }
    }
    for(int i = 1; i <= n; i++) if(act[i] != -1) add.push_back({act[i], q - 1});
    node neu = node(0, 0);
    vector<node> trie(b, neu);
    vector<int> maxi(b);
    vector<vector<int> > ins(q);
    for(int i = 0; i < b; i++) trie[i] = node(0, (1 << 30) - 1);
    for(auto x : add)
    {
        int l = x.first, r = x.second;
        int val = no[l];
        while(l % b != 0 && l <= r)
        {
            ins[l].push_back(val);
            l++;
        }
        while(l + b - 1 <= r)
        {
            trie[l / b].upd(v[val], 29, 1);
            maxi[l / b] = max(maxi[l / b], trie[l / b].get(v[val], 29));
            l += b;
        }
        while(l <= r)
        {
            ins[l].push_back(val);
            l++;
        }
    }
    for(int i = 0; i < q; i++)
    {
        int actb = i / b;
        int ans = maxi[actb];
        for(auto x : ins[i])
        {
            trie[actb].upd(v[x], 29, 1);
            ans = max(ans, trie[actb].get(v[x], 29));
        }
        cout << ans << "\n";
        for(auto x : ins[i]) trie[actb].upd(v[x], 29, -1);
    }
    return 0;
}
Részfeladat Összpont Teszt Verdikt Idő Memória
subtask1 0/0
1 Elfogadva 3ms 1840 KiB
2 Elfogadva 3ms 2044 KiB
subtask2 11/11
3 Elfogadva 4ms 2668 KiB
4 Elfogadva 3ms 2732 KiB
5 Elfogadva 4ms 3152 KiB
6 Elfogadva 4ms 3184 KiB
7 Elfogadva 4ms 3404 KiB
8 Elfogadva 4ms 3404 KiB
9 Elfogadva 4ms 3504 KiB
10 Elfogadva 4ms 3472 KiB
11 Elfogadva 4ms 3420 KiB
12 Elfogadva 4ms 3544 KiB
13 Elfogadva 4ms 3588 KiB
subtask3 0/13
14 Elfogadva 79ms 17244 KiB
15 Elfogadva 115ms 18548 KiB
16 Időlimit túllépés 1.585s 67196 KiB
17 Időlimit túllépés 1.572s 78096 KiB
18 Időlimit túllépés 1.585s 91992 KiB
19 Időlimit túllépés 1.572s 95392 KiB
20 Időlimit túllépés 1.572s 74896 KiB
21 Időlimit túllépés 1.572s 78536 KiB
22 Elfogadva 119ms 19636 KiB
23 Elfogadva 115ms 19608 KiB
subtask4 17/17
24 Elfogadva 78ms 11308 KiB
25 Elfogadva 45ms 9032 KiB
26 Elfogadva 115ms 13832 KiB
27 Elfogadva 155ms 16016 KiB
28 Elfogadva 186ms 17512 KiB
29 Elfogadva 70ms 11232 KiB
30 Elfogadva 87ms 12256 KiB
31 Elfogadva 90ms 12184 KiB
32 Elfogadva 67ms 7820 KiB
33 Elfogadva 67ms 7748 KiB
34 Elfogadva 67ms 7840 KiB
35 Elfogadva 67ms 7988 KiB
subtask5 0/59
36 Futási hiba 523ms 522040 KiB
37 Futási hiba 523ms 522012 KiB
38 Futási hiba 518ms 521992 KiB
39 Futási hiba 510ms 521760 KiB
40 Futási hiba 512ms 521736 KiB
41 Futási hiba 524ms 521736 KiB
42 Futási hiba 537ms 521724 KiB
43 Futási hiba 544ms 521728 KiB
44 Futási hiba 541ms 521724 KiB
45 Időlimit túllépés 1.56s 119172 KiB
46 Időlimit túllépés 1.582s 188240 KiB
47 Időlimit túllépés 1.559s 198100 KiB
48 Időlimit túllépés 1.572s 196044 KiB
49 Időlimit túllépés 1.58s 187320 KiB