Submission #982480

# Submission time Handle Problem Language Result Execution time Memory
982480 2024-05-14T09:49:11 Z MarwenElarbi Roller Coaster Railroad (IOI16_railroad) C++17
0 / 100
141 ms 18772 KB
#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;
}*/

Compilation message

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
1 Correct 1 ms 3420 KB n = 2
2 Correct 1 ms 3420 KB n = 2
3 Correct 1 ms 3420 KB n = 2
4 Correct 1 ms 3420 KB n = 2
5 Correct 1 ms 3420 KB n = 2
6 Incorrect 2 ms 3420 KB answer is not correct: 1 instead of 523688153
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB n = 2
2 Correct 1 ms 3420 KB n = 2
3 Correct 1 ms 3420 KB n = 2
4 Correct 1 ms 3420 KB n = 2
5 Correct 1 ms 3420 KB n = 2
6 Incorrect 2 ms 3420 KB answer is not correct: 1 instead of 523688153
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 141 ms 15156 KB n = 199999
2 Correct 89 ms 14896 KB n = 199991
3 Correct 52 ms 18772 KB n = 199993
4 Incorrect 87 ms 16724 KB answer is not correct: 1 instead of 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB n = 2
2 Correct 1 ms 3420 KB n = 2
3 Correct 1 ms 3420 KB n = 2
4 Correct 1 ms 3420 KB n = 2
5 Correct 1 ms 3420 KB n = 2
6 Incorrect 2 ms 3420 KB answer is not correct: 1 instead of 523688153
7 Halted 0 ms 0 KB -