Submission #397078

# Submission time Handle Problem Language Result Execution time Memory
397078 2021-05-01T09:51:02 Z fedoseevtimofey Event Hopping 2 (JOI21_event2) C++14
100 / 100
227 ms 25568 KB
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <bitset>
#include <chrono>
 
using namespace std;
 
typedef long long ll;
 
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n, k;
  cin >> n >> k;
  vector <int> l(n), r(n);
  vector <int> c;
  for (int i = 0; i < n; ++i) {
    cin >> l[i] >> r[i];
    c.push_back(l[i]);
    c.push_back(r[i]);
  }
  sort(c.begin(), c.end());
  c.resize(unique(c.begin(), c.end()) - c.begin());
  for (int i = 0; i < n; ++i) {
    l[i] = lower_bound(c.begin(), c.end(), l[i]) - c.begin();
    r[i] = lower_bound(c.begin(), c.end(), r[i]) - c.begin();
  }
  int m = c.size();
  vector <int> nxt(m + 1, m);
  for (int i = 0; i < n; ++i) {
    nxt[l[i]] = min(nxt[l[i]], r[i]);
  }
  for (int i = m - 1; i >= 0; --i) {
    nxt[i] = min(nxt[i], nxt[i + 1]);
  }
  const int K = 20;
  vector <vector <int>> go(K, vector <int> (m + 1, m));
  go[0] = nxt;
  for (int j = 1; j < K; ++j) {
    for (int i = 0; i <= m; ++i) {
      go[j][i] = go[j - 1][go[j - 1][i]];
    }
  }
  auto get_cnt = [&] (int L, int R) {
    int can = 0;
    for (int i = K - 1; i >= 0; --i) {
      if (go[i][L] <= R) {
        can += (1 << i);
        L = go[i][L];
      }
    }
    return can;
  };
  if (get_cnt(0, m - 1) < k) {
    cout << "-1\n";
    return 0;
  }
  set <pair <int, int>> segs;
  segs.insert({-1, 0});
  segs.insert({m - 1, m});
  int cnt = get_cnt(0, m - 1);
  auto can_add = [&] (int L, int R) {
    int new_cnt = cnt;
    auto nx = segs.lower_bound({L, -1});
    int nL = nx->first;
    if (nL < R) return false; 
    auto pr = prev(nx);
    int pR = pr->second;
    if (pR > L) return false;
    new_cnt -= get_cnt(pR, nL);
    new_cnt += get_cnt(pR, L);
    new_cnt += get_cnt(R, nL);
    ++new_cnt;
    if (new_cnt >= k) {
      cnt = new_cnt;
      segs.insert({L, R});
      return true;
    } else {
      return false;
    }
  };
  vector <int> ans;
  for (int i = 0; i < n; ++i) {
    if (ans.size() < k && can_add(l[i], r[i])) {
      ans.push_back(i);
    }
  }
  for (auto x : ans) {
    cout << x + 1 << '\n';
  }
}

Compilation message

