#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 - 1);
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+1,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())
| ~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3416 KB |
Output is correct |
2 |
Correct |
3 ms |
3416 KB |
Output is correct |
3 |
Correct |
3 ms |
3416 KB |
Output is correct |
4 |
Correct |
11 ms |
4692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
802 ms |
245668 KB |
Output is correct |
2 |
Correct |
806 ms |
245584 KB |
Output is correct |
3 |
Correct |
486 ms |
234324 KB |
Output is correct |
4 |
Execution timed out |
3053 ms |
154532 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
753 ms |
245920 KB |
Output is correct |
2 |
Execution timed out |
3078 ms |
235060 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
12892 KB |
Output is correct |
2 |
Correct |
208 ms |
12632 KB |
Output is correct |
3 |
Correct |
278 ms |
12184 KB |
Output is correct |
4 |
Correct |
1466 ms |
12368 KB |
Output is correct |
5 |
Correct |
1282 ms |
13104 KB |
Output is correct |
6 |
Correct |
172 ms |
10584 KB |
Output is correct |
7 |
Correct |
1294 ms |
12352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
3 ms |
3416 KB |
Output is correct |
3 |
Correct |
3 ms |
3416 KB |
Output is correct |
4 |
Correct |
3 ms |
3416 KB |
Output is correct |
5 |
Correct |
11 ms |
4692 KB |
Output is correct |
6 |
Correct |
802 ms |
245668 KB |
Output is correct |
7 |
Correct |
806 ms |
245584 KB |
Output is correct |
8 |
Correct |
486 ms |
234324 KB |
Output is correct |
9 |
Execution timed out |
3053 ms |
154532 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |