답안 #1104547

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

using namespace std;

#define ll long long

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

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 1 ms 6480 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 6652 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 1 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 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 6480 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 1 ms 6480 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 2 ms 6480 KB Output is correct
22 Correct 1 ms 6480 KB Output is correct
23 Correct 2 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 6652 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 1 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 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 6480 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 1 ms 6480 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 2 ms 6480 KB Output is correct
22 Correct 1 ms 6480 KB Output is correct
23 Correct 2 ms 6480 KB Output is correct
24 Correct 1 ms 6480 KB Output is correct
25 Correct 2 ms 6736 KB Output is correct
26 Correct 2 ms 6736 KB Output is correct
27 Correct 2 ms 6904 KB Output is correct
28 Correct 2 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 6736 KB Output is correct
33 Correct 2 ms 6736 KB Output is correct
34 Correct 2 ms 6736 KB Output is correct
35 Correct 2 ms 6908 KB Output is correct
36 Correct 3 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 1 ms 6480 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 6652 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 1 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 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 6480 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 1 ms 6480 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 2 ms 6480 KB Output is correct
22 Correct 1 ms 6480 KB Output is correct
23 Correct 2 ms 6480 KB Output is correct
24 Correct 1 ms 6480 KB Output is correct
25 Correct 2 ms 6736 KB Output is correct
26 Correct 2 ms 6736 KB Output is correct
27 Correct 2 ms 6904 KB Output is correct
28 Correct 2 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 6736 KB Output is correct
33 Correct 2 ms 6736 KB Output is correct
34 Correct 2 ms 6736 KB Output is correct
35 Correct 2 ms 6908 KB Output is correct
36 Correct 3 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 20 ms 10832 KB Output is correct
40 Correct 17 ms 10832 KB Output is correct
41 Correct 17 ms 10840 KB Output is correct
42 Correct 12 ms 9208 KB Output is correct
43 Correct 12 ms 8784 KB Output is correct
44 Correct 13 ms 8904 KB Output is correct
45 Correct 13 ms 8908 KB Output is correct
46 Correct 12 ms 9040 KB Output is correct
47 Correct 19 ms 10832 KB Output is correct
48 Correct 17 ms 10832 KB Output is correct
49 Correct 13 ms 10796 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 6480 KB Output is correct
6 Correct 1 ms 6660 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6480 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 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 17 ms 10744 KB Output is correct
16 Correct 13 ms 9020 KB Output is correct
17 Correct 12 ms 8952 KB Output is correct
18 Correct 12 ms 9040 KB Output is correct
19 Correct 17 ms 11000 KB Output is correct
20 Correct 108 ms 69896 KB Output is correct
21 Correct 1684 ms 196680 KB Output is correct
22 Correct 1909 ms 196748 KB Output is correct
23 Correct 1085 ms 132460 KB Output is correct
24 Correct 1511 ms 196680 KB Output is correct
25 Correct 930 ms 122640 KB Output is correct
26 Correct 1100 ms 134252 KB Output is correct
27 Correct 1107 ms 134288 KB Output is correct
28 Correct 1353 ms 193652 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 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 3 ms 6768 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 10756 KB Output is correct
13 Correct 13 ms 9040 KB Output is correct
14 Correct 13 ms 9040 KB Output is correct
15 Correct 117 ms 69896 KB Output is correct
16 Correct 1111 ms 132424 KB Output is correct
17 Correct 1849 ms 196676 KB Output is correct
18 Execution timed out 2069 ms 195908 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 2 ms 6652 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 1 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 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 6480 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 1 ms 6480 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 2 ms 6480 KB Output is correct
22 Correct 1 ms 6480 KB Output is correct
23 Correct 2 ms 6480 KB Output is correct
24 Correct 1 ms 6480 KB Output is correct
25 Correct 2 ms 6736 KB Output is correct
26 Correct 2 ms 6736 KB Output is correct
27 Correct 2 ms 6904 KB Output is correct
28 Correct 2 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 6736 KB Output is correct
33 Correct 2 ms 6736 KB Output is correct
34 Correct 2 ms 6736 KB Output is correct
35 Correct 2 ms 6908 KB Output is correct
36 Correct 3 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 20 ms 10832 KB Output is correct
40 Correct 17 ms 10832 KB Output is correct
41 Correct 17 ms 10840 KB Output is correct
42 Correct 12 ms 9208 KB Output is correct
43 Correct 12 ms 8784 KB Output is correct
44 Correct 13 ms 8904 KB Output is correct
45 Correct 13 ms 8908 KB Output is correct
46 Correct 12 ms 9040 KB Output is correct
47 Correct 19 ms 10832 KB Output is correct
48 Correct 17 ms 10832 KB Output is correct
49 Correct 13 ms 10796 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 6480 KB Output is correct
56 Correct 1 ms 6660 KB Output is correct
57 Correct 1 ms 6480 KB Output is correct
58 Correct 1 ms 6480 KB Output is correct
59 Correct 2 ms 6736 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 17 ms 10744 KB Output is correct
66 Correct 13 ms 9020 KB Output is correct
67 Correct 12 ms 8952 KB Output is correct
68 Correct 12 ms 9040 KB Output is correct
69 Correct 17 ms 11000 KB Output is correct
70 Correct 108 ms 69896 KB Output is correct
71 Correct 1684 ms 196680 KB Output is correct
72 Correct 1909 ms 196748 KB Output is correct
73 Correct 1085 ms 132460 KB Output is correct
74 Correct 1511 ms 196680 KB Output is correct
75 Correct 930 ms 122640 KB Output is correct
76 Correct 1100 ms 134252 KB Output is correct
77 Correct 1107 ms 134288 KB Output is correct
78 Correct 1353 ms 193652 KB Output is correct
79 Correct 1 ms 4432 KB Output is correct
80 Correct 1 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 3 ms 6768 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 10756 KB Output is correct
91 Correct 13 ms 9040 KB Output is correct
92 Correct 13 ms 9040 KB Output is correct
93 Correct 117 ms 69896 KB Output is correct
94 Correct 1111 ms 132424 KB Output is correct
95 Correct 1849 ms 196676 KB Output is correct
96 Execution timed out 2069 ms 195908 KB Time limit exceeded
97 Halted 0 ms 0 KB -