답안 #849843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849843 2023-09-15T12:38:56 Z Ahmed57 Event Hopping (BOI22_events) C++17
0 / 100
405 ms 33736 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
bool cmp(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
    return a.first.second<b.first.second;
}
long long seg[800001];
void build(int p,int l,int r){
    if(l==r){
        seg[p] = 1e18;
        return ;
    }
    int md = (l+r)/2;
    build(p*2,l,md);build(p*2+1,md+1,r);
    seg[p] = min(seg[p*2],seg[p*2+1]);
}
long long query(int p,int l,int r,int lq,int rq){
    if(l>=lq&&r<=rq)return seg[p];
    if(r<lq||l>rq)return 1e18;
    int md = (l+r)/2;
    return min(query(p*2,l,md,lq,rq),query(p*2+1,md+1,r,lq,rq));
}
void update(int p,int l,int r,int idx,long long val){
    if(l==r){
        seg[p] = val;
        return ;
    }
    int md = (l+r)/2;
    if(idx<=md)update(p*2,l,md,idx,val);
    else update(p*2+1,md+1,r,idx,val);
    seg[p] = min(seg[p*2],seg[p*2+1]);
}
signed main(){
    int n,q;cin>>n>>q;
    vector<pair<pair<int,int>,int>> v;
    map<int,int> comp,sav;
    for(int i = 0;i<n;i++){
        int a,b;
        cin>>a>>b;
        comp[a]++;comp[b]++;
        v.push_back({{a,b},i});
    }
    long long z = 0;
    for(auto i:comp){
        sav[i.first] = ++z;
    }
    for(int i = 0;i<n;i++){
        v[i].first.first = sav[v[i].first.first];
        v[i].first.second = sav[v[i].first.second];
    }
    build(1,0,z);
    long long lol = -1e7;
    sort(v.begin(),v.end(),cmp);
    long long llol[n] = {0};
    long long la = 0;
    for(int i = 0;i<v.size();i++){
        long long ans = query(1,0,z,v[i].first.first,v[i].first.second);
        //cout<<ans<<endl;
        if(ans==1e18){
            lol+=1e7;
            ans = lol;
        }else ans++;
        llol[v[i].second] = ans;
        assert(ans>=la);
        la = ans;
        //cout<<ans<<" "<<v[i].first<<" "<<v[i].second<<endl;
        update(1,0,z,v[i].first.second,ans);
    }
    while(q--){
        int a,b;cin>>a>>b;
        a--;b--;
        long long a1 = llol[a];
        long long a2 = llol[b];
        if(abs(a1-a2)>=1e7){
            cout<<"impossible\n";
        }else{
            cout<<abs(a1-a2)<<endl;
        }
    }
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:56:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(int i = 0;i<v.size();i++){
      |                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 346 ms 19380 KB Output is correct
2 Correct 346 ms 19436 KB Output is correct
3 Correct 365 ms 18684 KB Output is correct
4 Correct 405 ms 33736 KB Output is correct
5 Incorrect 345 ms 19132 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -