#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5;
const int oo = 1e9;
int n;
int h[nmax + 5];
set<pair<int,int>> s;
vector<int> l;
/*struct Node
{
Node *st, *dr;
int val = 0;
Node()
{
st = nullptr;
dr = nullptr;
val = 0;
}
};
struct aint
{
void update(Node *nod, int val, int nod, int a, int b)
{
if(a==b)
{
}
}
void update_per(int poz, int val, int nr)
{
pair<int, *Node> val = {nr, new Node};
if(r.size())
{
val.second -> st = r.back() -> st;
val.second -> dr = r.back() -> dr;
val.second -> val = r.back() -> val;
}
r.push_back(val);
update(r.back().second, val, 1,1,n);
}
};
*/
struct idk
{
vector<pair<int,set<int>>> r;
void update_per(int poz, int val, int nr)
{
set<int> aux;
pair<int, set<int> > cur = {nr, aux};
if(r.size())
{
cur.second = r.back().second;
}
if(val==0)
{
auto it = cur.second.lower_bound(poz);
cur.second.erase(it);
}
else
{
cur.second.insert(poz);
}
r.push_back(cur);
}
void find_friends(int v)
{
l.clear();
int st = 0;
int dr = r.size() - 1;
int poz = -1;
while(st<=dr)
{
int mij = (st + dr) >> 1;
if(r[mij].first <= v)
{
poz = mij;
st = mij + 1;
}
else
{
dr = mij - 1;
}
}
if(poz==-1)
{
return;
}
for(auto it=r[poz].second.begin();it!=r[poz].second.end();it++)
{
l.push_back(*it);
}
}
} ai[nmax + 5];
void init(int N, int D, int H[])
{
n = N;
for(int i=1; i<=n; i++)
{
h[i] = H[i];
}
}
void curseChanges(int U, int A[], int B[])
{
for(int i=0; i<U; i++)
{
int x = A[i];
int y = B[i];
if(x > y)
{
swap(x,y);
}
if(s.find({x,y})==s.end())
{
s.insert({x,y});
ai[x].update_per(y,+1,i + 1);
ai[y].update_per(x,+1,i + 1);
}
else
{
auto it = s.find({x,y});
s.erase(it);
ai[x].update_per(y,0,i + 1);
ai[y].update_per(x,0,i + 1);
}
}
for(int i=1;i<=U;i++)
{
ai[3].find_friends(i);
for(auto it : l)
{
cerr<<it<<' ';
}
cerr<<'\n';
}
}
int question(int x, int y, int v)
{
ai[x].find_friends(v);
vector<int> vx;
for(auto it : l)
{
vx.push_back(h[it]);
}
ai[y].find_friends(v);
vector<int> vy;
for(auto it : l)
{
vy.push_back(h[it]);
}
int Min = oo;
for(int i=0;i<vx.size();i++)
{
for(int j=0;j<vy.size();j++)
{
Min = min(Min, abs(vx[i] - vy[j]));
}
}
return Min;
}
Compilation message
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:163:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
163 | for(int i=0;i<vx.size();i++)
| ~^~~~~~~~~~
potion.cpp:165:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
165 | for(int j=0;j<vy.size();j++)
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
3208 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2569 ms |
106212 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
993 ms |
101824 KB |
Output is correct |
2 |
Runtime error |
387 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
64 ms |
6812 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Incorrect |
5 ms |
3208 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |