Submission #973571

# Submission time Handle Problem Language Result Execution time Memory
973571 2024-05-02T07:25:28 Z vjudge1 Passport (JOI23_passport) C++17
6 / 100
98 ms 9048 KB
#include <time.h>
#include <cstdlib>
#include <stack>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <map>
#include <set>
#include <iterator>
#include <deque>
#include <queue>
#include <sstream>
#include <array>
#include <string>
#include <tuple>
#include <chrono>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <list>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <bitset>

using namespace std;

int tt = 1, n;
int a[200005], lf[200005], rg[200005];
int mn[4 * 200005], mx[4 * 200005];
void up(int l, int r, int pos, int num, int num1, int vv){
    if(l > pos || r < pos) return;
    if(l == r){
        mn[vv] = num;
        mx[vv] = num1;
        return; 
    }
    int mid = (l + r) / 2;
    up(l, mid, pos, num, num1, vv * 2);
    up(mid + 1, r, pos, num, num1, vv * 2 + 1);
    mn[vv] = min(mn[vv * 2], mn[vv * 2 + 1]);
    mx[vv] = max(mx[vv * 2], mx[vv * 2 + 1]);
}
int sbor(int l, int r, int l1, int r1, int vv){
    if(l > r1 || l1 > r) return 1e9;
    if(l >= l1 && r1 >= r) return mn[vv];
    int mid = (l + r) / 2;
    return min(sbor(l, mid, l1, r1, vv * 2), sbor(mid + 1, r, l1, r1, vv * 2 + 1));
}
int sbor1(int l, int r, int l1, int r1, int vv){
    if(l > r1 || l1 > r) return 0;
    if(l >= l1 && r1 >= r) return mx[vv];
    int mid = (l + r) / 2;
    return max(sbor1(l, mid, l1, r1, vv * 2), sbor1(mid + 1, r, l1, r1, vv * 2 + 1));
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> lf[i] >> rg[i];
        up(1, n, i, lf[i], rg[i], 1);
    }
    cin >> tt;
    while(tt--){
        int x;
        cin >> x;
        int l = x, r = x, l1 = x, r1 = x, k = 0;
        bool ok = 0;
        while(l != 1 || r != n){
            int mn1 = sbor(1, n, l, r, 1);
            int mx1 = sbor1(1, n, l, r, 1);
            l = mn1, r = mx1;
            k++;
            if(l == l1 && r == r1){
                ok = 1;
                break;
            }
            l1 = l, r1 = r;
        }
        if(ok) cout << -1 << "\n";
        else cout << k << "\n";
    }
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 54 ms 8796 KB Output is correct
5 Correct 56 ms 9048 KB Output is correct
6 Correct 98 ms 8816 KB Output is correct
7 Correct 47 ms 8796 KB Output is correct
8 Correct 38 ms 8792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6744 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Incorrect 1 ms 6492 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6744 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Incorrect 1 ms 6492 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6744 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Incorrect 1 ms 6492 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 54 ms 8796 KB Output is correct
5 Correct 56 ms 9048 KB Output is correct
6 Correct 98 ms 8816 KB Output is correct
7 Correct 47 ms 8796 KB Output is correct
8 Correct 38 ms 8792 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6744 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Incorrect 1 ms 6492 KB Output isn't correct
16 Halted 0 ms 0 KB -