Submission #982477

# Submission time Handle Problem Language Result Execution time Memory
982477 2024-05-14T09:45:56 Z MarwenElarbi Roller Coaster Railroad (IOI16_railroad) C++17
0 / 100
137 ms 13280 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<int,int> segtree[nax*4];
vector<pair<int,int>> 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<int,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;
    int x=1;
    build(0,0,n-1);
    while(cnt<n){
        int cur=lower_bound(tab.begin(),tab.end(),make_pair(x,0))-tab.begin();
        if(cur==tab.size()) break;
        auto ne=query(0,0,n-1,cur,n-1);
        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<int, 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 1884 KB n = 2
2 Correct 1 ms 1884 KB n = 2
3 Correct 1 ms 1884 KB n = 2
4 Correct 1 ms 1884 KB n = 2
5 Correct 1 ms 1884 KB n = 2
6 Incorrect 1 ms 1884 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 1884 KB n = 2
2 Correct 1 ms 1884 KB n = 2
3 Correct 1 ms 1884 KB n = 2
4 Correct 1 ms 1884 KB n = 2
5 Correct 1 ms 1884 KB n = 2
6 Incorrect 1 ms 1884 KB answer is not correct: 1 instead of 523688153
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 137 ms 13280 KB n = 199999
2 Incorrect 134 ms 13112 KB answer is not correct: 0 instead of 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB n = 2
2 Correct 1 ms 1884 KB n = 2
3 Correct 1 ms 1884 KB n = 2
4 Correct 1 ms 1884 KB n = 2
5 Correct 1 ms 1884 KB n = 2
6 Incorrect 1 ms 1884 KB answer is not correct: 1 instead of 523688153
7 Halted 0 ms 0 KB -