#include<bits/stdc++.h>
//#include "potion.h"
#pragma GCC optimize(2)
#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];
}
set<int> arr[100100];
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 = arr[a], &y = arr[b];
if(x.count(b)) x.erase(b), y.erase(a);
else x.insert(b), y.insert(a);
set<int> x1, y1;
for(auto j: x) x1.insert(h[j]);
for(auto j: y) y1.insert(h[j]);
adj[a][i] = x1, adj[b][i] = y1;
}
}
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(i);
for(auto i: b) d.push_back(i);
return calc(c,d);
}
Compilation message
potion.cpp: In function 'int calc(std::vector<int>, std::vector<int>)':
potion.cpp:29:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
| ~~^~~~~~~~~~
potion.cpp:29:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
10192 KB |
Output is correct |
2 |
Correct |
5 ms |
10192 KB |
Output is correct |
3 |
Correct |
6 ms |
10192 KB |
Output is correct |
4 |
Correct |
20 ms |
20268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
680 ms |
134024 KB |
Output is correct |
2 |
Correct |
677 ms |
134076 KB |
Output is correct |
3 |
Correct |
903 ms |
237512 KB |
Output is correct |
4 |
Runtime error |
930 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
591 ms |
107228 KB |
Output is correct |
2 |
Correct |
1755 ms |
83216 KB |
Output is correct |
3 |
Correct |
2294 ms |
89364 KB |
Output is correct |
4 |
Execution timed out |
3091 ms |
80984 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
15440 KB |
Output is correct |
2 |
Correct |
109 ms |
20804 KB |
Output is correct |
3 |
Correct |
177 ms |
21640 KB |
Output is correct |
4 |
Correct |
885 ms |
76688 KB |
Output is correct |
5 |
Correct |
844 ms |
60532 KB |
Output is correct |
6 |
Correct |
153 ms |
22656 KB |
Output is correct |
7 |
Correct |
700 ms |
66620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9680 KB |
Output is correct |
2 |
Correct |
6 ms |
10192 KB |
Output is correct |
3 |
Correct |
5 ms |
10192 KB |
Output is correct |
4 |
Correct |
6 ms |
10192 KB |
Output is correct |
5 |
Correct |
20 ms |
20268 KB |
Output is correct |
6 |
Correct |
680 ms |
134024 KB |
Output is correct |
7 |
Correct |
677 ms |
134076 KB |
Output is correct |
8 |
Correct |
903 ms |
237512 KB |
Output is correct |
9 |
Runtime error |
930 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |