#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,set<pii>> piv;
int n,h[100005];
const int sq=50;
vector<pii> c[100005];
vector<piv> v[100005];
bool comp(int a, int b) {return h[a]<h[b];}
void init(int N, int D, int H[]) {
n=N;
for (int i=0; i<n; ++i) h[i]=H[i], v[i].push_back(piv(0,{}));
}
void curseChanges(int U, int A[], int B[]) {
for (int i=0; i<U; ++i) {
c[A[i]].push_back(pii(i+1,B[i]));
c[B[i]].push_back(pii(i+1,A[i]));
}
for (int i=0; i<n; ++i) {
set<pii> temp;
for (int j=0; j<c[i].size(); ++j) {
int add=c[i][j].second;
if (temp.find(pii(h[add],add))==temp.end()) temp.insert(pii(h[add],add));
else temp.erase(temp.find(pii(h[add],add)));
if ((j+1)%sq==0) v[i].push_back(piv(c[i][j].first,temp));
}
}
}
int question(int x, int y, int day) {
int hx=upper_bound(v[x].begin(),v[x].end(),piv(day+1,{}))-v[x].begin()-1;
int hy=upper_bound(v[y].begin(),v[y].end(),piv(day+1,{}))-v[y].begin()-1;
set<pii> tempX=v[x][hx].second, tempY=v[y][hy].second;
int Hx=upper_bound(c[x].begin(),c[x].end(),pii(v[x][hx].first,INT_MAX))-c[x].begin();
int Hy=upper_bound(c[y].begin(),c[y].end(),pii(v[y][hy].first,INT_MAX))-c[y].begin();
while (Hx<c[x].size() && c[x][Hx].first<=day) {
int add=c[x][Hx].second;
if (tempX.find(pii(h[add],add))==tempX.end()) tempX.insert(pii(h[add],add));
else tempX.erase(tempX.find(pii(h[add],add)));
++Hx;
}
while (Hy<c[y].size() && c[y][Hy].first<=day) {
int add=c[y][Hy].second;
if (tempY.find(pii(h[add],add))==tempY.end()) tempY.insert(pii(h[add],add));
else tempY.erase(tempY.find(pii(h[add],add)));
++Hy;
}
int ans=1e9;
auto itx=tempX.begin(), ity=tempY.begin();
while (itx!=tempX.end() && ity!=tempY.end()) {
ans=min(ans,abs((*itx).first-(*ity).first));
if ((*itx).first<(*ity).first) ++itx;
else ++ity;
}
return ans;
}
Compilation message
potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:26:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for (int j=0; j<c[i].size(); ++j) {
| ~^~~~~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:44:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | while (Hx<c[x].size() && c[x][Hx].first<=day) {
| ~~^~~~~~~~~~~~
potion.cpp:51:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | while (Hy<c[y].size() && c[y][Hy].first<=day) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5028 KB |
Output is correct |
2 |
Correct |
4 ms |
5072 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
19 ms |
12104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
19888 KB |
Output is correct |
2 |
Correct |
149 ms |
19824 KB |
Output is correct |
3 |
Correct |
313 ms |
21176 KB |
Output is correct |
4 |
Correct |
1366 ms |
58204 KB |
Output is correct |
5 |
Correct |
495 ms |
13872 KB |
Output is correct |
6 |
Correct |
2229 ms |
86348 KB |
Output is correct |
7 |
Correct |
642 ms |
25884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
19848 KB |
Output is correct |
2 |
Correct |
1646 ms |
93120 KB |
Output is correct |
3 |
Correct |
1072 ms |
52556 KB |
Output is correct |
4 |
Correct |
1802 ms |
85872 KB |
Output is correct |
5 |
Correct |
296 ms |
23488 KB |
Output is correct |
6 |
Correct |
1888 ms |
86136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
6096 KB |
Output is correct |
2 |
Correct |
183 ms |
6096 KB |
Output is correct |
3 |
Correct |
266 ms |
6144 KB |
Output is correct |
4 |
Correct |
792 ms |
7376 KB |
Output is correct |
5 |
Correct |
722 ms |
6992 KB |
Output is correct |
6 |
Correct |
151 ms |
5436 KB |
Output is correct |
7 |
Correct |
697 ms |
7120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
5028 KB |
Output is correct |
3 |
Correct |
4 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
19 ms |
12104 KB |
Output is correct |
6 |
Correct |
151 ms |
19888 KB |
Output is correct |
7 |
Correct |
149 ms |
19824 KB |
Output is correct |
8 |
Correct |
313 ms |
21176 KB |
Output is correct |
9 |
Correct |
1366 ms |
58204 KB |
Output is correct |
10 |
Correct |
495 ms |
13872 KB |
Output is correct |
11 |
Correct |
2229 ms |
86348 KB |
Output is correct |
12 |
Correct |
642 ms |
25884 KB |
Output is correct |
13 |
Correct |
148 ms |
19848 KB |
Output is correct |
14 |
Correct |
1646 ms |
93120 KB |
Output is correct |
15 |
Correct |
1072 ms |
52556 KB |
Output is correct |
16 |
Correct |
1802 ms |
85872 KB |
Output is correct |
17 |
Correct |
296 ms |
23488 KB |
Output is correct |
18 |
Correct |
1888 ms |
86136 KB |
Output is correct |
19 |
Correct |
35 ms |
6096 KB |
Output is correct |
20 |
Correct |
183 ms |
6096 KB |
Output is correct |
21 |
Correct |
266 ms |
6144 KB |
Output is correct |
22 |
Correct |
792 ms |
7376 KB |
Output is correct |
23 |
Correct |
722 ms |
6992 KB |
Output is correct |
24 |
Correct |
151 ms |
5436 KB |
Output is correct |
25 |
Correct |
697 ms |
7120 KB |
Output is correct |
26 |
Correct |
823 ms |
41092 KB |
Output is correct |
27 |
Correct |
1160 ms |
52628 KB |
Output is correct |
28 |
Correct |
1145 ms |
47304 KB |
Output is correct |
29 |
Correct |
1300 ms |
58260 KB |
Output is correct |
30 |
Correct |
2124 ms |
86348 KB |
Output is correct |
31 |
Correct |
1983 ms |
96112 KB |
Output is correct |
32 |
Correct |
2041 ms |
86264 KB |
Output is correct |