답안 #842395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
842395 2023-09-02T19:52:37 Z serifefedartar Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
513 ms 55096 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 22
#define MAXN 400005
 
int sg[4*MAXN], lazy[4*MAXN];
int up[LOGN][MAXN];
vector<pair<int,int>> segments;
vector<int> cc;

void update(int k, int a, int b, int q_l, int q_r, int val) {
    if (lazy[k]) {
        sg[k] += lazy[k];
        if (a != b) {
            lazy[2*k] += lazy[k];
            lazy[2*k+1] += lazy[k];
        }
        lazy[k] = 0;
    }
 
    if (b < q_l || a > q_r)
        return ;
    if (q_l <= a && b <= q_r) {
        sg[k] += val;
        if (a != b) {
            lazy[2*k] += val;
            lazy[2*k+1] += val;
        }
        return ;
    }
    update(2*k, a, (a+b)/2, q_l, q_r, val);
    update(2*k+1, (a+b)/2+1, b, q_l, q_r, val);
    sg[k] = max(sg[2*k], sg[2*k+1]);
}
 
int index(int k) {
    return upper_bound(cc.begin(), cc.end(), k) - cc.begin();
}
 
int main() {
    fast
    int N;
    cin >> N;
    
    segments = vector<pair<int,int>>(N+1);
    for (int i = 1; i <= N; i++) {
        cin >> segments[i].f >> segments[i].s;
        cc.push_back(segments[i].f);
        cc.push_back(segments[i].s);
    }
    sort(cc.begin(), cc.end());
    cc.erase(unique(cc.begin(), cc.end()), cc.end());
    int n = cc.size();

    int L = 1;
    for (int R = 1; R <= N; R++) {
        update(1, 1, n, index(segments[R].f), index(segments[R].s), 1);
        while (sg[1] > 1) {
            up[0][L] = R;
            update(1, 1, n, index(segments[L].f), index(segments[L].s), -1);
            L++;
        }
    }
    for (int i = 1; i <= N; i++) {
        if (up[0][i] == 0)
            up[0][i] = N+1;
    }
 
    for (int i = 0; i < LOGN; i++)
        up[i][N+1] = N+1;
    for (int i = 1; i < LOGN; i++) {
        for (int j = 1; j <= N; j++)
            up[i][j] = up[i-1][up[i-1][j]];
    }

    int Q; 
    cin >> Q;
    while (Q--) {
        int a, b;
        cin >> a >> b;
        b++;
 
        int cnt = 0;
        int now = a;
        for (int i = LOGN-1; i >= 0; i--) {
            if (up[i][now] < b) {
                now = up[i][now];
                cnt += (1<<i);
            }
        }
        cout << cnt + 1 << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 48072 KB Output is correct
2 Correct 409 ms 47880 KB Output is correct
3 Correct 363 ms 47436 KB Output is correct
4 Correct 374 ms 48072 KB Output is correct
5 Correct 385 ms 47448 KB Output is correct
6 Correct 40 ms 38852 KB Output is correct
7 Correct 49 ms 39112 KB Output is correct
8 Correct 53 ms 39112 KB Output is correct
9 Correct 62 ms 39260 KB Output is correct
10 Correct 65 ms 39000 KB Output is correct
11 Correct 155 ms 46256 KB Output is correct
12 Correct 161 ms 45228 KB Output is correct
13 Correct 149 ms 45216 KB Output is correct
14 Correct 264 ms 46968 KB Output is correct
15 Correct 228 ms 46280 KB Output is correct
16 Correct 4 ms 35160 KB Output is correct
17 Correct 44 ms 39116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 35672 KB Output is correct
2 Correct 11 ms 35676 KB Output is correct
3 Correct 11 ms 35676 KB Output is correct
4 Correct 12 ms 35676 KB Output is correct
5 Correct 11 ms 35676 KB Output is correct
6 Correct 6 ms 35676 KB Output is correct
7 Correct 6 ms 35420 KB Output is correct
8 Correct 7 ms 35676 KB Output is correct
9 Correct 7 ms 35420 KB Output is correct
10 Correct 8 ms 35420 KB Output is correct
11 Correct 9 ms 35676 KB Output is correct
12 Correct 7 ms 35676 KB Output is correct
13 Correct 7 ms 35676 KB Output is correct
14 Correct 8 ms 35724 KB Output is correct
15 Correct 9 ms 35676 KB Output is correct
16 Correct 4 ms 35164 KB Output is correct
17 Correct 6 ms 35676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 35672 KB Output is correct
2 Correct 11 ms 35676 KB Output is correct
3 Correct 11 ms 35676 KB Output is correct
4 Correct 12 ms 35676 KB Output is correct
5 Correct 11 ms 35676 KB Output is correct
6 Correct 6 ms 35676 KB Output is correct
7 Correct 6 ms 35420 KB Output is correct
8 Correct 7 ms 35676 KB Output is correct
9 Correct 7 ms 35420 KB Output is correct
10 Correct 8 ms 35420 KB Output is correct
11 Correct 9 ms 35676 KB Output is correct
12 Correct 7 ms 35676 KB Output is correct
13 Correct 7 ms 35676 KB Output is correct
14 Correct 8 ms 35724 KB Output is correct
15 Correct 9 ms 35676 KB Output is correct
16 Correct 4 ms 35164 KB Output is correct
17 Correct 6 ms 35676 KB Output is correct
18 Correct 72 ms 38272 KB Output is correct
19 Correct 58 ms 37972 KB Output is correct
20 Correct 64 ms 38448 KB Output is correct
21 Correct 59 ms 38228 KB Output is correct
22 Correct 61 ms 38228 KB Output is correct
23 Correct 54 ms 37976 KB Output is correct
24 Correct 56 ms 38056 KB Output is correct
25 Correct 57 ms 38044 KB Output is correct
26 Correct 55 ms 38160 KB Output is correct
27 Correct 52 ms 37972 KB Output is correct
28 Correct 43 ms 37716 KB Output is correct
29 Correct 42 ms 37720 KB Output is correct
30 Correct 41 ms 37692 KB Output is correct
31 Correct 44 ms 37752 KB Output is correct
32 Correct 47 ms 37752 KB Output is correct
33 Correct 4 ms 35164 KB Output is correct
34 Correct 44 ms 37972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 384 ms 47452 KB Output is correct
2 Correct 376 ms 51796 KB Output is correct
3 Correct 345 ms 50828 KB Output is correct
4 Correct 356 ms 50696 KB Output is correct
5 Correct 364 ms 51412 KB Output is correct
6 Correct 44 ms 42612 KB Output is correct
7 Correct 50 ms 42700 KB Output is correct
8 Correct 56 ms 42372 KB Output is correct
9 Correct 58 ms 42444 KB Output is correct
10 Correct 70 ms 42956 KB Output is correct
11 Correct 146 ms 48948 KB Output is correct
12 Correct 171 ms 48016 KB Output is correct
13 Correct 147 ms 48188 KB Output is correct
14 Correct 249 ms 49492 KB Output is correct
15 Correct 236 ms 49356 KB Output is correct
16 Correct 4 ms 35164 KB Output is correct
17 Correct 52 ms 42700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 48072 KB Output is correct
2 Correct 409 ms 47880 KB Output is correct
3 Correct 363 ms 47436 KB Output is correct
4 Correct 374 ms 48072 KB Output is correct
5 Correct 385 ms 47448 KB Output is correct
6 Correct 40 ms 38852 KB Output is correct
7 Correct 49 ms 39112 KB Output is correct
8 Correct 53 ms 39112 KB Output is correct
9 Correct 62 ms 39260 KB Output is correct
10 Correct 65 ms 39000 KB Output is correct
11 Correct 155 ms 46256 KB Output is correct
12 Correct 161 ms 45228 KB Output is correct
13 Correct 149 ms 45216 KB Output is correct
14 Correct 264 ms 46968 KB Output is correct
15 Correct 228 ms 46280 KB Output is correct
16 Correct 4 ms 35160 KB Output is correct
17 Correct 44 ms 39116 KB Output is correct
18 Correct 12 ms 35672 KB Output is correct
19 Correct 11 ms 35676 KB Output is correct
20 Correct 11 ms 35676 KB Output is correct
21 Correct 12 ms 35676 KB Output is correct
22 Correct 11 ms 35676 KB Output is correct
23 Correct 6 ms 35676 KB Output is correct
24 Correct 6 ms 35420 KB Output is correct
25 Correct 7 ms 35676 KB Output is correct
26 Correct 7 ms 35420 KB Output is correct
27 Correct 8 ms 35420 KB Output is correct
28 Correct 9 ms 35676 KB Output is correct
29 Correct 7 ms 35676 KB Output is correct
30 Correct 7 ms 35676 KB Output is correct
31 Correct 8 ms 35724 KB Output is correct
32 Correct 9 ms 35676 KB Output is correct
33 Correct 4 ms 35164 KB Output is correct
34 Correct 6 ms 35676 KB Output is correct
35 Correct 72 ms 38272 KB Output is correct
36 Correct 58 ms 37972 KB Output is correct
37 Correct 64 ms 38448 KB Output is correct
38 Correct 59 ms 38228 KB Output is correct
39 Correct 61 ms 38228 KB Output is correct
40 Correct 54 ms 37976 KB Output is correct
41 Correct 56 ms 38056 KB Output is correct
42 Correct 57 ms 38044 KB Output is correct
43 Correct 55 ms 38160 KB Output is correct
44 Correct 52 ms 37972 KB Output is correct
45 Correct 43 ms 37716 KB Output is correct
46 Correct 42 ms 37720 KB Output is correct
47 Correct 41 ms 37692 KB Output is correct
48 Correct 44 ms 37752 KB Output is correct
49 Correct 47 ms 37752 KB Output is correct
50 Correct 4 ms 35164 KB Output is correct
51 Correct 44 ms 37972 KB Output is correct
52 Correct 384 ms 47452 KB Output is correct
53 Correct 376 ms 51796 KB Output is correct
54 Correct 345 ms 50828 KB Output is correct
55 Correct 356 ms 50696 KB Output is correct
56 Correct 364 ms 51412 KB Output is correct
57 Correct 44 ms 42612 KB Output is correct
58 Correct 50 ms 42700 KB Output is correct
59 Correct 56 ms 42372 KB Output is correct
60 Correct 58 ms 42444 KB Output is correct
61 Correct 70 ms 42956 KB Output is correct
62 Correct 146 ms 48948 KB Output is correct
63 Correct 171 ms 48016 KB Output is correct
64 Correct 147 ms 48188 KB Output is correct
65 Correct 249 ms 49492 KB Output is correct
66 Correct 236 ms 49356 KB Output is correct
67 Correct 4 ms 35164 KB Output is correct
68 Correct 52 ms 42700 KB Output is correct
69 Correct 479 ms 54468 KB Output is correct
70 Correct 513 ms 54732 KB Output is correct
71 Correct 446 ms 53964 KB Output is correct
72 Correct 460 ms 55096 KB Output is correct
73 Correct 460 ms 54308 KB Output is correct
74 Correct 165 ms 46980 KB Output is correct
75 Correct 163 ms 46132 KB Output is correct
76 Correct 205 ms 46768 KB Output is correct
77 Correct 160 ms 46020 KB Output is correct
78 Correct 183 ms 46276 KB Output is correct
79 Correct 218 ms 50952 KB Output is correct
80 Correct 202 ms 51660 KB Output is correct
81 Correct 214 ms 51660 KB Output is correct
82 Correct 312 ms 52564 KB Output is correct
83 Correct 292 ms 52912 KB Output is correct
84 Correct 4 ms 35164 KB Output is correct
85 Correct 94 ms 46068 KB Output is correct