event2.cpp: In function 'int main()':
event2.cpp:102:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  102 |     if (ans.size() < k && can_add(l[i], r[i])) {
      |         ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 118 ms 25544 KB Output is correct
5 Correct 114 ms 25332 KB Output is correct
6 Correct 114 ms 24944 KB Output is correct
7 Correct 105 ms 24552 KB Output is correct
8 Correct 116 ms 25540 KB Output is correct
9 Correct 116 ms 25420 KB Output is correct
10 Correct 110 ms 25072 KB Output is correct
11 Correct 105 ms 24480 KB Output is correct
12 Correct 101 ms 23472 KB Output is correct
13 Correct 98 ms 23392 KB Output is correct
14 Correct 94 ms 23216 KB Output is correct
15 Correct 88 ms 22832 KB Output is correct
16 Correct 72 ms 21232 KB Output is correct
17 Correct 73 ms 21184 KB Output is correct
18 Correct 68 ms 21312 KB Output is correct
19 Correct 63 ms 21220 KB Output is correct
20 Correct 63 ms 21152 KB Output is correct
21 Correct 62 ms 21184 KB Output is correct
22 Correct 65 ms 21236 KB Output is correct
23 Correct 65 ms 21260 KB Output is correct
24 Correct 63 ms 21168 KB Output is correct
25 Correct 68 ms 21248 KB Output is correct
26 Correct 68 ms 21216 KB Output is correct
27 Correct 70 ms 21184 KB Output is correct
28 Correct 54 ms 21164 KB Output is correct
29 Correct 56 ms 21200 KB Output is correct
30 Correct 56 ms 21208 KB Output is correct
31 Correct 61 ms 21224 KB Output is correct
32 Correct 62 ms 21188 KB Output is correct
33 Correct 69 ms 21244 KB Output is correct
34 Correct 80 ms 22320 KB Output is correct
35 Correct 74 ms 21680 KB Output is correct
36 Correct 64 ms 21228 KB Output is correct
37 Correct 92 ms 23092 KB Output is correct
38 Correct 93 ms 22984 KB Output is correct
39 Correct 90 ms 22884 KB Output is correct
40 Correct 87 ms 22752 KB Output is correct
41 Correct 88 ms 22612 KB Output is correct
42 Correct 68 ms 21232 KB Output is correct
43 Correct 109 ms 23032 KB Output is correct
44 Correct 102 ms 22992 KB Output is correct
45 Correct 99 ms 22728 KB Output is correct
46 Correct 99 ms 22740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 3 ms 844 KB Output is correct
29 Correct 3 ms 928 KB Output is correct
30 Correct 3 ms 844 KB Output is correct
31 Correct 3 ms 844 KB Output is correct
32 Correct 3 ms 844 KB Output is correct
33 Correct 3 ms 844 KB Output is correct
34 Correct 3 ms 848 KB Output is correct
35 Correct 5 ms 972 KB Output is correct
36 Correct 4 ms 972 KB Output is correct
37 Correct 4 ms 972 KB Output is correct
38 Correct 3 ms 844 KB Output is correct
39 Correct 5 ms 972 KB Output is correct
40 Correct 4 ms 972 KB Output is correct
41 Correct 4 ms 972 KB Output is correct
42 Correct 3 ms 840 KB Output is correct
43 Correct 4 ms 972 KB Output is correct
44 Correct 4 ms 972 KB Output is correct
45 Correct 3 ms 844 KB Output is correct
46 Correct 3 ms 844 KB Output is correct
47 Correct 3 ms 928 KB Output is correct
48 Correct 3 ms 844 KB Output is correct
49 Correct 3 ms 844 KB Output is correct
50 Correct 3 ms 844 KB Output is correct
51 Correct 3 ms 844 KB Output is correct
52 Correct 3 ms 848 KB Output is correct
53 Correct 3 ms 844 KB Output is correct
54 Correct 3 ms 844 KB Output is correct
55 Correct 4 ms 844 KB Output is correct
56 Correct 4 ms 844 KB Output is correct
57 Correct 4 ms 844 KB Output is correct
58 Correct 4 ms 804 KB Output is correct
59 Correct 3 ms 844 KB Output is correct
60 Correct 3 ms 716 KB Output is correct
61 Correct 3 ms 716 KB Output is correct
62 Correct 3 ms 716 KB Output is correct
63 Correct 3 ms 716 KB Output is correct
64 Correct 2 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 118 ms 25544 KB Output is correct
5 Correct 114 ms 25332 KB Output is correct
6 Correct 114 ms 24944 KB Output is correct
7 Correct 105 ms 24552 KB Output is correct
8 Correct 116 ms 25540 KB Output is correct
9 Correct 116 ms 25420 KB Output is correct
10 Correct 110 ms 25072 KB Output is correct
11 Correct 105 ms 24480 KB Output is correct
12 Correct 101 ms 23472 KB Output is correct
13 Correct 98 ms 23392 KB Output is correct
14 Correct 94 ms 23216 KB Output is correct
15 Correct 88 ms 22832 KB Output is correct
16 Correct 72 ms 21232 KB Output is correct
17 Correct 73 ms 21184 KB Output is correct
18 Correct 68 ms 21312 KB Output is correct
19 Correct 63 ms 21220 KB Output is correct
20 Correct 63 ms 21152 KB Output is correct
21 Correct 62 ms 21184 KB Output is correct
22 Correct 65 ms 21236 KB Output is correct
23 Correct 65 ms 21260 KB Output is correct
24 Correct 63 ms 21168 KB Output is correct
25 Correct 68 ms 21248 KB Output is correct
26 Correct 68 ms 21216 KB Output is correct
27 Correct 70 ms 21184 KB Output is correct
28 Correct 54 ms 21164 KB Output is correct
29 Correct 56 ms 21200 KB Output is correct
30 Correct 56 ms 21208 KB Output is correct
31 Correct 61 ms 21224 KB Output is correct
32 Correct 62 ms 21188 KB Output is correct
33 Correct 69 ms 21244 KB Output is correct
34 Correct 80 ms 22320 KB Output is correct
35 Correct 74 ms 21680 KB Output is correct
36 Correct 64 ms 21228 KB Output is correct
37 Correct 92 ms 23092 KB Output is correct
38 Correct 93 ms 22984 KB Output is correct
39 Correct 90 ms 22884 KB Output is correct
40 Correct 87 ms 22752 KB Output is correct
41 Correct 88 ms 22612 KB Output is correct
42 Correct 68 ms 21232 KB Output is correct
43 Correct 109 ms 23032 KB Output is correct
44 Correct 102 ms 22992 KB Output is correct
45 Correct 99 ms 22728 KB Output is correct
46 Correct 99 ms 22740 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 316 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 1 ms 204 KB Output is correct
54 Correct 1 ms 312 KB Output is correct
55 Correct 1 ms 204 KB Output is correct
56 Correct 1 ms 204 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 1 ms 204 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 1 ms 204 KB Output is correct
67 Correct 1 ms 204 KB Output is correct
68 Correct 1 ms 204 KB Output is correct
69 Correct 1 ms 204 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 312 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 1 ms 204 KB Output is correct
74 Correct 3 ms 844 KB Output is correct
75 Correct 3 ms 928 KB Output is correct
76 Correct 3 ms 844 KB Output is correct
77 Correct 3 ms 844 KB Output is correct
78 Correct 3 ms 844 KB Output is correct
79 Correct 3 ms 844 KB Output is correct
80 Correct 3 ms 848 KB Output is correct
81 Correct 5 ms 972 KB Output is correct
82 Correct 4 ms 972 KB Output is correct
83 Correct 4 ms 972 KB Output is correct
84 Correct 3 ms 844 KB Output is correct
85 Correct 5 ms 972 KB Output is correct
86 Correct 4 ms 972 KB Output is correct
87 Correct 4 ms 972 KB Output is correct
88 Correct 3 ms 840 KB Output is correct
89 Correct 4 ms 972 KB Output is correct
90 Correct 4 ms 972 KB Output is correct
91 Correct 3 ms 844 KB Output is correct
92 Correct 3 ms 844 KB Output is correct
93 Correct 3 ms 928 KB Output is correct
94 Correct 3 ms 844 KB Output is correct
95 Correct 3 ms 844 KB Output is correct
96 Correct 3 ms 844 KB Output is correct
97 Correct 3 ms 844 KB Output is correct
98 Correct 3 ms 848 KB Output is correct
99 Correct 3 ms 844 KB Output is correct
100 Correct 3 ms 844 KB Output is correct
101 Correct 4 ms 844 KB Output is correct
102 Correct 4 ms 844 KB Output is correct
103 Correct 4 ms 844 KB Output is correct
104 Correct 4 ms 804 KB Output is correct
105 Correct 3 ms 844 KB Output is correct
106 Correct 3 ms 716 KB Output is correct
107 Correct 3 ms 716 KB Output is correct
108 Correct 3 ms 716 KB Output is correct
109 Correct 3 ms 716 KB Output is correct
110 Correct 2 ms 588 KB Output is correct
111 Correct 98 ms 21180 KB Output is correct
112 Correct 90 ms 21208 KB Output is correct
113 Correct 90 ms 21312 KB Output is correct
114 Correct 88 ms 21232 KB Output is correct
115 Correct 86 ms 21312 KB Output is correct
116 Correct 85 ms 21180 KB Output is correct
117 Correct 84 ms 21236 KB Output is correct
118 Correct 227 ms 25568 KB Output is correct
119 Correct 202 ms 25052 KB Output is correct
120 Correct 150 ms 22852 KB Output is correct
121 Correct 80 ms 21240 KB Output is correct
122 Correct 170 ms 23472 KB Output is correct
123 Correct 156 ms 23140 KB Output is correct
124 Correct 150 ms 22832 KB Output is correct
125 Correct 83 ms 21312 KB Output is correct
126 Correct 123 ms 21180 KB Output is correct
127 Correct 117 ms 21184 KB Output is correct
128 Correct 110 ms 21204 KB Output is correct
129 Correct 80 ms 21116 KB Output is correct
130 Correct 99 ms 21184 KB Output is correct
131 Correct 97 ms 21232 KB Output is correct
132 Correct 95 ms 21216 KB Output is correct
133 Correct 83 ms 21184 KB Output is correct
134 Correct 96 ms 21184 KB Output is correct
135 Correct 91 ms 21236 KB Output is correct
136 Correct 92 ms 21232 KB Output is correct
137 Correct 83 ms 21136 KB Output is correct
138 Correct 90 ms 21220 KB Output is correct
139 Correct 90 ms 21184 KB Output is correct
140 Correct 86 ms 21248 KB Output is correct
141 Correct 85 ms 21124 KB Output is correct
142 Correct 109 ms 17668 KB Output is correct
143 Correct 112 ms 17680 KB Output is correct
144 Correct 110 ms 17700 KB Output is correct
145 Correct 96 ms 17652 KB Output is correct
146 Correct 97 ms 17628 KB Output is correct
147 Correct 95 ms 17624 KB Output is correct
148 Correct 101 ms 17388 KB Output is correct
149 Correct 93 ms 17284 KB Output is correct
150 Correct 91 ms 17100 KB Output is correct
151 Correct 93 ms 16508 KB Output is correct
152 Correct 46 ms 12484 KB Output is correct
153 Correct 99 ms 17788 KB Output is correct
154 Correct 100 ms 17596 KB Output is correct
155 Correct 97 ms 17392 KB Output is correct
156 Correct 96 ms 17548 KB Output is correct
157 Correct 93 ms 17216 KB Output is correct
158 Correct 94 ms 17088 KB Output is correct
159 Correct 90 ms 16504 KB Output is correct
160 Correct 46 ms 12392 KB Output is correct
161 Correct 177 ms 19028 KB Output is correct
162 Correct 149 ms 18800 KB Output is correct
163 Correct 138 ms 18804 KB Output is correct
164 Correct 142 ms 18728 KB Output is correct
165 Correct 132 ms 18460 KB Output is correct
166 Correct 60 ms 21232 KB Output is correct
167 Correct 96 ms 23036 KB Output is correct
168 Correct 94 ms 22836 KB Output is correct
169 Correct 97 ms 22740 KB Output is correct
170 Correct 92 ms 22676 KB Output is correct
171 Correct 89 ms 22532 KB Output is correct
172 Correct 95 ms 23088 KB Output is correct
173 Correct 157 ms 14848 KB Output is correct
174 Correct 148 ms 14744 KB Output is correct
175 Correct 149 ms 14716 KB Output is correct
176 Correct 123 ms 14400 KB Output is correct