#include <bits/stdc++.h>
typedef int ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
using namespace std;
ll h[100001];
struct cmp {
bool operator() (ll a, ll b) const {
if (h[a] == h[b]) return a<b;
return h[a] < h[b];
}
};
vector<array<ll,2>> changes[100001];
vector<set<ll, cmp>> lotchange[100001];
void init(int N, int D, int H[]) {
FOR(i,0,N) h[i] = H[i];
}
void curseChanges(int U, int A[], int B[]) {
vector<set<ll, cmp>> tempedges;
tempedges.resize(100001);
FOR(i,0,U){
if (tempedges[A[i]].find(B[i]) != tempedges[A[i]].end()){
changes[A[i]].push_back({i, B[i]});
tempedges[A[i]].erase(B[i]);
}
else{
changes[A[i]].push_back({i, B[i]});
tempedges[A[i]].insert(B[i]);
}
if (tempedges[B[i]].find(A[i]) != tempedges[B[i]].end()){
changes[B[i]].push_back({i, A[i]});
tempedges[B[i]].erase(A[i]);
}
else{
changes[B[i]].push_back({i, A[i]});
tempedges[B[i]].insert(A[i]);
}
if ((changes[A[i]].size()-1)%50==0){
lotchange[A[i]].push_back(tempedges[A[i]]);
}
if ((changes[B[i]].size()-1)%50==0){
lotchange[B[i]].push_back(tempedges[B[i]]);
}
}
}
int mindiff(map<ll,ll, cmp>&a, map<ll,ll, cmp>&b){
ll ans = 1000000000;
vector<ll> A,B;
for (auto&i : a) if (i.second%2==1) A.push_back(h[i.first]);
for (auto&i : b) if (i.second%2==1) B.push_back(h[i.first]);
ll l=0,r=0;
while (l<A.size() && r<B.size()){
ans = min(ans, abs(A[l] - B[r]));
if (A[l] < B[r]) l++;
else r++;
}
return ans;
return ans;
}
int question(int x, int y, int v) {
v--;
ll ans = 1000000000;
ll pos = upper_bound(changes[x].begin(), changes[x].end(), array<ll, 2>{v, 1000000000})-changes[x].begin();
pos--;
map<ll,ll, cmp> X;
if (pos >= 0){
for (auto&i : lotchange[x][pos/50]) X[i] = 1;
FOR(i, (pos/50)*50+1, pos+1){
ll temp = changes[x][i][1];
X[temp] += 1;
}
}
pos = upper_bound(changes[y].begin(), changes[y].end(), array<ll, 2>{v, 1000000000})-changes[y].begin();
pos--;
map<ll,ll, cmp> Y;
if (pos >= 0){
for (auto&i : lotchange[y][pos/50]) Y[i] = 1;
FOR(i, (pos/50)*50+1, pos+1){
ll temp = changes[y][i][1];
Y[temp] += 1;
}
}
return mindiff(X,Y);
}
Compilation message
potion.cpp: In function 'int mindiff(std::map<int, int, cmp>&, std::map<int, int, cmp>&)':
potion.cpp:72:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | while (l<A.size() && r<B.size()){
| ~^~~~~~~~~
potion.cpp:72:27: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | while (l<A.size() && r<B.size()){
| ~^~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:85:8: warning: unused variable 'ans' [-Wunused-variable]
85 | ll ans = 1000000000;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
10072 KB |
Output is correct |
2 |
Correct |
3 ms |
9952 KB |
Output is correct |
3 |
Correct |
3 ms |
10084 KB |
Output is correct |
4 |
Correct |
12 ms |
10936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
253 ms |
48492 KB |
Output is correct |
2 |
Correct |
264 ms |
48232 KB |
Output is correct |
3 |
Correct |
223 ms |
19664 KB |
Output is correct |
4 |
Correct |
2294 ms |
72372 KB |
Output is correct |
5 |
Correct |
470 ms |
38248 KB |
Output is correct |
6 |
Execution timed out |
3097 ms |
99664 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
211 ms |
48220 KB |
Output is correct |
2 |
Execution timed out |
3094 ms |
96164 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
12120 KB |
Output is correct |
2 |
Correct |
136 ms |
10584 KB |
Output is correct |
3 |
Correct |
223 ms |
10328 KB |
Output is correct |
4 |
Correct |
1212 ms |
12740 KB |
Output is correct |
5 |
Correct |
1285 ms |
12660 KB |
Output is correct |
6 |
Correct |
120 ms |
11096 KB |
Output is correct |
7 |
Correct |
997 ms |
11352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
10072 KB |
Output is correct |
3 |
Correct |
3 ms |
9952 KB |
Output is correct |
4 |
Correct |
3 ms |
10084 KB |
Output is correct |
5 |
Correct |
12 ms |
10936 KB |
Output is correct |
6 |
Correct |
253 ms |
48492 KB |
Output is correct |
7 |
Correct |
264 ms |
48232 KB |
Output is correct |
8 |
Correct |
223 ms |
19664 KB |
Output is correct |
9 |
Correct |
2294 ms |
72372 KB |
Output is correct |
10 |
Correct |
470 ms |
38248 KB |
Output is correct |
11 |
Execution timed out |
3097 ms |
99664 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |