이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "railroad.h"
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#include <set>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
int n;
pair < int, int > a[maxn];
pair < int, int > b[maxn];
int pos[maxn];
bool bio[maxn];
ll plan_roller_coaster(vector < int > ss, vector < int > t){
n=ss.size();
for(int i=0; i<n; i++){
a[i]={ss[i], i};
b[i]={t[i], i};
}
sort(a, a+n);
sort(b, b+n);
for(int i=0; i<n; i++){
pos[a[i].second]=i;
}
/* for(int i=0; i<n; i++){
cout << a[i] << ' ';
}
cout << endl;
for(int i=0; i<n; i++){
cout << b[i] << ' ';
}
cout << endl;*/
int ind1=0, ind2=0;
ll sol=0;
set < int > s;
s.insert((int)1e9);
while(ind1<n || ind2<n){
if(ind1==n || (ind2!=n && a[ind1].first>=b[ind2].first)){
s.insert(pos[b[ind2].second]);
ind2++;
}
else{
// cout << ind1 << ' ' << ind2 << endl;
if(s.empty() || (s.size()==1 && *s.begin()==ind1)){
// cout << "uso" << endl;
if(b[ind2].second==a[ind1].second){
bio[ind2+1]=1;
sol+=b[ind2+1].first-a[ind1].first;
}
else{
sol+=b[ind2].first-a[ind1].first;
ind2++;
}
}
else{
if(*s.begin()==ind1){
s.erase(++s.begin());
}
else{
s.erase(s.begin());
}
}
ind1++;
}
while(ind2<n && bio[ind2]){
ind2++;
}
}
return sol;
}
//g++ -std=c++17 -Wshadow -Wall -o "%e" "%f" -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |