Submission #756784

# Submission time Handle Problem Language Result Execution time Memory
756784 2023-06-12T07:47:48 Z Dan4Life Event Hopping 2 (JOI21_event2) C++17
100 / 100
272 ms 22592 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(a) begin(a),end(a)
const int N = (int)2e5+10, Lg = 20;
int n, k;
vector<int> v;
set<pair<int,int>> S;
int L[N], R[N], J[Lg][N*2];

int get(int l, int r){
    int T = 0;
    for(int i = Lg-1; i>=0; i--)
        if(J[i][l]<=r) l=J[i][l], T+=(1<<i);
    return T;
}

int main(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> L[i] >> R[i], v.pb(L[i]), v.pb(R[i]);
    sort(all(v)); v.erase(unique(all(v)),end(v));
    int m = v.size();
    for(int i = 0; i <= m; i++) J[0][i]=m;
    for(int i = 1; i <= n; i++){
        L[i] = lower_bound(all(v),L[i])-begin(v);
        R[i] = lower_bound(all(v),R[i])-begin(v);
        J[0][L[i]] = min(J[0][L[i]],R[i]);
    }
    for(int i = m-1; i>=0; i--)
        J[0][i]=min(J[0][i],J[0][i+1]);
    for(int i = 1; i < Lg; i++)
        for(int j = 0; j <= m; j++)
            J[i][j] = J[i-1][J[i-1][j]];
    int T = get(0,m-1); if(T<k){cout<<-1;return 0;}
    S.insert({0,0}), S.insert({m-1,m-1});
    for(int i = 1; i <= n; i++){
        auto it = S.lower_bound({R[i],0});
        int r = it->first, l = (--it)->second;
        int num = T-get(l,r)+get(l,L[i])+get(R[i],r)+1;
        if(L[i]>=l and num>=k){
            cout << i << "\n"; T=num;
            S.insert({L[i],R[i]});
            if(S.size()==k+2) break;
        }
    }
}

Compilation message

event2.cpp: In function 'int main()':
event2.cpp:44:24: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |             if(S.size()==k+2) break;
      |                ~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 168 ms 22592 KB Output is correct
5 Correct 147 ms 22312 KB Output is correct
6 Correct 144 ms 21984 KB Output is correct
7 Correct 144 ms 21468 KB Output is correct
8 Correct 152 ms 22428 KB Output is correct
9 Correct 149 ms 22204 KB Output is correct
10 Correct 155 ms 22012 KB Output is correct
11 Correct 142 ms 21536 KB Output is correct
12 Correct 139 ms 20688 KB Output is correct
13 Correct 143 ms 20396 KB Output is correct
14 Correct 131 ms 20336 KB Output is correct
15 Correct 130 ms 20000 KB Output is correct
16 Correct 135 ms 18216 KB Output is correct
17 Correct 120 ms 18240 KB Output is correct
18 Correct 115 ms 18124 KB Output is correct
19 Correct 112 ms 17828 KB Output is correct
20 Correct 126 ms 17872 KB Output is correct
21 Correct 117 ms 17788 KB Output is correct
22 Correct 114 ms 17628 KB Output is correct
23 Correct 115 ms 17764 KB Output is correct
24 Correct 115 ms 17728 KB Output is correct
25 Correct 117 ms 17728 KB Output is correct
26 Correct 116 ms 17660 KB Output is correct
27 Correct 116 ms 17732 KB Output is correct
28 Correct 97 ms 17656 KB Output is correct
29 Correct 96 ms 17692 KB Output is correct
30 Correct 97 ms 17716 KB Output is correct
31 Correct 100 ms 17788 KB Output is correct
32 Correct 102 ms 17636 KB Output is correct
33 Correct 119 ms 17692 KB Output is correct
34 Correct 134 ms 19328 KB Output is correct
35 Correct 124 ms 18800 KB Output is correct
36 Correct 104 ms 18236 KB Output is correct
37 Correct 135 ms 20228 KB Output is correct
38 Correct 130 ms 20128 KB Output is correct
39 Correct 131 ms 20012 KB Output is correct
40 Correct 128 ms 19868 KB Output is correct
41 Correct 130 ms 19832 KB Output is correct
42 Correct 106 ms 17684 KB Output is correct
43 Correct 144 ms 20116 KB Output is correct
44 Correct 141 ms 20064 KB Output is correct
45 Correct 141 ms 19848 KB Output is correct
46 Correct 144 ms 19816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 388 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 388 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 4 ms 980 KB Output is correct
29 Correct 4 ms 980 KB Output is correct
30 Correct 4 ms 980 KB Output is correct
31 Correct 4 ms 980 KB Output is correct
32 Correct 4 ms 980 KB Output is correct
33 Correct 4 ms 980 KB Output is correct
34 Correct 5 ms 980 KB Output is correct
35 Correct 8 ms 1108 KB Output is correct
36 Correct 5 ms 1108 KB Output is correct
37 Correct 6 ms 980 KB Output is correct
38 Correct 4 ms 1004 KB Output is correct
39 Correct 5 ms 980 KB Output is correct
40 Correct 5 ms 980 KB Output is correct
41 Correct 5 ms 980 KB Output is correct
42 Correct 4 ms 980 KB Output is correct
43 Correct 6 ms 980 KB Output is correct
44 Correct 4 ms 980 KB Output is correct
45 Correct 4 ms 980 KB Output is correct
46 Correct 5 ms 948 KB Output is correct
47 Correct 6 ms 980 KB Output is correct
48 Correct 4 ms 1004 KB Output is correct
49 Correct 4 ms 904 KB Output is correct
50 Correct 4 ms 980 KB Output is correct
51 Correct 5 ms 980 KB Output is correct
52 Correct 4 ms 980 KB Output is correct
53 Correct 4 ms 980 KB Output is correct
54 Correct 4 ms 980 KB Output is correct
55 Correct 4 ms 852 KB Output is correct
56 Correct 4 ms 852 KB Output is correct
57 Correct 5 ms 844 KB Output is correct
58 Correct 5 ms 852 KB Output is correct
59 Correct 5 ms 852 KB Output is correct
60 Correct 4 ms 852 KB Output is correct
61 Correct 4 ms 852 KB Output is correct
62 Correct 4 ms 852 KB Output is correct
63 Correct 4 ms 852 KB Output is correct
64 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 168 ms 22592 KB Output is correct
5 Correct 147 ms 22312 KB Output is correct
6 Correct 144 ms 21984 KB Output is correct
7 Correct 144 ms 21468 KB Output is correct
8 Correct 152 ms 22428 KB Output is correct
9 Correct 149 ms 22204 KB Output is correct
10 Correct 155 ms 22012 KB Output is correct
11 Correct 142 ms 21536 KB Output is correct
12 Correct 139 ms 20688 KB Output is correct
13 Correct 143 ms 20396 KB Output is correct
14 Correct 131 ms 20336 KB Output is correct
15 Correct 130 ms 20000 KB Output is correct
16 Correct 135 ms 18216 KB Output is correct
17 Correct 120 ms 18240 KB Output is correct
18 Correct 115 ms 18124 KB Output is correct
19 Correct 112 ms 17828 KB Output is correct
20 Correct 126 ms 17872 KB Output is correct
21 Correct 117 ms 17788 KB Output is correct
22 Correct 114 ms 17628 KB Output is correct
23 Correct 115 ms 17764 KB Output is correct
24 Correct 115 ms 17728 KB Output is correct
25 Correct 117 ms 17728 KB Output is correct
26 Correct 116 ms 17660 KB Output is correct
27 Correct 116 ms 17732 KB Output is correct
28 Correct 97 ms 17656 KB Output is correct
29 Correct 96 ms 17692 KB Output is correct
30 Correct 97 ms 17716 KB Output is correct
31 Correct 100 ms 17788 KB Output is correct
32 Correct 102 ms 17636 KB Output is correct
33 Correct 119 ms 17692 KB Output is correct
34 Correct 134 ms 19328 KB Output is correct
35 Correct 124 ms 18800 KB Output is correct
36 Correct 104 ms 18236 KB Output is correct
37 Correct 135 ms 20228 KB Output is correct
38 Correct 130 ms 20128 KB Output is correct
39 Correct 131 ms 20012 KB Output is correct
40 Correct 128 ms 19868 KB Output is correct
41 Correct 130 ms 19832 KB Output is correct
42 Correct 106 ms 17684 KB Output is correct
43 Correct 144 ms 20116 KB Output is correct
44 Correct 141 ms 20064 KB Output is correct
45 Correct 141 ms 19848 KB Output is correct
46 Correct 144 ms 19816 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 388 KB Output is correct
56 Correct 1 ms 388 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 0 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 0 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 4 ms 980 KB Output is correct
75 Correct 4 ms 980 KB Output is correct
76 Correct 4 ms 980 KB Output is correct
77 Correct 4 ms 980 KB Output is correct
78 Correct 4 ms 980 KB Output is correct
79 Correct 4 ms 980 KB Output is correct
80 Correct 5 ms 980 KB Output is correct
81 Correct 8 ms 1108 KB Output is correct
82 Correct 5 ms 1108 KB Output is correct
83 Correct 6 ms 980 KB Output is correct
84 Correct 4 ms 1004 KB Output is correct
85 Correct 5 ms 980 KB Output is correct
86 Correct 5 ms 980 KB Output is correct
87 Correct 5 ms 980 KB Output is correct
88 Correct 4 ms 980 KB Output is correct
89 Correct 6 ms 980 KB Output is correct
90 Correct 4 ms 980 KB Output is correct
91 Correct 4 ms 980 KB Output is correct
92 Correct 5 ms 948 KB Output is correct
93 Correct 6 ms 980 KB Output is correct
94 Correct 4 ms 1004 KB Output is correct
95 Correct 4 ms 904 KB Output is correct
96 Correct 4 ms 980 KB Output is correct
97 Correct 5 ms 980 KB Output is correct
98 Correct 4 ms 980 KB Output is correct
99 Correct 4 ms 980 KB Output is correct
100 Correct 4 ms 980 KB Output is correct
101 Correct 4 ms 852 KB Output is correct
102 Correct 4 ms 852 KB Output is correct
103 Correct 5 ms 844 KB Output is correct
104 Correct 5 ms 852 KB Output is correct
105 Correct 5 ms 852 KB Output is correct
106 Correct 4 ms 852 KB Output is correct
107 Correct 4 ms 852 KB Output is correct
108 Correct 4 ms 852 KB Output is correct
109 Correct 4 ms 852 KB Output is correct
110 Correct 3 ms 724 KB Output is correct
111 Correct 158 ms 17688 KB Output is correct
112 Correct 204 ms 17652 KB Output is correct
113 Correct 156 ms 17748 KB Output is correct
114 Correct 153 ms 17672 KB Output is correct
115 Correct 156 ms 17740 KB Output is correct
116 Correct 120 ms 17716 KB Output is correct
117 Correct 122 ms 17688 KB Output is correct
118 Correct 220 ms 22428 KB Output is correct
119 Correct 220 ms 22016 KB Output is correct
120 Correct 186 ms 20052 KB Output is correct
121 Correct 120 ms 17712 KB Output is correct
122 Correct 272 ms 20576 KB Output is correct
123 Correct 197 ms 20260 KB Output is correct
124 Correct 180 ms 20052 KB Output is correct
125 Correct 120 ms 17732 KB Output is correct
126 Correct 179 ms 18208 KB Output is correct
127 Correct 174 ms 18216 KB Output is correct
128 Correct 181 ms 18144 KB Output is correct
129 Correct 119 ms 17632 KB Output is correct
130 Correct 167 ms 17700 KB Output is correct
131 Correct 171 ms 17684 KB Output is correct
132 Correct 187 ms 17712 KB Output is correct
133 Correct 142 ms 17680 KB Output is correct
134 Correct 159 ms 17744 KB Output is correct
135 Correct 157 ms 17652 KB Output is correct
136 Correct 154 ms 17880 KB Output is correct
137 Correct 119 ms 17724 KB Output is correct
138 Correct 151 ms 17704 KB Output is correct
139 Correct 157 ms 17728 KB Output is correct
140 Correct 127 ms 17780 KB Output is correct
141 Correct 131 ms 17864 KB Output is correct
142 Correct 152 ms 15024 KB Output is correct
143 Correct 155 ms 15100 KB Output is correct
144 Correct 157 ms 15036 KB Output is correct
145 Correct 132 ms 15040 KB Output is correct
146 Correct 132 ms 15024 KB Output is correct
147 Correct 135 ms 15008 KB Output is correct
148 Correct 130 ms 14724 KB Output is correct
149 Correct 127 ms 14712 KB Output is correct
150 Correct 126 ms 14632 KB Output is correct
151 Correct 122 ms 14012 KB Output is correct
152 Correct 86 ms 9920 KB Output is correct
153 Correct 130 ms 15112 KB Output is correct
154 Correct 131 ms 14940 KB Output is correct
155 Correct 128 ms 14880 KB Output is correct
156 Correct 141 ms 14804 KB Output is correct
157 Correct 136 ms 14608 KB Output is correct
158 Correct 133 ms 14572 KB Output is correct
159 Correct 124 ms 14012 KB Output is correct
160 Correct 90 ms 9900 KB Output is correct
161 Correct 188 ms 16288 KB Output is correct
162 Correct 187 ms 16216 KB Output is correct
163 Correct 179 ms 16172 KB Output is correct
164 Correct 172 ms 16008 KB Output is correct
165 Correct 171 ms 15824 KB Output is correct
166 Correct 101 ms 17824 KB Output is correct
167 Correct 143 ms 20160 KB Output is correct
168 Correct 135 ms 19980 KB Output is correct
169 Correct 145 ms 19900 KB Output is correct
170 Correct 137 ms 19792 KB Output is correct
171 Correct 115 ms 20260 KB Output is correct
172 Correct 132 ms 20160 KB Output is correct
173 Correct 197 ms 12440 KB Output is correct
174 Correct 201 ms 12380 KB Output is correct
175 Correct 179 ms 12332 KB Output is correct
176 Correct 177 ms 11844 KB Output is correct