#include<bits/stdc++.h>
//#include "potion.h"
#define NN 100100
using namespace std;
int h[NN], n;
map<int, set<int>> adj[NN];
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 < n; i++) adj[i][0];
for(int i = 1; i <= U; i++) {
int a = A[i-1], b = B[i-1];
set<int> x = (--adj[a].end())->second, y = (--adj[b].end())->second;
if(x.count(b)) x.erase(b), y.erase(a);
else x.insert(b), y.insert(a);
adj[a][i] = x, adj[b][i] = y;
}
}
int calc(vector<int> a, vector<int> b){
int ans = 1e9;
for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
if(a[i]>b[j]) swap(a, b), swap(i, j);
if(j) ans=min(ans,abs(a[i]-b[j-1]));
ans = min(ans, abs(a[i] - b[j]));
}
return ans;
}
int question(int x, int y, int v) {
set<int> a = (--adj[x].upper_bound(v))->second, b = (--adj[y].upper_bound(v))->second;
vector<int> c, d;
for(auto i: a) c.push_back(h[i]);
for(auto i: b) d.push_back(h[i]);
sort(c.begin(), c.end());
sort(d.begin(), d.end());
return calc(c,d);
}
Compilation message
potion.cpp: In function 'int calc(std::vector<int>, std::vector<int>)':
potion.cpp:25:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
| ~~^~~~~~~~~~
potion.cpp:25:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5456 KB |
Output is correct |
2 |
Correct |
4 ms |
5456 KB |
Output is correct |
3 |
Correct |
4 ms |
5456 KB |
Output is correct |
4 |
Correct |
19 ms |
15432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
459 ms |
110536 KB |
Output is correct |
2 |
Correct |
474 ms |
110592 KB |
Output is correct |
3 |
Correct |
786 ms |
232780 KB |
Output is correct |
4 |
Runtime error |
472 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
497 ms |
110732 KB |
Output is correct |
2 |
Runtime error |
386 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
9908 KB |
Output is correct |
2 |
Correct |
147 ms |
16016 KB |
Output is correct |
3 |
Correct |
175 ms |
16908 KB |
Output is correct |
4 |
Correct |
1176 ms |
71384 KB |
Output is correct |
5 |
Correct |
1186 ms |
55052 KB |
Output is correct |
6 |
Correct |
165 ms |
17104 KB |
Output is correct |
7 |
Correct |
976 ms |
61808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
4 ms |
5456 KB |
Output is correct |
3 |
Correct |
4 ms |
5456 KB |
Output is correct |
4 |
Correct |
4 ms |
5456 KB |
Output is correct |
5 |
Correct |
19 ms |
15432 KB |
Output is correct |
6 |
Correct |
459 ms |
110536 KB |
Output is correct |
7 |
Correct |
474 ms |
110592 KB |
Output is correct |
8 |
Correct |
786 ms |
232780 KB |
Output is correct |
9 |
Runtime error |
472 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |