#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
typedef complex<int> point;
const int INF = 1e9;
int dist(vector<int>& a, vector<int>& b){
if(a.size() == 0 || b.size() == 0){
return INF;
}
int ia =0, ib = 0;
int res= abs(a[0]-b[0]);
while(ia<a.size()-1 || ib<b.size()-1){
if(ia==a.size()-1){
ib++;
}
else if(ib==b.size()-1){
ia++;
}
else if(a[ia]<=b[ib]){
ia++;
}
else{
ib++;
}
res = min(res, abs(a[ia]-b[ib]));
}
return res;
}
vector<vector<int>> vs;
vector<int> h;
set<pii> cur;
vector<map<int, int>> cur_vals;
vector<vector<pair<int, map<int, int>>>> events;
int n;
void init(int N, int D, int H[]) {
vs.resize(N);
h.resize(N);
cur_vals.resize(N);
events.resize(N);
for(int i = 0; i<N; i++){
h[i] = H[i];
}
n= N;
}
void curseChanges(int U, int A[], int B[]) {
for(int i = 0; i<n; i++){
events[i].push_back({-1, map<int, int>()});
}
for(int i = 0; i<U; i++){
int a= A[i], b= B[i];
if(cur.find({a, b})!=cur.end()){
cur.erase({a, b});
cur_vals[a][h[b]]--;
cur_vals[b][h[a]]--;
}
else if(cur.find({b, a})!=cur.end()){
cur.erase({b, a});
cur_vals[a][h[b]]--;
cur_vals[b][h[a]]--;
}
else{
cur.insert({a, b});
cur_vals[a][h[b]]++;
cur_vals[b][h[a]]++;
}
events[a].push_back({i, cur_vals[a]});
events[b].push_back({i, cur_vals[b]});
}
}
map<int, int> get_last_valid(int id, int d){
int cur= 0;
for(int step= (1<<28); step>=1; step/=2){
if(cur +step<events[id].size()){
if(events[id][cur+step].first<d){
cur+=step;
}
}
}
return events[id][cur].second;
}
int question(int x, int y, int v) {
auto xm =get_last_valid(x, v);
auto ym = get_last_valid(y, v);
vector<int> xv;
vector<int> yv;
for(auto e: xm){
if(e.second>0){
xv.push_back(e.first);
}
}
for(auto e: ym){
if(e.second>0){
yv.push_back(e.first);
}
}
return dist(xv, yv);
}
Compilation message
potion.cpp: In function 'int dist(std::vector<int>&, std::vector<int>&)':
potion.cpp:17:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | while(ia<a.size()-1 || ib<b.size()-1){
| ~~^~~~~~~~~~~
potion.cpp:17:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | while(ia<a.size()-1 || ib<b.size()-1){
| ~~^~~~~~~~~~~
potion.cpp:18:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | if(ia==a.size()-1){
| ~~^~~~~~~~~~~~
potion.cpp:21:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | else if(ib==b.size()-1){
| ~~^~~~~~~~~~~~
potion.cpp: In function 'std::map<int, int> get_last_valid(int, int)':
potion.cpp:85:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::map<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | if(cur +step<events[id].size()){
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1112 KB |
Output is correct |
2 |
Correct |
2 ms |
1112 KB |
Output is correct |
3 |
Correct |
2 ms |
1112 KB |
Output is correct |
4 |
Correct |
19 ms |
17540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
823 ms |
136212 KB |
Output is correct |
2 |
Correct |
865 ms |
136572 KB |
Output is correct |
3 |
Runtime error |
368 ms |
262144 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
646 ms |
98880 KB |
Output is correct |
2 |
Correct |
355 ms |
79736 KB |
Output is correct |
3 |
Correct |
554 ms |
82508 KB |
Output is correct |
4 |
Correct |
533 ms |
82264 KB |
Output is correct |
5 |
Correct |
724 ms |
98036 KB |
Output is correct |
6 |
Correct |
542 ms |
82412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
7156 KB |
Output is correct |
2 |
Correct |
158 ms |
21316 KB |
Output is correct |
3 |
Correct |
220 ms |
22288 KB |
Output is correct |
4 |
Correct |
873 ms |
86032 KB |
Output is correct |
5 |
Correct |
779 ms |
59620 KB |
Output is correct |
6 |
Correct |
127 ms |
14168 KB |
Output is correct |
7 |
Correct |
949 ms |
104536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
1112 KB |
Output is correct |
3 |
Correct |
2 ms |
1112 KB |
Output is correct |
4 |
Correct |
2 ms |
1112 KB |
Output is correct |
5 |
Correct |
19 ms |
17540 KB |
Output is correct |
6 |
Correct |
823 ms |
136212 KB |
Output is correct |
7 |
Correct |
865 ms |
136572 KB |
Output is correct |
8 |
Runtime error |
368 ms |
262144 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |