Submission #528422

# Submission time Handle Problem Language Result Execution time Memory
528422 2022-02-20T09:10:15 Z N1NT3NDO Osumnjičeni (COCI21_osumnjiceni) C++14
10 / 110
1000 ms 22280 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) (int)x.size()
#define fi first
#define sd second
#define all(x) x.begin(), x.end()
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = (int)2e5 + 5;
int n, l[N], r[N], q, nxt[N], mn[N][22], lg[N];
vector<int> vec;

bool intersect(const pair<int, int> a, const pair<int, int> b)
{
    int L = max(a.fi, b.fi);
    int R = min(a.sd, b.sd);
    return R >= L;
}

int get(int l, int r)
{
    int t = lg[r - l + 1];
    return min(mn[l][t], mn[r - (1 << t) + 1][t]);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    lg[1] = 0;
    for(int i = 2; i <= n; i++) lg[i] = lg[i / 2] + 1;
    for(int i = 1; i <= n; i++)
    {
        cin >> l[i] >> r[i];
        vec.pb(l[i]);
        vec.pb(r[i]);
    }

    sort(all(vec));
    vec.erase(unique(all(vec)), vec.end());
    for(int i = 1; i <= n; i++)
    {
        l[i] = lower_bound(all(vec), l[i]) - vec.begin(); l[i]++;
        r[i] = lower_bound(all(vec), r[i]) - vec.begin(); r[i]++;
    }

    for(int i = 1; i <= n; i++)
    {
        bool ok = 0;
        for(int j = i + 1; j <= n; j++)
          if (intersect({l[i], r[i]}, {l[j], r[j]}))
            {
                nxt[i] = j;
                ok = 1;
                break;
            }

        if (!ok) nxt[i] = n + 1;
        mn[i][0] = nxt[i];
    }

    for(int i = 1; (1 << i) <= n; i++)
    {
        for(int j = 1; j + (1 << i) - 1 <= n; j++)
          mn[j][i] = min(mn[j][i - 1], mn[j + (1 << (i - 1))][i - 1]);
    }

    for(int i = 1; i <= n; i++) nxt[i] = get(i, nxt[i] - 1);

    cin >> q;
    while(q--)
    {
        int le, ri;
        cin >> le >> ri;
        int i = le, ans = 0;
        while(i <= ri)
        {
            i = nxt[i];
            ans++;
        }

        cout << ans << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 145 ms 21344 KB Output is correct
2 Correct 146 ms 21040 KB Output is correct
3 Correct 143 ms 21172 KB Output is correct
4 Correct 149 ms 21264 KB Output is correct
5 Correct 152 ms 22188 KB Output is correct
6 Correct 71 ms 20256 KB Output is correct
7 Correct 79 ms 20664 KB Output is correct
8 Correct 77 ms 20776 KB Output is correct
9 Correct 82 ms 21240 KB Output is correct
10 Correct 81 ms 20644 KB Output is correct
11 Execution timed out 1092 ms 4652 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 960 KB Output is correct
2 Correct 17 ms 1044 KB Output is correct
3 Correct 17 ms 1048 KB Output is correct
4 Correct 15 ms 948 KB Output is correct
5 Correct 14 ms 928 KB Output is correct
6 Correct 19 ms 968 KB Output is correct
7 Correct 13 ms 940 KB Output is correct
8 Correct 11 ms 972 KB Output is correct
9 Correct 10 ms 928 KB Output is correct
10 Correct 8 ms 928 KB Output is correct
11 Correct 19 ms 888 KB Output is correct
12 Correct 14 ms 844 KB Output is correct
13 Correct 14 ms 844 KB Output is correct
14 Correct 16 ms 964 KB Output is correct
15 Correct 20 ms 844 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 50 ms 1060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 960 KB Output is correct
2 Correct 17 ms 1044 KB Output is correct
3 Correct 17 ms 1048 KB Output is correct
4 Correct 15 ms 948 KB Output is correct
5 Correct 14 ms 928 KB Output is correct
6 Correct 19 ms 968 KB Output is correct
7 Correct 13 ms 940 KB Output is correct
8 Correct 11 ms 972 KB Output is correct
9 Correct 10 ms 928 KB Output is correct
10 Correct 8 ms 928 KB Output is correct
11 Correct 19 ms 888 KB Output is correct
12 Correct 14 ms 844 KB Output is correct
13 Correct 14 ms 844 KB Output is correct
14 Correct 16 ms 964 KB Output is correct
15 Correct 20 ms 844 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 50 ms 1060 KB Output is correct
18 Correct 512 ms 2792 KB Output is correct
19 Correct 454 ms 3552 KB Output is correct
20 Correct 525 ms 3868 KB Output is correct
21 Correct 451 ms 3420 KB Output is correct
22 Correct 479 ms 3664 KB Output is correct
23 Correct 611 ms 3636 KB Output is correct
24 Correct 454 ms 3640 KB Output is correct
25 Correct 359 ms 3660 KB Output is correct
26 Correct 288 ms 3524 KB Output is correct
27 Correct 198 ms 3396 KB Output is correct
28 Correct 53 ms 3048 KB Output is correct
29 Correct 51 ms 3192 KB Output is correct
30 Correct 53 ms 3140 KB Output is correct
31 Correct 52 ms 3096 KB Output is correct
32 Correct 53 ms 3140 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Execution timed out 1093 ms 2676 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 182 ms 22280 KB Output is correct
2 Correct 163 ms 22048 KB Output is correct
3 Correct 168 ms 20404 KB Output is correct
4 Correct 147 ms 20120 KB Output is correct
5 Correct 154 ms 20736 KB Output is correct
6 Correct 83 ms 20504 KB Output is correct
7 Correct 79 ms 20184 KB Output is correct
8 Correct 82 ms 20472 KB Output is correct
9 Correct 79 ms 20140 KB Output is correct
10 Correct 88 ms 21816 KB Output is correct
11 Execution timed out 1092 ms 4540 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 145 ms 21344 KB Output is correct
2 Correct 146 ms 21040 KB Output is correct
3 Correct 143 ms 21172 KB Output is correct
4 Correct 149 ms 21264 KB Output is correct
5 Correct 152 ms 22188 KB Output is correct
6 Correct 71 ms 20256 KB Output is correct
7 Correct 79 ms 20664 KB Output is correct
8 Correct 77 ms 20776 KB Output is correct
9 Correct 82 ms 21240 KB Output is correct
10 Correct 81 ms 20644 KB Output is correct
11 Execution timed out 1092 ms 4652 KB Time limit exceeded
12 Halted 0 ms 0 KB -