QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#331635#4909. 《关于因为与去年互测zjk撞题而不得不改题这回事》james1BadCreeper0 2080ms319204kbC++142.7kb2024-02-18 16:12:002024-02-18 16:12:00

Judging History

你现在查看的是最新测评结果

  • [2024-02-18 16:12:00]
  • 评测
  • 测评结果:0
  • 用时:2080ms
  • 内存:319204kb
  • [2024-02-18 16:12:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std; 
typedef long long i64; 
const int N = 1e6 + 5; 

int n, q, id[N]; 
i64 a[N]; 
int sz[N], dep[N], f[N]; 
int dfn[N], top[N], son[N], num; 
vector<int> G[N]; 

void dfs1(int x, int fa) {
    dep[x] = dep[f[x] = fa] + 1; sz[x] = 1; 
    for (int y : G[x]) if (y != fa) {
        dfs1(y, x); 
        if (sz[y] > sz[son[x]]) son[x] = y; 
    }
}
void dfs2(int x, int topf) {
    dfn[x] = ++num; top[x] = topf; 
    if (!son[x]) return; dfs2(son[x], topf); 
    for (int y : G[x]) if (y != f[x] && y != son[x]) dfs2(y, y); 
}

vector<int> T[N * 4]; 
void update(int o, int l, int r, int x, i64 k) { // 从小到大插入数
    T[o].emplace_back(k); 
    if (l == r) return; 
    int mid = l + r >> 1; 
    if (x <= mid) update(o << 1, l, mid, x, k);
    else update(o << 1 | 1, mid + 1, r, x, k);
}
vector<pair<int, int>> s; 
vector<int> now; 
void query(int o, int l, int r, int x, int y) {
    if (x <= l && r <= y) return s.emplace_back(o, 0), void(); 
    int mid = l + r >> 1; 
    if (x <= mid) query(o << 1, l, mid, x, y); 
    if (mid < y) query(o << 1 | 1, mid + 1, r, x, y); 
}
i64 query(int x, int y, int k) {
    s.clear(), now.clear(); 
    while (top[x] != top[y]) {
        if (dep[top[x]] < dep[top[y]]) swap(x, y); 
        query(1, 1, n, dfn[top[x]], dfn[x]), x = f[top[x]]; 
    }
    if (dep[x] > dep[y]) swap(x, y); 
    query(1, 1, n, dfn[x], dfn[y]); 
    i64 ans = 0; 
    for (int i = 61; i >= 0; --i) {
        int cnt = 0; 
        for (auto [node, p] : s) {
            while ((T[node][p] >> i & 1) && (T[node][p] & ans) == ans) {
                ++p; ++cnt; 
                if (cnt >= k) break; 
            }
            if (cnt >= k) break; 
        }
        for (auto val : now) {
            if (cnt >= k) break; 
            if ((val >> i & 1) && (val & ans) == ans) ++cnt; 
        }
        if (cnt >= k) { ans |= 1ll << i; continue; }
        for (auto &[node, p] : s)
            while ((T[node][p] >> i & 1) && (T[node][p] & ans) == ans) now.emplace_back(T[node][p++]); 
    }
    return ans; 
}

int main(void) {
    ios::sync_with_stdio(0); cin.tie(0); 
    cin >> n; 
    for (int i = 1; i < n; ++i) {
        int x, y; cin >> x >> y; 
        G[x].emplace_back(y); G[y].emplace_back(x); 
    } dfs1(1, 0); dfs2(1, 1); 
    for (int i = 1; i <= n; ++i) cin >> a[i], id[i] = i; 
    sort(id + 1, id + n + 1, [&](int x, int y) { return a[x] > a[y]; }); 
    for (int i = 1; i <= n; ++i) update(1, 1, n, dfn[id[i]], a[id[i]]); 
    cin >> q; 
    for (i64 lst = 0; q--; ) {
        int x, y, k; cin >> x >> y >> k; 
        x = (x ^ lst) % n + 1, y = (y ^ lst) % n + 1; 
        cout << (lst = query(x, y, k)) << '\n'; 
    }
    return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 16ms
memory: 134852kb

input:

931
184 700
485 184
419 485
386 419
308 386
114 308
301 114
598 301
120 598
144 120
595 144
812 595
236 812
7 236
543 7
327 543
858 327
68 858
177 68
398 177
899 398
408 899
848 408
202 848
269 202
304 269
540 304
647 540
672 647
314 672
157 314
241 157
745 241
300 745
343 300
92 343
117 92
30 117
2...

output:

68719476736

result:

wrong answer 1st numbers differ - expected: '1152921504606846976', found: '68719476736'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 107ms
memory: 157796kb

input:

99115
98506 98914
1961 98506
45808 1961
23027 45808
16655 23027
66393 16655
77250 66393
68284 77250
53684 68284
21189 53684
84955 21189
73464 84955
47574 73464
40651 47574
21101 40651
6589 21101
59680 6589
6185 59680
25529 6185
207 25529
33286 207
98459 33286
92565 98459
85446 92565
97388 85446
1630...

output:

8796093022208

result:

wrong answer 1st numbers differ - expected: '2050', found: '8796093022208'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Wrong Answer

Test #45:

score: 0
Wrong Answer
time: 2080ms
memory: 319204kb

input:

996678
2 1
3 1
4 1
5 1
6 3
7 5
8 5
9 5
10 7
11 8
12 9
13 1
14 2
15 7
16 4
17 5
18 17
19 16
20 2
21 1
22 1
23 9
24 17
25 19
26 10
27 9
28 7
29 25
30 25
31 4
32 11
33 31
34 21
35 13
36 19
37 25
38 10
39 11
40 20
41 35
42 1
43 19
44 20
45 41
46 1
47 19
48 5
49 28
50 21
51 33
52 7
53 14
54 21
55 20
56 1...

output:

17179869184
0
17179869184
0
21386
8589934592
0
4096
0
0
0
0
0
0
0
0
8589934592
0
34359738368
0
0
8192
0
68719476736
2
0
17592186044416
8589934592
8589934592
0
0
17592186044416
0
0
0
0
8589934592
0
8589934592
0
0
2199023255552
0
0
0
0
137438953472
2199023255552
8589934592
0
0
2199023255552
3435973836...

result:

wrong answer 1st numbers differ - expected: '4', found: '17179869184'

Subtask #8:

score: 0
Skipped

Dependency #1:

0%