Submission #724584

# Submission time Handle Problem Language Result Execution time Memory
724584 2023-04-15T15:13:45 Z TheSahib Osumnjičeni (COCI21_osumnjiceni) C++17
30 / 110
1000 ms 20928 KB
#include <bits/stdc++.h>
 
#pragma GCC optimize("O3")
 
#define ll long long
#define oo 1e9 + 9
#define pii pair<int, int>
 
using namespace std;

const int MAX = 2e5 + 5;

int n, q;
pii arr[MAX];

int st[20][MAX];

bool checkRange(pii a, pii b){
    return a.first <= b.second && a.second >= b.first;
}

void calcMaxR(){
    set<pii> s;
    int l = 0;
    for (int i = 0; i < n; i++)
    {
        while(!s.empty()){
            //auto itr = s.upper_bound({arr[i].first, 0});
            //auto itr2 = s.upper_bound({arr[i].second, 0});
            //if(itr != s.begin()) --itr;
            //if(itr2 != s.begin()) --itr2;
            bool b = false;
            for(auto& p:s){
                if(checkRange(p, arr[i])) b = true;
            }
            if(b){
                st[0][l] = i;
                s.erase(arr[l]);
                ++l;
            }
            else{
                break;
            }
        }
        s.insert(arr[i]);
    }
    
    for (int j = l; j <= n; j++)
    {
        st[0][j] = n;
    }
}


void build(){
    for (int j = 1; j < 20; j++)
    {
        for (int i = 0; i <= n; i++)
        {
            st[j][i] = st[j - 1][st[j - 1][i]];
        }
    }
}

int ask(int l, int r){
    int ans = 1;
    for(int j = 19; j >= 0; --j){
        if(st[j][l] <= r){
            l = st[j][l];
            ans += (1 << j);
        }
    }
    return ans;
}

int main(){
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i].first >> arr[i].second;
    }
    calcMaxR();
    build();

    cin >> q;
    while(q--){
        int l, r; cin >> l >> r;
        --l; --r;
        cout << ask(l, r) << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 158 ms 16716 KB Output is correct
2 Correct 163 ms 16504 KB Output is correct
3 Correct 160 ms 16624 KB Output is correct
4 Correct 162 ms 16752 KB Output is correct
5 Correct 161 ms 17484 KB Output is correct
6 Correct 152 ms 15952 KB Output is correct
7 Correct 156 ms 16180 KB Output is correct
8 Correct 167 ms 19864 KB Output is correct
9 Correct 170 ms 20340 KB Output is correct
10 Correct 167 ms 19616 KB Output is correct
11 Execution timed out 1083 ms 5672 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 852 KB Output is correct
2 Correct 13 ms 724 KB Output is correct
3 Correct 18 ms 732 KB Output is correct
4 Correct 18 ms 848 KB Output is correct
5 Correct 14 ms 820 KB Output is correct
6 Correct 15 ms 848 KB Output is correct
7 Correct 14 ms 828 KB Output is correct
8 Correct 14 ms 988 KB Output is correct
9 Correct 13 ms 980 KB Output is correct
10 Correct 13 ms 980 KB Output is correct
11 Correct 124 ms 1176 KB Output is correct
12 Correct 118 ms 1012 KB Output is correct
13 Correct 119 ms 1100 KB Output is correct
14 Correct 69 ms 1064 KB Output is correct
15 Correct 60 ms 972 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 19 ms 984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 852 KB Output is correct
2 Correct 13 ms 724 KB Output is correct
3 Correct 18 ms 732 KB Output is correct
4 Correct 18 ms 848 KB Output is correct
5 Correct 14 ms 820 KB Output is correct
6 Correct 15 ms 848 KB Output is correct
7 Correct 14 ms 828 KB Output is correct
8 Correct 14 ms 988 KB Output is correct
9 Correct 13 ms 980 KB Output is correct
10 Correct 13 ms 980 KB Output is correct
11 Correct 124 ms 1176 KB Output is correct
12 Correct 118 ms 1012 KB Output is correct
13 Correct 119 ms 1100 KB Output is correct
14 Correct 69 ms 1064 KB Output is correct
15 Correct 60 ms 972 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 19 ms 984 KB Output is correct
18 Correct 386 ms 3540 KB Output is correct
19 Correct 342 ms 3336 KB Output is correct
20 Correct 387 ms 3620 KB Output is correct
21 Correct 365 ms 3388 KB Output is correct
22 Correct 501 ms 3444 KB Output is correct
23 Correct 364 ms 3500 KB Output is correct
24 Correct 403 ms 3528 KB Output is correct
25 Correct 412 ms 3524 KB Output is correct
26 Correct 360 ms 3464 KB Output is correct
27 Correct 353 ms 3284 KB Output is correct
28 Correct 468 ms 3088 KB Output is correct
29 Correct 453 ms 3196 KB Output is correct
30 Correct 451 ms 3424 KB Output is correct
31 Correct 406 ms 3088 KB Output is correct
32 Correct 459 ms 3108 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 356 ms 3292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 17556 KB Output is correct
2 Correct 163 ms 17164 KB Output is correct
3 Correct 152 ms 16056 KB Output is correct
4 Correct 147 ms 15872 KB Output is correct
5 Correct 158 ms 16344 KB Output is correct
6 Correct 148 ms 16080 KB Output is correct
7 Correct 157 ms 15948 KB Output is correct
8 Correct 154 ms 19508 KB Output is correct
9 Correct 154 ms 19376 KB Output is correct
10 Correct 217 ms 20928 KB Output is correct
11 Execution timed out 1072 ms 5276 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 158 ms 16716 KB Output is correct
2 Correct 163 ms 16504 KB Output is correct
3 Correct 160 ms 16624 KB Output is correct
4 Correct 162 ms 16752 KB Output is correct
5 Correct 161 ms 17484 KB Output is correct
6 Correct 152 ms 15952 KB Output is correct
7 Correct 156 ms 16180 KB Output is correct
8 Correct 167 ms 19864 KB Output is correct
9 Correct 170 ms 20340 KB Output is correct
10 Correct 167 ms 19616 KB Output is correct
11 Execution timed out 1083 ms 5672 KB Time limit exceeded
12 Halted 0 ms 0 KB -