답안 #863039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863039 2023-10-19T13:45:25 Z 3omar_ahmed Osumnjičeni (COCI21_osumnjiceni) C++17
0 / 110
1000 ms 38644 KB
#include <bits/stdc++.h>
using namespace std ;
#define int long long
#define endl '\n'
#define all(a) a.begin() , a.end()
#define alr(a) a.rbegin() , a.rend()

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);

    int n;
    cin >> n;
    n += 1;
    vector < pair < int , int >> a(n);
    for(int i = 0 ; i + 1 < n ; i++) {
        cin >> a[i].first >> a[i].second;
    }    
    a[n - 1] = {1, n};
    vector < vector < int >> nxt(20, vector < int > (n + 1, -1));
    
    for(int i = 0 ; i < n ; i++) {
        int found = -1;
        for(int j = i + 1 ; j < n ; j++) {
            for(int k = i ; k < j ; k++) {
                int l = max(a[j].first, a[k].first);
                int r = min(a[j].second, a[k].second);
                if(l <= r) {
                    found = j - 1;
                    break;
                }
            }
            if(found != -1) {
                break;
            }
        }
        nxt[0][i] = found;
    }

    for(int i = 1 ; i < 20 ; i++) {
        for(int j = 0 ; j < n ; j++) {
            if(nxt[i - 1][j] != -1)
                nxt[i][j] = nxt[i - 1][nxt[i - 1][j] + 1];
        }
    }

    int q;
    cin >> q;
    while(q--) {
        int l, r;
        cin >> l >> r;
        l -= 1, r -= 1;
        int ans = 0;
        for(int i = 19 ; i >= 0 ; i--) {
            if(nxt[i][l] <= r && nxt[i][l] != -1) {
                ans += (1ll << i);
                l = nxt[i][l] + 1;
            }
        }
        ans += (l <= r);
        cout << ans << endl;
    }
    return 0 ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 37204 KB Output is correct
2 Correct 44 ms 36180 KB Output is correct
3 Correct 44 ms 36432 KB Output is correct
4 Correct 44 ms 36728 KB Output is correct
5 Correct 47 ms 38480 KB Output is correct
6 Correct 41 ms 34896 KB Output is correct
7 Correct 43 ms 35448 KB Output is correct
8 Correct 43 ms 35920 KB Output is correct
9 Correct 49 ms 36692 KB Output is correct
10 Correct 46 ms 35668 KB Output is correct
11 Execution timed out 1044 ms 37200 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1412 KB Output is correct
2 Correct 3 ms 1408 KB Output is correct
3 Correct 3 ms 1420 KB Output is correct
4 Correct 3 ms 1372 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 3 ms 1496 KB Output is correct
7 Correct 3 ms 1672 KB Output is correct
8 Correct 3 ms 1372 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Execution timed out 1069 ms 1492 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1412 KB Output is correct
2 Correct 3 ms 1408 KB Output is correct
3 Correct 3 ms 1420 KB Output is correct
4 Correct 3 ms 1372 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 3 ms 1496 KB Output is correct
7 Correct 3 ms 1672 KB Output is correct
8 Correct 3 ms 1372 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Execution timed out 1069 ms 1492 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 38644 KB Output is correct
2 Correct 48 ms 37712 KB Output is correct
3 Correct 45 ms 35160 KB Output is correct
4 Correct 46 ms 34896 KB Output is correct
5 Correct 45 ms 35920 KB Output is correct
6 Correct 42 ms 35156 KB Output is correct
7 Correct 42 ms 34896 KB Output is correct
8 Correct 43 ms 35412 KB Output is correct
9 Correct 43 ms 34852 KB Output is correct
10 Correct 46 ms 37560 KB Output is correct
11 Execution timed out 1032 ms 34896 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 37204 KB Output is correct
2 Correct 44 ms 36180 KB Output is correct
3 Correct 44 ms 36432 KB Output is correct
4 Correct 44 ms 36728 KB Output is correct
5 Correct 47 ms 38480 KB Output is correct
6 Correct 41 ms 34896 KB Output is correct
7 Correct 43 ms 35448 KB Output is correct
8 Correct 43 ms 35920 KB Output is correct
9 Correct 49 ms 36692 KB Output is correct
10 Correct 46 ms 35668 KB Output is correct
11 Execution timed out 1044 ms 37200 KB Time limit exceeded
12 Halted 0 ms 0 KB -