Task: | Company Queries II |
Sender: | aalto2024h_004 |
Submission time: | 2024-10-24 12:22:04 +0300 |
Language: | C++ (C++20) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.00 s | details |
#2 | WRONG ANSWER | 0.00 s | details |
#3 | WRONG ANSWER | 0.00 s | details |
#4 | WRONG ANSWER | 0.00 s | details |
#5 | WRONG ANSWER | 0.00 s | details |
#6 | WRONG ANSWER | 0.78 s | details |
#7 | ACCEPTED | 0.58 s | details |
#8 | WRONG ANSWER | 0.84 s | details |
#9 | WRONG ANSWER | 0.78 s | details |
#10 | WRONG ANSWER | 0.74 s | details |
#11 | WRONG ANSWER | 0.00 s | details |
#12 | WRONG ANSWER | 0.80 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:62:19: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare] 62 | for(int i=0; i<q; i++){ | ~^~
Code
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef unsigned long long ull;int n;int logn;int d[2*200000+1];int f[2*200000+1];int e[2*(2*200000+1)];int didx = 0;#define logn_max 20int rmq[(2*200000+1)*logn_max];map<int,vector<int>> adj;void dfs(int a, int di){d[a] = di;f[a] = didx;e[didx++] = a;if(adj.count(a)){for(auto b : adj[a]){dfs(b, di+1);e[didx++] = a;}}}void makermq(){rmq[1] = 0;for(int i=2; i<=didx; i++)rmq[i]=rmq[i/2] + 1;for(int i=0; i<didx; i++){rmq[i*logn_max + 0] = e[i];}for(int j=1; (1<<j)<=didx; j++){for(int i=0; i+(1<<j)<=didx; i++){int l = rmq[i*logn_max + j - 1];int r = rmq[(i + (1 << (j - 1)))*logn_max + (j-1)];int ln = e[l];int rn = e[r];rmq[i*logn_max + j] = d[ln] < d[rn] ? l : r;}}}int main(){ull q;cin >> n >> q;for(int i=0; i<n-1; i++){int b;cin >> b;adj[b].push_back(i+2);}dfs(1, 1);makermq();for(int i=0; i<q; i++){ll a, b;cin >> a >> b;a = f[a];b = f[b];if(a > b) swap(a, b);ll l = b-a+1;ll k = floor(log2(l));int li = rmq[a *logn_max + k];int ri = rmq[(b - (1 << k) + 1) *logn_max + k];int ln = e[li];int rn = e[ri];cout << e[(d[ln] < d[rn]) ? li : ri] << endl;}}
Test details
Test 1
Verdict: WRONG ANSWER
input |
---|
10 10 1 2 3 4 5 6 7 8 9 6 9 8 10 10 3 ... |
correct output |
---|
6 8 3 1 8 ... |
user output |
---|
7 9 4 2 9 ... |
Test 2
Verdict: WRONG ANSWER
input |
---|
10 10 1 1 1 1 1 1 1 1 1 1 7 3 4 4 1 ... |
correct output |
---|
1 1 1 1 1 ... |
user output |
---|
1 1 1 1 1 ... |
Test 3
Verdict: WRONG ANSWER
input |
---|
10 10 1 1 1 1 2 3 4 4 1 1 8 2 7 8 3 ... |
correct output |
---|
1 1 1 1 1 ... |
user output |
---|
1 3 1 1 2 ... |
Test 4
Verdict: WRONG ANSWER
input |
---|
10 10 1 1 3 1 2 2 5 3 9 7 2 7 6 3 9 ... |
correct output |
---|
2 2 3 1 1 ... |
user output |
---|
1 1 3 1 1 ... |
Test 5
Verdict: WRONG ANSWER
input |
---|
10 10 1 2 3 2 5 3 2 2 4 6 1 1 3 1 9 ... |
correct output |
---|
1 1 1 2 2 ... |
user output |
---|
2 2 2 2 3 ... |
Test 6
Verdict: WRONG ANSWER
input |
---|
200000 200000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
74862 8750 16237 72298 58111 ... |
user output |
---|
74863 8751 16238 72299 58112 ... Truncated |
Test 7
Verdict: ACCEPTED
input |
---|
200000 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
1 1 1 1 1 ... |
user output |
---|
1 1 1 1 1 ... Truncated |
Test 8
Verdict: WRONG ANSWER
input |
---|
200000 200000 1 2 1 2 3 2 1 6 3 1 10 12 13 4... |
correct output |
---|
1 2 2 2 1 ... |
user output |
---|
2 3 3 3 2 ... Truncated |
Test 9
Verdict: WRONG ANSWER
input |
---|
200000 200000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
2796 633 633 151 2690 ... |
user output |
---|
151 151 151 152 112876 ... Truncated |
Test 10
Verdict: WRONG ANSWER
input |
---|
200000 200000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
365 73 103 365 216 ... |
user output |
---|
34 37 488 34 490 ... Truncated |
Test 11
Verdict: WRONG ANSWER
input |
---|
2 4 1 1 1 1 2 2 1 ... |
correct output |
---|
1 1 1 2 |
user output |
---|
2 1 1 1 |
Test 12
Verdict: WRONG ANSWER
input |
---|
200000 200000 1 1 2 3 4 5 6 7 8 9 10 11 12 1... |
correct output |
---|
27468 6353 27468 6353 6353 ... |
user output |
---|
6353 5269 6353 5269 5269 ... Truncated |