#include <bits/stdc++.h>
using namespace std;
typedef pair<int,vector<int>> piv;
int n,h[100005];
vector<piv> v[100005];
void add(int x, int y, int t) { //add y to x
vector<int> temp;
bool f=false;
for (auto s : v[x].back().second) {
if (s<h[y]) temp.push_back(s);
else {
if (!f) {
if (s!=h[y]) {
temp.push_back(h[y]);
temp.push_back(s);
}
f=true;
} else {
temp.push_back(s);
}
}
}
if (!f) temp.push_back(h[y]);
v[x].push_back(piv(t,temp));
}
void init(int N, int D, int H[]) {
n=N;
for (int i=0; i<n; ++i) h[i]=H[i], v[i].push_back(piv(0,{}));
}
void curseChanges(int U, int A[], int B[]) {
for (int i=0; i<U; ++i) {
add(A[i],B[i],i+1);
add(B[i],A[i],i+1);
}
}
int question(int x, int y, int day) {
int hx=upper_bound(v[x].begin(),v[x].end(),piv(day+1,{}))-v[x].begin()-1;
int hy=upper_bound(v[y].begin(),v[y].end(),piv(day+1,{}))-v[y].begin()-1;
int xi=0, yi=0, nx=v[x][hx].second.size(), ny=v[y][hy].second.size();
if (!nx || !ny) return 1e9;
else {
int ans=INT_MAX;
while (xi<nx && yi<ny) {
ans=min(ans,abs(v[x][hx].second[xi]-v[y][hy].second[yi]));
if (xi>yi) ++yi;
else ++xi;
}
return ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2896 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
239 ms |
41468 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
197 ms |
38724 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
4852 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2896 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |