이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
const int nax=2e5+5;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
pair<ll,ll> segtree[nax*4];
vector<pair<ll,ll>> tab(nax);
void build(int pos,int l,int r){
if(l==r){
segtree[pos]={tab[l].se,l};
return;
}
int mid=(r+l)/2;
build(pos*2+1,l,mid);
build(pos*2+2,mid+1,r);
segtree[pos]=min(segtree[pos*2+1],segtree[pos*2+2]);
}
void update(int pos,int l,int r,int index){
if(l==r){
segtree[pos]={1e18,l};
return;
}
int mid=(r+l)/2;
if(index<=mid) update(pos*2+1,l,mid,index);
else update(pos*2+2,mid+1,r,index);
segtree[pos]=min(segtree[pos*2+1],segtree[pos*2+2]);
}
pair<ll,int> query(int pos,int l,int r,int left,int right){
if(l>r||l>right||r<left) return {1e18,1e18};
if(l>=left&&r<=right){
return segtree[pos];
}
int mid=(r+l)/2;
return min(query(pos*2+1,l,mid,left,right),query(pos*2+2,mid+1,r,left,right));
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int)s.size();
tab.resize(n);
for (int i = 0; i < n; ++i)
{
tab[i]={s[i],t[i]};
}
sort(tab.begin(),tab.end());
int cnt=0;
ll x=1;
build(0,0,n-1);
while(cnt<n){
int cur=lower_bound(tab.begin(),tab.end(),make_pair(x,1ll*0))-tab.begin();
if(cur==tab.size()) break;
//cout <<x<<" "<<cur<<endl;
auto ne=query(0,0,n-1,cur,n-1);
//cout <<ne.fi<<endl;
if(ne.fi==1e18) break;
update(0,0,n-1,ne.se);
x=tab[ne.se].se;
cnt++;
}
if(cnt>=n) return 0;
else return 1;
}
/*int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
assert(1 == scanf("%d", &n));
std::vector<int> s(n), t(n);
for (int i = 0; i < n; ++i)
assert(2 == scanf("%d%d", &s[i], &t[i]));
long long ans = plan_roller_coaster(s, t);
printf("%lld\n", ans);
return 0;
}*/
컴파일 시 표준 에러 (stderr) 메시지
railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:54:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | if(cur==tab.size()) break;
| ~~~^~~~~~~~~~~~
# | 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... |