#include<bits/stdc++.h>
void debug(){}
#define NN 100100
using namespace std;
int h[NN], n;
map<int, vector<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++) {
if(i==10) debug();
int a = A[i-1], b = B[i-1];
vector<int> x = (--adj[a].end())->second, y = (--adj[b].end())->second;
if(find(x.begin(), x.end(), b)!=x.end()) {
int i=0;
while(x[i]!=b)i++;
while(i<x.size()-1)x[i]=x[i+1], i++;
x.pop_back(), i=0;
while(y[i]!=a)i++;
while(i<y.size()-1)y[i]=y[i+1], i++;
y.pop_back();
} else x.push_back(b),y.push_back(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) {
vector<int> a = (--adj[x].upper_bound(v))->second, b = (--adj[y].upper_bound(v))->second;
for(auto &i: a) i = h[i];
for(auto &i: b) i = h[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
return calc(a,b);
}
Compilation message
potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | while(i<x.size()-1)x[i]=x[i+1], i++;
| ~^~~~~~~~~~~
potion.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | while(i<y.size()-1)y[i]=y[i+1], i++;
| ~^~~~~~~~~~~
potion.cpp: In function 'int calc(std::vector<int>, std::vector<int>)':
potion.cpp:33:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
| ~~^~~~~~~~~~
potion.cpp:33:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5328 KB |
Output is correct |
2 |
Correct |
3 ms |
5328 KB |
Output is correct |
3 |
Correct |
4 ms |
5328 KB |
Output is correct |
4 |
Correct |
19 ms |
13876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
299 ms |
59284 KB |
Output is correct |
2 |
Correct |
318 ms |
59320 KB |
Output is correct |
3 |
Correct |
280 ms |
66764 KB |
Output is correct |
4 |
Correct |
1247 ms |
241556 KB |
Output is correct |
5 |
Correct |
473 ms |
77232 KB |
Output is correct |
6 |
Runtime error |
316 ms |
262144 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
326 ms |
59304 KB |
Output is correct |
2 |
Runtime error |
244 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
8128 KB |
Output is correct |
2 |
Correct |
70 ms |
8504 KB |
Output is correct |
3 |
Correct |
76 ms |
8568 KB |
Output is correct |
4 |
Correct |
487 ms |
13204 KB |
Output is correct |
5 |
Correct |
503 ms |
11996 KB |
Output is correct |
6 |
Correct |
63 ms |
7888 KB |
Output is correct |
7 |
Correct |
384 ms |
12400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
5328 KB |
Output is correct |
3 |
Correct |
3 ms |
5328 KB |
Output is correct |
4 |
Correct |
4 ms |
5328 KB |
Output is correct |
5 |
Correct |
19 ms |
13876 KB |
Output is correct |
6 |
Correct |
299 ms |
59284 KB |
Output is correct |
7 |
Correct |
318 ms |
59320 KB |
Output is correct |
8 |
Correct |
280 ms |
66764 KB |
Output is correct |
9 |
Correct |
1247 ms |
241556 KB |
Output is correct |
10 |
Correct |
473 ms |
77232 KB |
Output is correct |
11 |
Runtime error |
316 ms |
262144 KB |
Execution killed with signal 9 |
12 |
Halted |
0 ms |
0 KB |
- |