This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
void debug(){}
#define NN 100100
using namespace std;
int h[NN], n;
map<int, vector<int>> adj[NN];
void init(int N, int D, int H[]) {
n = N;
for(int i = 0; i < N; i++)
h[i] = H[i];
}
void curseChanges(int U, int A[], int B[]) {
for(int i = 0; i < n; i++) adj[i][0];
for(int i = 1; i <= U; i++) {
if(i==10) debug();
int a = A[i-1], b = B[i-1];
vector<int> x = (--adj[a].end())->second, y = (--adj[b].end())->second;
if(find(x.begin(), x.end(), b)!=x.end()) {
int i=0;
while(x[i]!=b)i++;
while(i<x.size()-1)x[i]=x[i+1], i++;
x.pop_back(), i=0;
while(y[i]!=a)i++;
while(i<y.size()-1)y[i]=y[i+1], i++;
y.pop_back();
} else x.push_back(b),y.push_back(a);
adj[a][i] = x, adj[b][i] = y;
}
}
int calc(vector<int> a, vector<int> b){
int ans = 1e9;
for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
if(a[i]>b[j]) swap(a, b), swap(i, j);
if(j) ans=min(ans,abs(a[i]-b[j-1]));
ans = min(ans, abs(a[i] - b[j]));
}
return ans;
}
int question(int x, int y, int v) {
vector<int> a = (--adj[x].upper_bound(v))->second, b = (--adj[y].upper_bound(v))->second;
for(auto &i: a) i = h[i];
for(auto &i: b) i = h[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
return calc(a,b);
}
Compilation message (stderr)
potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | while(i<x.size()-1)x[i]=x[i+1], i++;
| ~^~~~~~~~~~~
potion.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | while(i<y.size()-1)y[i]=y[i+1], i++;
| ~^~~~~~~~~~~
potion.cpp: In function 'int calc(std::vector<int>, std::vector<int>)':
potion.cpp:33:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
| ~~^~~~~~~~~~
potion.cpp:33:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
| ~~^~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |