답안 #1104546

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104546 2024-10-24T03:02:30 Z 12345678 Fire (BOI24_fire) C++17
53 / 100
2000 ms 200612 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int nx=2e5+5, kx=18;

ll n, m, pa[nx][kx], sm[nx][kx], t, vl[nx][2], sh[nx][2], ans=1e9;
map<ll, ll> mp, rvmp;

struct segtree
{
    pair<ll, ll> d[16*nx];
    void update(int l, int r, int i, int idx, pair<ll, ll> vl)
    {
        if (idx<l||r<idx) return;
        if (l==r) return d[i]=max(d[i], vl), void();
        int md=(l+r)/2;
        update(l, md, 2*i, idx, vl);
        update(md+1, r, 2*i+1, idx, vl);
        d[i]=max(d[2*i], d[2*i+1]);
    }  
    pair<ll, ll> query(int l, int r, int i, int ql, int qr)
    {
        if (qr<l||r<ql) return {0, 0};
        if (ql<=l&&r<=qr) return d[i];
        int md=(l+r)/2;
        return max(query(l, md, 2*i, ql, qr), query(md+1, r, 2*i+1, ql, qr));
    }
} s;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m;
    for (int i=1; i<=n; i++)
    {
        cin>>vl[i][0]>>vl[i][1];
        if (vl[i][1]<vl[i][0]) vl[i][1]+=m;
        sh[i][0]=vl[i][0]+m;
        sh[i][1]=vl[i][1]+m;
        mp[vl[i][0]]=mp[vl[i][1]]=mp[sh[i][0]]=mp[sh[i][1]]=0;
    }
    for (auto &[x, y]:mp) y=++t;
    for (auto [x, y]:mp) rvmp[y]=x;
    for (int i=1; i<=n ;i++) vl[i][0]=mp[vl[i][0]], vl[i][1]=mp[vl[i][1]], sh[i][0]=mp[sh[i][0]], sh[i][1]=mp[sh[i][1]];
    for (int i=1; i<=n; i++) s.update(1, 4*n, 1, vl[i][0], {vl[i][1], i}), s.update(1, 4*n, 1, sh[i][0], {sh[i][1], i});
    for (int i=1; i<=n; i++)
    {
        auto mx=s.query(1, 4*n, 1, vl[i][0], vl[i][1]);
        mx.first=rvmp[mx.first];
        auto tmp=rvmp[vl[i][1]];
        if (mx.first<=tmp) continue;
        pa[i][0]=mx.second;
        sm[i][0]=mx.first-tmp;
        //cout<<"pa "<<i<<' '<<pa[i][0]<<' '<<sm[i][0]<<'\n';
    }
    for (int j=1; j<kx; j++) for (int i=1; i<=n; i++) pa[i][j]=pa[pa[i][j-1]][j-1], sm[i][j]=sm[i][j-1]+sm[pa[i][j-1]][j-1];
    for (int i=1; i<=n; i++)
    {
        ll cur=rvmp[vl[i][1]]-rvmp[vl[i][0]], u=i, cnt=1;
        for (int j=kx-1; j>=0; j--) if (cur+sm[u][j]<m) cnt+=1<<j, cur+=sm[u][j], u=pa[u][j];
        //cout<<"cur "<<cur<<' '<<cnt<<' '<<u<<' '<<cur+sm[u][0]<<'\n';
        if (cur+sm[u][0]<m||u==0) continue;
        ans=min(ans, cnt+1);
    }
    if (ans==1e9) cout<<-1;
    else cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 6648 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 2 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6652 KB Output is correct
