답안 #784562

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784562 2023-07-16T09:14:27 Z MohamedAliSaidane Passport (JOI23_passport) C++14
6 / 100
45 ms 20812 KB
#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;

#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()

const int nax = 2e5 + 4;
int n, q;
vi L, R, X;
int sp[nax][20], LG[nax];
void build()
{
    for(int i =0 ; i < n;i++)
        sp[i][0] = R[i];
    //cout << "here" << endl;
    for(int j = 1; j < 20; j++)
    {
        //cout << j << endl;
        for(int i = 0; i + (1 << (j - 1)) < n;i ++)
            sp[i][j] = max(sp[i][j - 1], sp[i + (1 << (j - 1))][j - 1]);
    }
}
int RMQ(int l, int r)
{
    int j = LG[r - l + 1];
    return max(sp[l][j], sp[r- (1 << j) + 1][j]);
}

void solve()
{
    cin >> n;
    L.resize(n); R.resize(n);
    for(int i =0; i < n; i++)
    {
        cin >> L[i] >> R[i];
        L[i]--; R[i]--;
    }

    build();
    //cout << "here" << endl;
    cin >> q;
    while(q--)
    {
        int X; cin >> X;
        X--;
        int l = L[X], r = R[X], cnt = 1;
        while(r < n - 1)
        {
            int maxi = RMQ(l, r);
            //cout << cnt << ' ' << maxi << endl;
            if(maxi == r)
            {
                cnt = -1;
                break;
            }
            r = maxi;
            cnt++;
        }
        cout << cnt << '\n';
    }
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    LG[1] = 0;
    for(int i =2; i < nax; i++)
        LG[i] = LG[i/2] + 1;
    int tt = 1;
    while(tt--)
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 44 ms 20436 KB Output is correct
5 Correct 45 ms 20732 KB Output is correct
6 Correct 45 ms 20812 KB Output is correct
7 Correct 39 ms 19532 KB Output is correct
8 Correct 30 ms 16240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Incorrect 1 ms 1108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Incorrect 1 ms 1108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Incorrect 1 ms 1108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 44 ms 20436 KB Output is correct
5 Correct 45 ms 20732 KB Output is correct
6 Correct 45 ms 20812 KB Output is correct
7 Correct 39 ms 19532 KB Output is correct
8 Correct 30 ms 16240 KB Output is correct
9 Correct 1 ms 1112 KB Output is correct
10 Incorrect 1 ms 1108 KB Output isn't correct
11 Halted 0 ms 0 KB -