Task: | Company Queries II |
Sender: | HFalke |
Submission time: | 2024-10-23 19:45:22 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | TIME LIMIT EXCEEDED | -- | details |
#7 | ACCEPTED | 0.08 s | details |
#8 | ACCEPTED | 0.10 s | details |
#9 | TIME LIMIT EXCEEDED | -- | details |
#10 | ACCEPTED | 0.88 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | TIME LIMIT EXCEEDED | -- | details |
Code
#include <bits/stdc++.h> using namespace std; //Definitions for quicker writing #define REP(i,a,b) for (int i = a; i < b; i++) #define PB push_back #define MP make_pair #define F first #define S second //Typedefs for quicker writing typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef pair<int,int> pi; typedef pair<long long, long long> pl; //Max values const long long lmx = LLONG_MAX; const int imx = INT_MAX; int main() { //IO optimization ios::sync_with_stdio(0); cin.tie(0); //Input definition int n; int q; //Read In cin >> n >> q; int boss[n]; int level[n]; boss[0] = 1; level[0] = 0; REP(i,1,n){ cin >> boss[i]; level[i] = level[boss[i]-1] + 1; } pi queries[q]; REP(i,0,q){ cin >> queries[i].first; cin >> queries[i].second; } //Main part int ans[q]; int emp1, emp2; int lvl1, lvl2; REP(i,0,q){ emp1 = queries[i].first; lvl1 = level[emp1-1]; emp2 = queries[i].second; lvl2 = level[emp2-1]; if(lvl1 < lvl2){ REP(j,0,lvl2-lvl1){ emp2 = boss[emp2-1]; //cout << "l2: " << level[emp2]-1 << "\n"; } } if(lvl2 < lvl1){ REP(j,0,lvl1-lvl2){ emp1 = boss[emp1-1]; //cout << "l1: " << level[emp1]-1 << "\n"; } } while(emp1 != emp2){ emp1 = boss[emp1-1]; emp2 = boss[emp2-1]; } ans[i] = emp1; } //Write out REP(i,0,q) cout << ans[i] << "\n"; //Return return 0; }
Test details
Test 1
Verdict: ACCEPTED
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 |
---|
6 8 3 1 8 ... |
Test 2
Verdict: ACCEPTED
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: ACCEPTED
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 1 1 1 1 ... |
Test 4
Verdict: ACCEPTED
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 |
---|
2 2 3 1 1 ... |
Test 5
Verdict: ACCEPTED
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 |
---|
1 1 1 2 2 ... |
Test 6
Verdict: TIME LIMIT EXCEEDED
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 |
---|
(empty) |
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 ... |
Test 8
Verdict: ACCEPTED
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 |
---|
1 2 2 2 1 ... |
Test 9
Verdict: TIME LIMIT EXCEEDED
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 |
---|
(empty) |
Test 10
Verdict: ACCEPTED
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 |
---|
365 73 103 365 216 ... |
Test 11
Verdict: ACCEPTED
input |
---|
2 4 1 1 1 1 2 2 1 ... |
correct output |
---|
1 1 1 2 |
user output |
---|
1 1 1 2 |
Test 12
Verdict: TIME LIMIT EXCEEDED
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 |
---|
(empty) |