18 Correct 2 ms 6644 KB Output is correct
19 Correct 1 ms 6616 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 2 ms 6480 KB Output is correct
22 Correct 2 ms 6480 KB Output is correct
23 Correct 1 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 6648 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 2 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6652 KB Output is correct
18 Correct 2 ms 6644 KB Output is correct
19 Correct 1 ms 6616 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 2 ms 6480 KB Output is correct
22 Correct 2 ms 6480 KB Output is correct
23 Correct 1 ms 6480 KB Output is correct
24 Correct 2 ms 6480 KB Output is correct
25 Correct 3 ms 6736 KB Output is correct
26 Correct 2 ms 6736 KB Output is correct
27 Correct 2 ms 6736 KB Output is correct
28 Correct 3 ms 6736 KB Output is correct
29 Correct 2 ms 6736 KB Output is correct
30 Correct 2 ms 6736 KB Output is correct
31 Correct 2 ms 6736 KB Output is correct
32 Correct 2 ms 6756 KB Output is correct
33 Correct 2 ms 6904 KB Output is correct
34 Correct 2 ms 6736 KB Output is correct
35 Correct 2 ms 6736 KB Output is correct
36 Correct 2 ms 6736 KB Output is correct
37 Correct 2 ms 6736 KB Output is correct
38 Correct 2 ms 6736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 6648 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 2 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6652 KB Output is correct
18 Correct 2 ms 6644 KB Output is correct
19 Correct 1 ms 6616 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 2 ms 6480 KB Output is correct
22 Correct 2 ms 6480 KB Output is correct
23 Correct 1 ms 6480 KB Output is correct
24 Correct 2 ms 6480 KB Output is correct
25 Correct 3 ms 6736 KB Output is correct
26 Correct 2 ms 6736 KB Output is correct
27 Correct 2 ms 6736 KB Output is correct
28 Correct 3 ms 6736 KB Output is correct
29 Correct 2 ms 6736 KB Output is correct
30 Correct 2 ms 6736 KB Output is correct
31 Correct 2 ms 6736 KB Output is correct
32 Correct 2 ms 6756 KB Output is correct
33 Correct 2 ms 6904 KB Output is correct
34 Correct 2 ms 6736 KB Output is correct
35 Correct 2 ms 6736 KB Output is correct
36 Correct 2 ms 6736 KB Output is correct
37 Correct 2 ms 6736 KB Output is correct
38 Correct 2 ms 6736 KB Output is correct
39 Correct 18 ms 10832 KB Output is correct
40 Correct 17 ms 10732 KB Output is correct
41 Correct 18 ms 10776 KB Output is correct
42 Correct 13 ms 8992 KB Output is correct
43 Correct 13 ms 8784 KB Output is correct
44 Correct 12 ms 9040 KB Output is correct
45 Correct 13 ms 9040 KB Output is correct
46 Correct 13 ms 9212 KB Output is correct
47 Correct 17 ms 10728 KB Output is correct
48 Correct 17 ms 10832 KB Output is correct
49 Correct 15 ms 10832 KB Output is correct
50 Correct 13 ms 9040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6648 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6620 KB Output is correct
10 Correct 2 ms 6736 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 2 ms 6736 KB Output is correct
14 Correct 2 ms 6736 KB Output is correct
15 Correct 18 ms 10784 KB Output is correct
16 Correct 12 ms 9040 KB Output is correct
17 Correct 12 ms 8784 KB Output is correct
18 Correct 13 ms 9040 KB Output is correct
19 Correct 17 ms 10832 KB Output is correct
20 Correct 110 ms 70672 KB Output is correct
21 Correct 1865 ms 200608 KB Output is correct
22 Correct 1872 ms 200612 KB Output is correct
23 Correct 1232 ms 135376 KB Output is correct
24 Correct 1677 ms 200560 KB Output is correct
25 Correct 1068 ms 126024 KB Output is correct
26 Correct 1180 ms 138232 KB Output is correct
27 Correct 1132 ms 138212 KB Output is correct
28 Correct 1406 ms 197508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 2 ms 6736 KB Output is correct
9 Correct 2 ms 6736 KB Output is correct
10 Correct 2 ms 6736 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 18 ms 10832 KB Output is correct
13 Correct 12 ms 9040 KB Output is correct
14 Correct 13 ms 9040 KB Output is correct
15 Correct 151 ms 70728 KB Output is correct
16 Correct 1231 ms 135368 KB Output is correct
17 Correct 1933 ms 200388 KB Output is correct
18 Execution timed out 2068 ms 200008 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 6648 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 2 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 2 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6652 KB Output is correct
18 Correct 2 ms 6644 KB Output is correct
19 Correct 1 ms 6616 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 2 ms 6480 KB Output is correct
22 Correct 2 ms 6480 KB Output is correct
23 Correct 1 ms 6480 KB Output is correct
24 Correct 2 ms 6480 KB Output is correct
25 Correct 3 ms 6736 KB Output is correct
26 Correct 2 ms 6736 KB Output is correct
27 Correct 2 ms 6736 KB Output is correct
28 Correct 3 ms 6736 KB Output is correct
29 Correct 2 ms 6736 KB Output is correct
30 Correct 2 ms 6736 KB Output is correct
31 Correct 2 ms 6736 KB Output is correct
32 Correct 2 ms 6756 KB Output is correct
33 Correct 2 ms 6904 KB Output is correct
34 Correct 2 ms 6736 KB Output is correct
35 Correct 2 ms 6736 KB Output is correct
36 Correct 2 ms 6736 KB Output is correct
37 Correct 2 ms 6736 KB Output is correct
38 Correct 2 ms 6736 KB Output is correct
39 Correct 18 ms 10832 KB Output is correct
40 Correct 17 ms 10732 KB Output is correct
41 Correct 18 ms 10776 KB Output is correct
42 Correct 13 ms 8992 KB Output is correct
43 Correct 13 ms 8784 KB Output is correct
44 Correct 12 ms 9040 KB Output is correct
45 Correct 13 ms 9040 KB Output is correct
46 Correct 13 ms 9212 KB Output is correct
47 Correct 17 ms 10728 KB Output is correct
48 Correct 17 ms 10832 KB Output is correct
49 Correct 15 ms 10832 KB Output is correct
50 Correct 13 ms 9040 KB Output is correct
51 Correct 1 ms 4432 KB Output is correct
52 Correct 1 ms 6480 KB Output is correct
53 Correct 1 ms 6480 KB Output is correct
54 Correct 1 ms 6480 KB Output is correct
55 Correct 1 ms 6648 KB Output is correct
56 Correct 1 ms 6480 KB Output is correct
57 Correct 1 ms 6480 KB Output is correct
58 Correct 2 ms 6480 KB Output is correct
59 Correct 2 ms 6620 KB Output is correct
60 Correct 2 ms 6736 KB Output is correct
61 Correct 2 ms 6736 KB Output is correct
62 Correct 2 ms 6736 KB Output is correct
63 Correct 2 ms 6736 KB Output is correct
64 Correct 2 ms 6736 KB Output is correct
65 Correct 18 ms 10784 KB Output is correct
66 Correct 12 ms 9040 KB Output is correct
67 Correct 12 ms 8784 KB Output is correct
68 Correct 13 ms 9040 KB Output is correct
69 Correct 17 ms 10832 KB Output is correct
70 Correct 110 ms 70672 KB Output is correct
71 Correct 1865 ms 200608 KB Output is correct
72 Correct 1872 ms 200612 KB Output is correct
73 Correct 1232 ms 135376 KB Output is correct
74 Correct 1677 ms 200560 KB Output is correct
75 Correct 1068 ms 126024 KB Output is correct
76 Correct 1180 ms 138232 KB Output is correct
77 Correct 1132 ms 138212 KB Output is correct
78 Correct 1406 ms 197508 KB Output is correct
79 Correct 1 ms 4432 KB Output is correct
80 Correct 2 ms 6480 KB Output is correct
81 Correct 1 ms 6480 KB Output is correct
82 Correct 1 ms 6480 KB Output is correct
83 Correct 1 ms 6480 KB Output is correct
84 Correct 1 ms 6480 KB Output is correct
85 Correct 1 ms 6480 KB Output is correct
86 Correct 2 ms 6736 KB Output is correct
87 Correct 2 ms 6736 KB Output is correct
88 Correct 2 ms 6736 KB Output is correct
89 Correct 2 ms 6736 KB Output is correct
90 Correct 18 ms 10832 KB Output is correct
91 Correct 12 ms 9040 KB Output is correct
92 Correct 13 ms 9040 KB Output is correct
93 Correct 151 ms 70728 KB Output is correct
94 Correct 1231 ms 135368 KB Output is correct
95 Correct 1933 ms 200388 KB Output is correct
96 Execution timed out 2068 ms 200008 KB Time limit exceeded
97 Halted 0 ms 0 KB -