#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> h;
struct cmp{
bool operator()(const int &a,const int &b)const{
if(h[a]==h[b]){
return a<b;
}
return h[a]<h[b];
}
};
vector<unordered_map<int,vector<pair<int,int>>>> s;
void init(int N, int D, int H[]) {
n=N;
h.resize(n);
s.resize(n);
for(int i=0;i<n;i++){
h[i]=H[i];
}
}
void curseChanges(int U, int A[], int B[]) {
for(int i=1;i<=U;i++){
int a=A[i-1];
int b=B[i-1];
if(s[a].find(b)==s[a].end()||s[a][b].back().second==0){
s[a][b].push_back({i,1});
s[b][a].push_back({i,1});
}
else{
s[a][b].push_back({i,0});
s[b][a].push_back({i,0});
}
}
}
int question(int x, int y, int v) {
int ans=1000000000;
vector<int> a,b;
for(pair<int,vector<pair<int,int>>> j:s[x]){
int tmp=(--upper_bound(j.second.begin(),j.second.end(),make_pair(v,10)))->second;
if(tmp==1){
a.push_back(j.first);
}
}
for(pair<int,vector<pair<int,int>>> j:s[y]){
int tmp=(--upper_bound(j.second.begin(),j.second.end(),make_pair(v,10)))->second;
if(tmp==1){
b.push_back(j.first);
}
}
sort(a.begin(),a.end(),cmp());
sort(b.begin(),b.end(),cmp());
int ptr1=0,ptr2=0;
while(ptr1<a.size()&&ptr2<b.size()){
int a1=a[ptr1];
int b1=b[ptr2];
ans=min(ans,abs(h[a1]-h[b1]));
if(h[a1]<h[b1]){
ptr1++;
}
else{
ptr2++;
}
}
return ans;
}
Compilation message
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:56:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | while(ptr1<a.size()&&ptr2<b.size()){
| ~~~~^~~~~~~~~
potion.cpp:56:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | while(ptr1<a.size()&&ptr2<b.size()){
| ~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
3 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
15 ms |
6848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
344 ms |
50228 KB |
Output is correct |
2 |
Correct |
343 ms |
50260 KB |
Output is correct |
3 |
Correct |
760 ms |
12560 KB |
Output is correct |
4 |
Execution timed out |
3021 ms |
27936 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
344 ms |
50144 KB |
Output is correct |
2 |
Execution timed out |
3020 ms |
23088 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
3532 KB |
Output is correct |
2 |
Correct |
171 ms |
1872 KB |
Output is correct |
3 |
Correct |
309 ms |
1360 KB |
Output is correct |
4 |
Correct |
1702 ms |
2896 KB |
Output is correct |
5 |
Correct |
1494 ms |
3280 KB |
Output is correct |
6 |
Correct |
163 ms |
2128 KB |
Output is correct |
7 |
Correct |
1735 ms |
1604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
3 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
15 ms |
6848 KB |
Output is correct |
6 |
Correct |
344 ms |
50228 KB |
Output is correct |
7 |
Correct |
343 ms |
50260 KB |
Output is correct |
8 |
Correct |
760 ms |
12560 KB |
Output is correct |
9 |
Execution timed out |
3021 ms |
27936 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |