#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(Node *last)
{
if(last)
{
st = last->st;
dr = last->dr;
val = last->val;
}
else
{
st = nullptr;
dr = nullptr;
val = 0;
}
};
};
struct aint
{
vector<pair<int,Node*>> r;
void update(Node *nod, int poz, int val, int a, int b)
{
if(a==b)
{
nod -> val = val;
return;
}
int mij = (a + b) >> 1;
if(poz<=mij)
{
nod->st = new Node(nod->st);
update(nod->st, poz, val,a,mij);
}
else
{
nod->dr = new Node(nod->dr);
update(nod->dr, poz, val, mij+1,b);
}
if(nod->st)
{
nod->val += nod->st->val;
}
if(nod->dr)
{
nod->val += nod->dr->val;
}
}
void parcurg(Node *nod, int a, int b)
{
if(a==b)
{
l.push_back(a);
return;
}
int mij = (a + b) >> 1;
if(nod->st && nod->st->val)
{
parcurg(nod->st, a,mij);
}
if(nod->dr && nod->dr->val)
{
parcurg(nod->dr, mij+1,b);
}
}
void update_per(int poz, int val, int nr)
{
pair<int, Node*> cur = {nr, new Node(nullptr)};
if(r.size())
{
cur.second -> st = r.back().second -> st;
cur.second -> dr = r.back().second -> dr;
cur.second -> val = r.back().second -> val;
}
r.push_back(cur);
update(cur.second,poz,val,1,n);
}
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;
}
parcurg(r[poz].second,1,n);
}
} ai[nmax + 5];
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<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);
}
}
}
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]);
}
sort(vx.begin(),vx.end());
sort(vy.begin(),vy.end());
int rez = oo;
int poz = 0;
for(int i=0; i<vx.size(); i++)
{
while(poz < vy.size() && vy[poz] < vx[i])
{
++poz;
}
if(poz >= vy.size())
{
break;
}
rez = min(rez, vy[poz] - vx[i]);
}
poz = 0;
for(int i=0; i<vy.size(); i++)
{
while(poz < vx.size() && vx[poz] < vy[i])
{
++poz;
}
if(poz >= vx.size())
{
break;
}
rez = min(rez, vx[poz] - vy[i]);
}
return rez;
}
Compilation message
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:175:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
175 | for(int i=0; i<vx.size(); i++)
| ~^~~~~~~~~~
potion.cpp:177:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
177 | while(poz < vy.size() && vy[poz] < vx[i])
| ~~~~^~~~~~~~~~~
potion.cpp:181:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
181 | if(poz >= vy.size())
| ~~~~^~~~~~~~~~~~
potion.cpp:188:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
188 | for(int i=0; i<vy.size(); i++)
| ~^~~~~~~~~~
potion.cpp:190:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
190 | while(poz < vx.size() && vx[poz] < vy[i])
| ~~~~^~~~~~~~~~~
potion.cpp:194:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
194 | if(poz >= vx.size())
| ~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
3608 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
666 ms |
245620 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
748 ms |
246208 KB |
Output is correct |
2 |
Execution timed out |
3049 ms |
234880 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
13144 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Incorrect |
4 ms |
3608 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |