답안 #987181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987181 2024-05-22T08:33:15 Z alexdd Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 8912 KB
#include<bits/stdc++.h>
using namespace std;

/*ifstream fin("events.in");
ofstream fout("events.out");
#define cin fin
#define cout fout*/

int n,q,cate;
pair<int,int> e[100005];
pair<int,int> ord[100005];
vector<pair<int,int>> qrys[100005];
int rez[100005];
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>q;
    int le,ri;
    for(int i=1;i<=n;i++)
    {
        cin>>le>>ri;
        e[i]={le,ri};
        ord[i]={ri,i};
    }
    for(int i=1;i<=q;i++)
    {
        cin>>le>>ri;
        if(le==ri)
        {
            rez[i]=0;
            continue;
        }
        if(e[ri].second < e[le].second)
        {
            rez[i]=-1;
            continue;
        }
        if(e[ri].first <= e[le].second)
        {
            rez[i]=1;
            continue;
        }
        qrys[ri].push_back({le,i});
    }
    sort(ord+1,ord+1+n);
    deque<int> dq;
    for(int i=1;i<=n;i++)
    {
        int x = ord[i].second;
        while(!dq.empty() && e[x].first<=e[dq.back()].first)
            dq.pop_back();
        while((int)dq.size()>=2 && e[x].first<=e[dq[(int)dq.size()-2]].second)
            dq.pop_back();
        dq.push_back(x);

        //cout<<x<<"   ";for(auto y:dq) cout<<y<<" ";cout<<" dq\n";

        for(auto cv:qrys[x])
        {
            int aux = cv.first;
            rez[cv.second]=-1;
            for(int j=(int)dq.size()-1;j>=0;j--)
            {
                if(e[dq[j]].first<=e[aux].second && e[aux].second<=e[dq[j]].second)
                {
                    rez[cv.second] = (int)dq.size()-j;
                    break;
                }
                if(j>0 && e[dq[j]].first > e[dq[j-1]].second)
                    break;
            }
        }

    }
    for(int i=1;i<=q;i++)
    {
        if(rez[i]==-1) cout<<"impossible\n";
        else cout<<rez[i]<<"\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Execution timed out 1539 ms 8912 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4440 KB Output is correct
3 Correct 3 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Incorrect 2 ms 4444 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4440 KB Output is correct
3 Correct 3 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Incorrect 2 ms 4444 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4440 KB Output is correct
3 Correct 3 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Incorrect 2 ms 4444 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1530 ms 8912 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Execution timed out 1539 ms 8912 KB Time limit exceeded
3 Halted 0 ms 0 KB -