#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e5, INF=1e9, ROOT=450;
int n, d, u;
vector<int> h, a, b;
vector<int> adj[ROOT][MAXN];
void init(int N, int D, int H[])
{
n=N;
d=D;
h.resize(n);
for (int i=0; i<n; i++)
h[i]=H[i];
return;
}
void curseChanges(int U, int A[], int B[])
{
u=U;
a.resize(u);
b.resize(u);
for (int i=0; i<u; i++)
a[i]=A[i];
for (int i=0; i<=u; i++)
b[i]=B[i];
set<int> currentadj[MAXN];
for (int i=0; i<u; i++)
{
if (i%ROOT==0)
{
for (int j=0; j<n; j++)
{
adj[i/ROOT][j].clear();
for (auto t : currentadj[j])
adj[i/ROOT][j].push_back(t);
}
}
if (i==u)
break;
if (!currentadj[a[i]].count(b[i]))
{
currentadj[a[i]].insert(b[i]);
currentadj[b[i]].insert(a[i]);
}
else
{
currentadj[a[i]].erase(b[i]);
currentadj[b[i]].erase(a[i]);
}
}
return;
}
int question(int x, int y, int v)
{
set<int> xtrust, ytrust;
for (auto t : adj[v/ROOT][x])
xtrust.insert(t);
for (auto t : adj[v/ROOT][y])
ytrust.insert(t);
for (int i=v-v%ROOT; i<v; i++)
{
if (a[i]==x)
{
if (!xtrust.count(b[i]))
xtrust.insert(b[i]);
else
xtrust.erase(b[i]);
}
if (b[i]==x)
{
if (!xtrust.count(a[i]))
xtrust.insert(a[i]);
else
xtrust.erase(a[i]);
}
if (a[i]==y)
{
if (!ytrust.count(b[i]))
ytrust.insert(b[i]);
else
ytrust.erase(b[i]);
}
if (b[i]==y)
{
if (!ytrust.count(a[i]))
ytrust.insert(a[i]);
else
ytrust.erase(a[i]);
}
}
vector<int> vx, vy;
for (auto t : xtrust)
vx.push_back(h[t]);
for (auto t : ytrust)
vy.push_back(h[t]);
sort(vx.begin(), vx.end());
sort(vy.begin(), vy.end());
if (vx.empty() || vy.empty())
return INF;
int mind=INF;
int j=0;
for (int i=0; i<vx.size(); i++)
{
while (j<vy.size() && vx[i]>vy[j])
j=j+1;
if (j<vy.size())
mind=min(mind, vy[j]-vx[i]);
if (j-1>=0)
mind=min(mind, vx[i]-vy[j-1]);
}
return mind;
}
Compilation message
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:109:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | for (int i=0; i<vx.size(); i++)
| ~^~~~~~~~~~
potion.cpp:111:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
111 | while (j<vy.size() && vx[i]>vy[j])
| ~^~~~~~~~~~
potion.cpp:113:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | if (j<vy.size())
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
38 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
39 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
42 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
40 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
39 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
38 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |