#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5;
const int MAX_M = 3e5;
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;
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 < m; i++ ) {
if ( pos[a[i]][b[i]] == 0 ) {
pos[a[i]][b[i]] = trust[a[i]].size();
trust[a[i]].push_back( b[i] );
pos[b[i]][a[i]] = trust[b[i]].size();
trust[b[i]].push_back( a[i] );
} else {
int l;
l = trust[a[i]].size() - 1;
swap( pos[a[i]][b[i]], pos[a[i]][l] );
swap( trust[a[i]][pos[a[i]][l]], trust[a[i]][l] );
trust[a[i]].pop_back();
l = trust[b[i]].size() - 1;
swap( pos[b[i]][a[i]], pos[b[i]][l] );
swap( trust[b[i]][pos[b[i]][l]], trust[b[i]][l] );
trust[b[i]].pop_back();
}
}
}
int question( int x, int y, int t ) {
hy.clear();
for ( int i = 1; i < trust[y].size(); i++ )
hy.insert( h[trust[y][i]] );
if ( hy.size() == 0 )
return 1e9;
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
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:54:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for ( int i = 1; i < trust[y].size(); i++ )
| ~~^~~~~~~~~~~~~~~~~
potion.cpp:60:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for ( int i = 1; i < trust[x].size(); i++ ) {
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
19032 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
19304 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
254 ms |
48760 KB |
Output is correct |
2 |
Correct |
257 ms |
49044 KB |
Output is correct |
3 |
Runtime error |
62 ms |
49340 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
216 ms |
48956 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
21288 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
19032 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |