답안 #237231

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
237231 2020-06-05T10:33:13 Z rama_pang 새 집 (APIO18_new_home) C++14
100 / 100
2309 ms 94748 KB
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e8;
const int MAXN = 3e5 + 5;

int N, K, Q;
int X[MAXN];
int ans[MAXN];

vector<array<int, 2>> shops[MAXN]; // shops[type] = (time, id)
array<int, 3> queries[MAXN]; // (x-coord, time, id)

auto active_cmp = [&](int a, int b) {
  if (X[a] != X[b]) return X[a] < X[b];
  return a < b;
};
map<int, int, decltype(active_cmp)> active(active_cmp);

void Solve() {
  vector<array<int, 4>> lines; // (x1, x2, t1, t2)
  int sz = 2 * N + 1;
  vector<int> segtree(2 * sz, 0); // of time

  for (int k = 0; k < K; k++) {
    active.clear();
    active[N + 0] = 0;
    active[N + 1] = 0;
    for (auto s : shops[k]) {
      if (active.count(s[1]) == 0) {
        auto it1 = active.upper_bound(s[1]);
        auto it2 = it1--;
        lines.push_back({(X[it1->first] + X[it2->first] + 1) >> 1, X[it2->first], it2->second, s[0]});
        it2->second = s[0];
        active[s[1]] = s[0];
      } else {
        auto it1 = active.upper_bound(s[1]);
        auto it2 = it1--;
        lines.push_back({(X[it1->first] + X[it2->first] + 1) >> 1, X[it2->first], it2->second, s[0]});
        it2->second = s[0];
        it2 = it1--;
        lines.push_back({(X[it1->first] + X[it2->first] + 1) >> 1, X[it2->first], it2->second, s[0]});
        active.erase(it2);
      }
    }
    lines.push_back({0, 2 * INF, active[N + 1], sz});
  }

  sort(begin(lines), end(lines));
  for (int q = 0, j = 0; q < Q; q++) {
    while (j < lines.size() && lines[j][0] <= queries[q][0]) {
      for (int l = lines[j][2] + sz, r = lines[j][3] + sz; l < r; l /= 2, r /= 2) {
        if (l & 1) {
          segtree[l] = max(segtree[l], lines[j][1]);
          l++;
        }
        if (r & 1) {
          r--;
          segtree[r] = max(segtree[r], lines[j][1]);
        }
      }
      j++;
    }
    for (int i = queries[q][1] + sz; i > 0; i /= 2) {
      ans[queries[q][2]] = max(ans[queries[q][2]], segtree[i] - queries[q][0]);
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  cin >> N >> K >> Q;

  vector<int> times = {0};
  for (int i = 0; i < N; i++) {
    int t, a, b;
    cin >> X[i] >> t >> a >> b;
    t--;
    shops[t].push_back({a, i});
    shops[t].push_back({b + 1, i});
    times.push_back(a);
    times.push_back(b + 1);
  }
  X[N + 0] = - 2 * INF;
  X[N + 1] = + 2 * INF;

  sort(begin(times), end(times));
  for (int i = 0; i < K; i++) {
    for (auto &j : shops[i]) {
      j[0] = lower_bound(begin(times), end(times), j[0]) - begin(times);
    }
    sort(begin(shops[i]), end(shops[i]));
  }

  for (int i = 0; i < Q; i++) {
    cin >> queries[i][0] >> queries[i][1];
    queries[i][2] = i;
    queries[i][1] = upper_bound(begin(times), end(times), queries[i][1]) - begin(times) - 1;
  }
  sort(queries, queries + Q);

  Solve();
  for (int i = 0; i < N; i++) {
    X[i] = INF - X[i] + 1;
  }
  for (int i = 0; i < Q; i++) {
    queries[i][0] = INF - queries[i][0] + 1;
  }
  reverse(queries, queries + Q);
  Solve();

  for (int i = 0; i < Q; i++) {
    if (ans[i] >= INF) ans[i] = -1;
    cout << ans[i] << "\n";
  }
  return 0;
}

Compilation message

new_home.cpp: In function 'void Solve()':
new_home.cpp:51:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (j < lines.size() && lines[j][0] <= queries[q][0]) {
            ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 9 ms 7456 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 10 ms 7552 KB Output is correct
6 Correct 11 ms 7552 KB Output is correct
7 Correct 10 ms 7552 KB Output is correct
8 Correct 10 ms 7552 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7552 KB Output is correct
11 Correct 10 ms 7552 KB Output is correct
12 Correct 10 ms 7552 KB Output is correct
13 Correct 10 ms 7552 KB Output is correct
14 Correct 9 ms 7552 KB Output is correct
15 Correct 10 ms 7552 KB Output is correct
16 Correct 10 ms 7552 KB Output is correct
17 Correct 10 ms 7552 KB Output is correct
18 Correct 10 ms 7552 KB Output is correct
19 Correct 10 ms 7552 KB Output is correct
20 Correct 10 ms 7552 KB Output is correct
21 Correct 10 ms 7680 KB Output is correct
22 Correct 10 ms 7552 KB Output is correct
23 Correct 10 ms 7552 KB Output is correct
24 Correct 10 ms 7552 KB Output is correct
25 Correct 10 ms 7552 KB Output is correct
26 Correct 10 ms 7552 KB Output is correct
27 Correct 11 ms 7424 KB Output is correct
28 Correct 10 ms 7552 KB Output is correct
29 Correct 9 ms 7552 KB Output is correct
30 Correct 9 ms 7552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 9 ms 7456 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 10 ms 7552 KB Output is correct
6 Correct 11 ms 7552 KB Output is correct
7 Correct 10 ms 7552 KB Output is correct
8 Correct 10 ms 7552 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7552 KB Output is correct
11 Correct 10 ms 7552 KB Output is correct
12 Correct 10 ms 7552 KB Output is correct
13 Correct 10 ms 7552 KB Output is correct
14 Correct 9 ms 7552 KB Output is correct
15 Correct 10 ms 7552 KB Output is correct
16 Correct 10 ms 7552 KB Output is correct
17 Correct 10 ms 7552 KB Output is correct
18 Correct 10 ms 7552 KB Output is correct
19 Correct 10 ms 7552 KB Output is correct
20 Correct 10 ms 7552 KB Output is correct
21 Correct 10 ms 7680 KB Output is correct
22 Correct 10 ms 7552 KB Output is correct
23 Correct 10 ms 7552 KB Output is correct
24 Correct 10 ms 7552 KB Output is correct
25 Correct 10 ms 7552 KB Output is correct
26 Correct 10 ms 7552 KB Output is correct
27 Correct 11 ms 7424 KB Output is correct
28 Correct 10 ms 7552 KB Output is correct
29 Correct 9 ms 7552 KB Output is correct
30 Correct 9 ms 7552 KB Output is correct
31 Correct 269 ms 21720 KB Output is correct
32 Correct 240 ms 19240 KB Output is correct
33 Correct 300 ms 21008 KB Output is correct
34 Correct 253 ms 21688 KB Output is correct
35 Correct 295 ms 21192 KB Output is correct
36 Correct 309 ms 21160 KB Output is correct
37 Correct 252 ms 21128 KB Output is correct
38 Correct 284 ms 20700 KB Output is correct
39 Correct 214 ms 21296 KB Output is correct
40 Correct 238 ms 20716 KB Output is correct
41 Correct 190 ms 20932 KB Output is correct
42 Correct 194 ms 21484 KB Output is correct
43 Correct 156 ms 20916 KB Output is correct
44 Correct 196 ms 21172 KB Output is correct
45 Correct 193 ms 21112 KB Output is correct
46 Correct 170 ms 20788 KB Output is correct
47 Correct 153 ms 20572 KB Output is correct
48 Correct 149 ms 20624 KB Output is correct
49 Correct 169 ms 20932 KB Output is correct
50 Correct 198 ms 21464 KB Output is correct
51 Correct 165 ms 20804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 908 ms 73424 KB Output is correct
2 Correct 1294 ms 69312 KB Output is correct
3 Correct 1127 ms 92956 KB Output is correct
4 Correct 918 ms 73776 KB Output is correct
5 Correct 1870 ms 76416 KB Output is correct
6 Correct 1328 ms 70176 KB Output is correct
7 Correct 919 ms 93128 KB Output is correct
8 Correct 817 ms 73092 KB Output is correct
9 Correct 843 ms 71516 KB Output is correct
10 Correct 999 ms 69772 KB Output is correct
11 Correct 890 ms 68160 KB Output is correct
12 Correct 882 ms 69920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1195 ms 70768 KB Output is correct
2 Correct 1135 ms 61156 KB Output is correct
3 Correct 1595 ms 68948 KB Output is correct
4 Correct 1353 ms 92648 KB Output is correct
5 Correct 1208 ms 72860 KB Output is correct
6 Correct 1209 ms 73792 KB Output is correct
7 Correct 2309 ms 76128 KB Output is correct
8 Correct 1711 ms 70028 KB Output is correct
9 Correct 1141 ms 92776 KB Output is correct
10 Correct 1053 ms 72760 KB Output is correct
11 Correct 1157 ms 70880 KB Output is correct
12 Correct 1313 ms 69384 KB Output is correct
13 Correct 937 ms 67744 KB Output is correct
14 Correct 944 ms 68204 KB Output is correct
15 Correct 1053 ms 67988 KB Output is correct
16 Correct 1048 ms 69696 KB Output is correct
17 Correct 1133 ms 68024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 9 ms 7456 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 10 ms 7552 KB Output is correct
6 Correct 11 ms 7552 KB Output is correct
7 Correct 10 ms 7552 KB Output is correct
8 Correct 10 ms 7552 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7552 KB Output is correct
11 Correct 10 ms 7552 KB Output is correct
12 Correct 10 ms 7552 KB Output is correct
13 Correct 10 ms 7552 KB Output is correct
14 Correct 9 ms 7552 KB Output is correct
15 Correct 10 ms 7552 KB Output is correct
16 Correct 10 ms 7552 KB Output is correct
17 Correct 10 ms 7552 KB Output is correct
18 Correct 10 ms 7552 KB Output is correct
19 Correct 10 ms 7552 KB Output is correct
20 Correct 10 ms 7552 KB Output is correct
21 Correct 10 ms 7680 KB Output is correct
22 Correct 10 ms 7552 KB Output is correct
23 Correct 10 ms 7552 KB Output is correct
24 Correct 10 ms 7552 KB Output is correct
25 Correct 10 ms 7552 KB Output is correct
26 Correct 10 ms 7552 KB Output is correct
27 Correct 11 ms 7424 KB Output is correct
28 Correct 10 ms 7552 KB Output is correct
29 Correct 9 ms 7552 KB Output is correct
30 Correct 9 ms 7552 KB Output is correct
31 Correct 269 ms 21720 KB Output is correct
32 Correct 240 ms 19240 KB Output is correct
33 Correct 300 ms 21008 KB Output is correct
34 Correct 253 ms 21688 KB Output is correct
35 Correct 295 ms 21192 KB Output is correct
36 Correct 309 ms 21160 KB Output is correct
37 Correct 252 ms 21128 KB Output is correct
38 Correct 284 ms 20700 KB Output is correct
39 Correct 214 ms 21296 KB Output is correct
40 Correct 238 ms 20716 KB Output is correct
41 Correct 190 ms 20932 KB Output is correct
42 Correct 194 ms 21484 KB Output is correct
43 Correct 156 ms 20916 KB Output is correct
44 Correct 196 ms 21172 KB Output is correct
45 Correct 193 ms 21112 KB Output is correct
46 Correct 170 ms 20788 KB Output is correct
47 Correct 153 ms 20572 KB Output is correct
48 Correct 149 ms 20624 KB Output is correct
49 Correct 169 ms 20932 KB Output is correct
50 Correct 198 ms 21464 KB Output is correct
51 Correct 165 ms 20804 KB Output is correct
52 Correct 268 ms 22912 KB Output is correct
53 Correct 271 ms 22912 KB Output is correct
54 Correct 247 ms 22100 KB Output is correct
55 Correct 208 ms 21876 KB Output is correct
56 Correct 223 ms 21980 KB Output is correct
57 Correct 200 ms 21224 KB Output is correct
58 Correct 219 ms 21928 KB Output is correct
59 Correct 227 ms 21968 KB Output is correct
60 Correct 205 ms 21468 KB Output is correct
61 Correct 175 ms 22284 KB Output is correct
62 Correct 257 ms 22888 KB Output is correct
63 Correct 236 ms 21980 KB Output is correct
64 Correct 226 ms 21632 KB Output is correct
65 Correct 217 ms 21452 KB Output is correct
66 Correct 203 ms 21296 KB Output is correct
67 Correct 188 ms 19672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 9 ms 7456 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 10 ms 7552 KB Output is correct
6 Correct 11 ms 7552 KB Output is correct
7 Correct 10 ms 7552 KB Output is correct
8 Correct 10 ms 7552 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7552 KB Output is correct
11 Correct 10 ms 7552 KB Output is correct
12 Correct 10 ms 7552 KB Output is correct
13 Correct 10 ms 7552 KB Output is correct
14 Correct 9 ms 7552 KB Output is correct
15 Correct 10 ms 7552 KB Output is correct
16 Correct 10 ms 7552 KB Output is correct
17 Correct 10 ms 7552 KB Output is correct
18 Correct 10 ms 7552 KB Output is correct
19 Correct 10 ms 7552 KB Output is correct
20 Correct 10 ms 7552 KB Output is correct
21 Correct 10 ms 7680 KB Output is correct
22 Correct 10 ms 7552 KB Output is correct
23 Correct 10 ms 7552 KB Output is correct
24 Correct 10 ms 7552 KB Output is correct
25 Correct 10 ms 7552 KB Output is correct
26 Correct 10 ms 7552 KB Output is correct
27 Correct 11 ms 7424 KB Output is correct
28 Correct 10 ms 7552 KB Output is correct
29 Correct 9 ms 7552 KB Output is correct
30 Correct 9 ms 7552 KB Output is correct
31 Correct 269 ms 21720 KB Output is correct
32 Correct 240 ms 19240 KB Output is correct
33 Correct 300 ms 21008 KB Output is correct
34 Correct 253 ms 21688 KB Output is correct
35 Correct 295 ms 21192 KB Output is correct
36 Correct 309 ms 21160 KB Output is correct
37 Correct 252 ms 21128 KB Output is correct
38 Correct 284 ms 20700 KB Output is correct
39 Correct 214 ms 21296 KB Output is correct
40 Correct 238 ms 20716 KB Output is correct
41 Correct 190 ms 20932 KB Output is correct
42 Correct 194 ms 21484 KB Output is correct
43 Correct 156 ms 20916 KB Output is correct
44 Correct 196 ms 21172 KB Output is correct
45 Correct 193 ms 21112 KB Output is correct
46 Correct 170 ms 20788 KB Output is correct
47 Correct 153 ms 20572 KB Output is correct
48 Correct 149 ms 20624 KB Output is correct
49 Correct 169 ms 20932 KB Output is correct
50 Correct 198 ms 21464 KB Output is correct
51 Correct 165 ms 20804 KB Output is correct
52 Correct 908 ms 73424 KB Output is correct
53 Correct 1294 ms 69312 KB Output is correct
54 Correct 1127 ms 92956 KB Output is correct
55 Correct 918 ms 73776 KB Output is correct
56 Correct 1870 ms 76416 KB Output is correct
57 Correct 1328 ms 70176 KB Output is correct
58 Correct 919 ms 93128 KB Output is correct
59 Correct 817 ms 73092 KB Output is correct
60 Correct 843 ms 71516 KB Output is correct
61 Correct 999 ms 69772 KB Output is correct
62 Correct 890 ms 68160 KB Output is correct
63 Correct 882 ms 69920 KB Output is correct
64 Correct 1195 ms 70768 KB Output is correct
65 Correct 1135 ms 61156 KB Output is correct
66 Correct 1595 ms 68948 KB Output is correct
67 Correct 1353 ms 92648 KB Output is correct
68 Correct 1208 ms 72860 KB Output is correct
69 Correct 1209 ms 73792 KB Output is correct
70 Correct 2309 ms 76128 KB Output is correct
71 Correct 1711 ms 70028 KB Output is correct
72 Correct 1141 ms 92776 KB Output is correct
73 Correct 1053 ms 72760 KB Output is correct
74 Correct 1157 ms 70880 KB Output is correct
75 Correct 1313 ms 69384 KB Output is correct
76 Correct 937 ms 67744 KB Output is correct
77 Correct 944 ms 68204 KB Output is correct
78 Correct 1053 ms 67988 KB Output is correct
79 Correct 1048 ms 69696 KB Output is correct
80 Correct 1133 ms 68024 KB Output is correct
81 Correct 268 ms 22912 KB Output is correct
82 Correct 271 ms 22912 KB Output is correct
83 Correct 247 ms 22100 KB Output is correct
84 Correct 208 ms 21876 KB Output is correct
85 Correct 223 ms 21980 KB Output is correct
86 Correct 200 ms 21224 KB Output is correct
87 Correct 219 ms 21928 KB Output is correct
88 Correct 227 ms 21968 KB Output is correct
89 Correct 205 ms 21468 KB Output is correct
90 Correct 175 ms 22284 KB Output is correct
91 Correct 257 ms 22888 KB Output is correct
92 Correct 236 ms 21980 KB Output is correct
93 Correct 226 ms 21632 KB Output is correct
94 Correct 217 ms 21452 KB Output is correct
95 Correct 203 ms 21296 KB Output is correct
96 Correct 188 ms 19672 KB Output is correct
97 Correct 1586 ms 94696 KB Output is correct
98 Correct 1215 ms 61572 KB Output is correct
99 Correct 1795 ms 70392 KB Output is correct
100 Correct 1563 ms 94704 KB Output is correct
101 Correct 1399 ms 75700 KB Output is correct
102 Correct 1957 ms 71428 KB Output is correct
103 Correct 1424 ms 70696 KB Output is correct
104 Correct 1558 ms 70184 KB Output is correct
105 Correct 1223 ms 70512 KB Output is correct
106 Correct 1301 ms 69968 KB Output is correct
107 Correct 1126 ms 74600 KB Output is correct
108 Correct 1186 ms 92688 KB Output is correct
109 Correct 1093 ms 74040 KB Output is correct
110 Correct 1173 ms 75640 KB Output is correct
111 Correct 1241 ms 93052 KB Output is correct
112 Correct 1118 ms 73636 KB Output is correct
113 Correct 909 ms 91724 KB Output is correct
114 Correct 1385 ms 94748 KB Output is correct
115 Correct 1325 ms 93100 KB Output is correct
116 Correct 1281 ms 74672 KB Output is correct
117 Correct 1187 ms 73660 KB Output is correct
118 Correct 1105 ms 73048 KB Output is correct
119 Correct 953 ms 64508 KB Output is correct
120 Correct 721 ms 68220 KB Output is correct
121 Correct 772 ms 68932 KB Output is correct
122 Correct 747 ms 69204 KB Output is correct
123 Correct 823 ms 69668 KB Output is correct
124 Correct 925 ms 72144 KB Output is correct
125 Correct 835 ms 69860 KB Output is correct
126 Correct 988 ms 74076 KB Output is correct