#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int n, q, t, a, b;
cin >> n >> q >> t;
vector<int> A;
for (int i = 0; i < n; i++) {
cin >> a;
a--;
A.push_back(a);
}
for (int i = 0; i < q; i++) {
cin >> a >> b;
a--, b--;
while (a != b) {
int ka = (1 + pow(1 + 8 * a, 0.5f)) / 2;
int kb = (1 + pow(1 + 8 * b, 0.5f)) / 2;
if (ka < kb) {
b -= kb;
if (b < A[kb - 2])
b++;
}
else if (ka > kb) {
a -= ka;
if (a < A[ka - 2])
a++;
}
else {
b -= kb;
if (b < A[kb - 2])
b++;
a -= ka;
if (a < A[ka - 2])
a++;
}
}
cout << a + 1 << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |