#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];
map<int, int> mp[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), mp[a][h[b]]--, y.erase(a), mp[b][h[a]]--;
else x.insert(b), y.insert(a), mp[a][h[b]]++, mp[b][h[a]]++;
set<int> x1, y1;
for(auto j: mp[a]) if(j.second)x1.insert(j.first);
for(auto j: mp[b]) if(j.second)y1.insert(j.first);
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:30:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
| ~~^~~~~~~~~~
potion.cpp:30:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
15056 KB |
Output is correct |
2 |
Correct |
9 ms |
15056 KB |
Output is correct |
3 |
Correct |
11 ms |
15060 KB |
Output is correct |
4 |
Correct |
25 ms |
25012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
783 ms |
157496 KB |
Output is correct |
2 |
Correct |
797 ms |
157596 KB |
Output is correct |
3 |
Correct |
1002 ms |
242288 KB |
Output is correct |
4 |
Runtime error |
818 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
631 ms |
120008 KB |
Output is correct |
2 |
Correct |
404 ms |
90276 KB |
Output is correct |
3 |
Correct |
682 ms |
98532 KB |
Output is correct |
4 |
Correct |
709 ms |
98468 KB |
Output is correct |
5 |
Correct |
634 ms |
119540 KB |
Output is correct |
6 |
Correct |
635 ms |
98508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
21072 KB |
Output is correct |
2 |
Correct |
116 ms |
25864 KB |
Output is correct |
3 |
Correct |
150 ms |
26440 KB |
Output is correct |
4 |
Correct |
724 ms |
81856 KB |
Output is correct |
5 |
Correct |
659 ms |
66024 KB |
Output is correct |
6 |
Correct |
159 ms |
28332 KB |
Output is correct |
7 |
Correct |
590 ms |
71448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14416 KB |
Output is correct |
2 |
Correct |
10 ms |
15056 KB |
Output is correct |
3 |
Correct |
9 ms |
15056 KB |
Output is correct |
4 |
Correct |
11 ms |
15060 KB |
Output is correct |
5 |
Correct |
25 ms |
25012 KB |
Output is correct |
6 |
Correct |
783 ms |
157496 KB |
Output is correct |
7 |
Correct |
797 ms |
157596 KB |
Output is correct |
8 |
Correct |
1002 ms |
242288 KB |
Output is correct |
9 |
Runtime error |
818 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |