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>
using namespace std;
struct change {
int time, val;
};
const int MAX_N = 1e5;
const int MAX_M = 2e5;
const int MAX_D = 500;
int n, m, d;
int h[MAX_N], a[MAX_M], b[MAX_M];
unordered_map<int, int> pos[MAX_N];
vector<int> trust[MAX_N];
set<int> hy;
vector<change> changes[MAX_N][MAX_D];
void init( int N, int D, int H[] ) {
n = N;
d = D;
for ( int i = 0; i < n; i++ )
h[i] = H[i];
for ( int i = 0; i < n; i++ )
trust[i].push_back( i );
}
void curseChanges( int M, int A[], int B[] ) {
m = M;
for ( int i = 0; i < M; i++ ) {
a[i] = A[i];
b[i] = B[i];
}
for ( int i = 0; i < n; i++ ) {
for ( int j = 0; j < d; j++ )
changes[i][j].push_back( { -1, -1 } );
}
for ( int i = 0; i < m; i++ ) {
if ( pos[a[i]][b[i]] == 0 ) {
pos[a[i]][b[i]] = trust[a[i]].size();
changes[a[i]][trust[a[i]].size()].push_back( { i, b[i] } );
trust[a[i]].push_back( b[i] );
pos[b[i]][a[i]] = trust[b[i]].size();
changes[b[i]][trust[b[i]].size()].push_back( { i, a[i] } );
trust[b[i]].push_back( a[i] );
} else {
int p, l;
p = pos[a[i]][b[i]], l = trust[a[i]].size() - 1;
swap( pos[a[i]][b[i]], pos[a[i]][l] );
swap( trust[a[i]][p], trust[a[i]][l] );
changes[a[i]][p].push_back( { i, trust[a[i]][p] } );
changes[a[i]][l].push_back( { i, -1 } );
trust[a[i]].pop_back();
p = pos[b[i]][a[i]], l = trust[b[i]].size() - 1;
swap( pos[b[i]][a[i]], pos[b[i]][l] );
swap( trust[b[i]][p], trust[b[i]][l] );
changes[b[i]][p].push_back( { i, trust[b[i]][p] } );
changes[b[i]][l].push_back( { i, -1 } );
trust[b[i]].pop_back();
}
}
}
int question( int x, int y, int t ) {
/*for ( int i = 1; i < d; i++ ) {
int l = 0; r = changes[]
}*/
int minDist = 1e9;
for ( int i = 1; i < trust[x].size(); i++ ) {
int hx = h[trust[x][i]];
auto p = hy.upper_bound( hx );
if ( p != hy.end() )
minDist = min( minDist, *p - hx );
if ( p != hy.begin() ) {
p--;
minDist = min( minDist, hx - *p );
}
}
return minDist;
}
Compilation message (stderr)
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:74:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for ( int i = 1; i < trust[x].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... |