# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
701858 | Darren0724 | The Potion of Great Power (CEOI20_potion) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "grader.cpp"
#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<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].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;
}