#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
// #define int long long
#define ll long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 2e5+10;
int n, a[maxn], idord[maxn];
vector<pair<int,int>> ord;
vector<pair<int,int>> g[maxn];
vector<pair<int,vector<int>>> frds[maxn];
const int BC = 1;
void init(int N, int D, int H[]) {
n = N;
for(int i = 0; i < n; i++) {
ord.pb(mp(H[i],i));
}
sort(all(ord));
for(int i = 0; i < n; i++) {
idord[ord[i].sc] = i;
a[i] = ord[i].fr;
}
}
void curseChanges(int U, int A[], int B[]) {
for(int i = 0; i < U; i++) {
int u = idord[A[i]];
int v = idord[B[i]];
g[u].pb(mp(i+1,v));
g[v].pb(mp(i+1,u));
}
for(int i = 0; i < n; i++) {
set<int> st;
int cnt = 0;
frds[i].pb(mp(0,vector<int>{}));
for(auto X : g[i]) {
int j = X.sc;
int id = X.fr;
if(st.count(j)) st.erase(j);
else st.insert(j);
if(++cnt == BC || g[i].back().fr == id) {
frds[i].pb(mp(id,vector<int>{}));
for(auto x : st) {
frds[i].back().sc.pb(x);
}
cnt = 0;
}
}
frds[i].pb(mp(U+1,vector<int>{}));
// cout << i << " " << a[i] << endl;
// for(auto x : frds[i]) {
// cout << " " << x.fr << endl;
// }
}
}
int question(int x, int y, int v) {
x = idord[x];
y = idord[y];
vector<int> vcx;
vcx = prev(lower_bound(all(frds[x]),mp(v+1,vector<int>{})))->sc;
// cout << x << " " << " x " << prev(lower_bound(all(frds[x]),mp(v+1,vector<int>{})))->fr << endl;
vector<int> vcy;
vcy = prev(lower_bound(all(frds[y]),mp(v+1,vector<int>{})))->sc;
// cout << " y " << prev(lower_bound(all(frds[y]),mp(v+1,vector<int>{})))->fr << endl;
if(vcx.size() == 0) return 1000000000;
if(vcy.size() == 0) return 1000000000;
int i = 0;
int j = 0;
int ans = inf1;
while(i != vcx.size() && j != vcy.size()) {
ans = min(ans, abs(a[vcx[i]]-a[vcy[j]]));
if(a[vcx[i]] < a[vcy[j]]) {
//increase i
i++;
}
else {
j++;
}
}
return ans;
}
Compilation message
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:89:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | while(i != vcx.size() && j != vcy.size()) {
| ~~^~~~~~~~~~~~~
potion.cpp:89:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | while(i != vcx.size() && j != vcy.size()) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9936 KB |
Output is correct |
2 |
Correct |
6 ms |
9936 KB |
Output is correct |
3 |
Correct |
7 ms |
10020 KB |
Output is correct |
4 |
Correct |
38 ms |
19724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
277 ms |
59084 KB |
Output is correct |
2 |
Correct |
276 ms |
59104 KB |
Output is correct |
3 |
Correct |
264 ms |
64512 KB |
Output is correct |
4 |
Runtime error |
601 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
262 ms |
59016 KB |
Output is correct |
2 |
Runtime error |
753 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
12624 KB |
Output is correct |
2 |
Correct |
55 ms |
13164 KB |
Output is correct |
3 |
Correct |
61 ms |
13012 KB |
Output is correct |
4 |
Correct |
152 ms |
19656 KB |
Output is correct |
5 |
Correct |
127 ms |
18368 KB |
Output is correct |
6 |
Correct |
57 ms |
12532 KB |
Output is correct |
7 |
Correct |
124 ms |
18164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
2 |
Correct |
6 ms |
9936 KB |
Output is correct |
3 |
Correct |
6 ms |
9936 KB |
Output is correct |
4 |
Correct |
7 ms |
10020 KB |
Output is correct |
5 |
Correct |
38 ms |
19724 KB |
Output is correct |
6 |
Correct |
277 ms |
59084 KB |
Output is correct |
7 |
Correct |
276 ms |
59104 KB |
Output is correct |
8 |
Correct |
264 ms |
64512 KB |
Output is correct |
9 |
Runtime error |
601 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |