답안 #237232

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
237232 2020-06-05T10:35:23 Z rama_pang 새 집 (APIO18_new_home) C++14
100 / 100
2383 ms 83692 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 < (int) 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 9 ms 7412 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 10 ms 7424 KB Output is correct
6 Correct 10 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 7424 KB Output is correct
12 Correct 10 ms 7552 KB Output is correct
13 Correct 10 ms 7552 KB Output is correct
14 Correct 10 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 7552 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 9 ms 7552 KB Output is correct
26 Correct 9 ms 7552 KB Output is correct
27 Correct 10 ms 7552 KB Output is correct
28 Correct 9 ms 7552 KB Output is correct
29 Correct 9 ms 7552 KB Output is correct
30 Correct 9 ms 7424 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 7412 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 10 ms 7424 KB Output is correct
6 Correct 10 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 7424 KB Output is correct
12 Correct 10 ms 7552 KB Output is correct
13 Correct 10 ms 7552 KB Output is correct
14 Correct 10 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 7552 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 9 ms 7552 KB Output is correct
26 Correct 9 ms 7552 KB Output is correct
27 Correct 10 ms 7552 KB Output is correct
28 Correct 9 ms 7552 KB Output is correct
29 Correct 9 ms 7552 KB Output is correct
30 Correct 9 ms 7424 KB Output is correct
31 Correct 262 ms 21808 KB Output is correct
32 Correct 239 ms 19476 KB Output is correct
33 Correct 292 ms 20964 KB Output is correct
34 Correct 255 ms 21548 KB Output is correct
35 Correct 272 ms 20920 KB Output is correct
36 Correct 321 ms 21156 KB Output is correct
37 Correct 249 ms 21104 KB Output is correct
38 Correct 267 ms 20700 KB Output is correct
39 Correct 218 ms 21032 KB Output is correct
40 Correct 230 ms 20728 KB Output is correct
41 Correct 195 ms 20932 KB Output is correct
42 Correct 198 ms 21308 KB Output is correct
43 Correct 152 ms 20916 KB Output is correct
44 Correct 187 ms 21172 KB Output is correct
45 Correct 179 ms 20944 KB Output is correct
46 Correct 171 ms 20764 KB Output is correct
47 Correct 154 ms 20572 KB Output is correct
48 Correct 147 ms 20488 KB Output is correct
49 Correct 164 ms 20820 KB Output is correct
50 Correct 185 ms 21464 KB Output is correct
51 Correct 159 ms 20680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 863 ms 64040 KB Output is correct
2 Correct 1244 ms 61352 KB Output is correct
3 Correct 1061 ms 83692 KB Output is correct
4 Correct 905 ms 64564 KB Output is correct
5 Correct 1787 ms 68204 KB Output is correct
6 Correct 1336 ms 62036 KB Output is correct
7 Correct 911 ms 83288 KB Output is correct
8 Correct 800 ms 63532 KB Output is correct
9 Correct 801 ms 62200 KB Output is correct
10 Correct 980 ms 60928 KB Output is correct
11 Correct 904 ms 60032 KB Output is correct
12 Correct 869 ms 61216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1172 ms 62072 KB Output is correct
2 Correct 1168 ms 61100 KB Output is correct
3 Correct 1654 ms 60824 KB Output is correct
4 Correct 1360 ms 82800 KB Output is correct
5 Correct 1207 ms 63732 KB Output is correct
6 Correct 1227 ms 64192 KB Output is correct
7 Correct 2383 ms 67828 KB Output is correct
8 Correct 1727 ms 61660 KB Output is correct
9 Correct 1121 ms 82788 KB Output is correct
10 Correct 1022 ms 63436 KB Output is correct
11 Correct 1067 ms 61536 KB Output is correct
12 Correct 1270 ms 60100 KB Output is correct
13 Correct 921 ms 59320 KB Output is correct
14 Correct 942 ms 59788 KB Output is correct
15 Correct 1020 ms 59396 KB Output is correct
16 Correct 1036 ms 60916 KB Output is correct
17 Correct 1115 ms 59620 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 7412 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 10 ms 7424 KB Output is correct
6 Correct 10 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 7424 KB Output is correct
12 Correct 10 ms 7552 KB Output is correct
13 Correct 10 ms 7552 KB Output is correct
14 Correct 10 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 7552 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 9 ms 7552 KB Output is correct
26 Correct 9 ms 7552 KB Output is correct
27 Correct 10 ms 7552 KB Output is correct
28 Correct 9 ms 7552 KB Output is correct
29 Correct 9 ms 7552 KB Output is correct
30 Correct 9 ms 7424 KB Output is correct
31 Correct 262 ms 21808 KB Output is correct
32 Correct 239 ms 19476 KB Output is correct
33 Correct 292 ms 20964 KB Output is correct
34 Correct 255 ms 21548 KB Output is correct
35 Correct 272 ms 20920 KB Output is correct
36 Correct 321 ms 21156 KB Output is correct
37 Correct 249 ms 21104 KB Output is correct
38 Correct 267 ms 20700 KB Output is correct
39 Correct 218 ms 21032 KB Output is correct
40 Correct 230 ms 20728 KB Output is correct
41 Correct 195 ms 20932 KB Output is correct
42 Correct 198 ms 21308 KB Output is correct
43 Correct 152 ms 20916 KB Output is correct
44 Correct 187 ms 21172 KB Output is correct
45 Correct 179 ms 20944 KB Output is correct
46 Correct 171 ms 20764 KB Output is correct
47 Correct 154 ms 20572 KB Output is correct
48 Correct 147 ms 20488 KB Output is correct
49 Correct 164 ms 20820 KB Output is correct
50 Correct 185 ms 21464 KB Output is correct
51 Correct 159 ms 20680 KB Output is correct
52 Correct 265 ms 22864 KB Output is correct
53 Correct 269 ms 22780 KB Output is correct
54 Correct 237 ms 21872 KB Output is correct
55 Correct 215 ms 21760 KB Output is correct
56 Correct 217 ms 21976 KB Output is correct
57 Correct 200 ms 21088 KB Output is correct
58 Correct 220 ms 22032 KB Output is correct
59 Correct 218 ms 22108 KB Output is correct
60 Correct 203 ms 21464 KB Output is correct
61 Correct 175 ms 22300 KB Output is correct
62 Correct 245 ms 22792 KB Output is correct
63 Correct 237 ms 22216 KB Output is correct
64 Correct 224 ms 21796 KB Output is correct
65 Correct 215 ms 21448 KB Output is correct
66 Correct 197 ms 21296 KB Output is correct
67 Correct 187 ms 19544 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 7412 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 10 ms 7424 KB Output is correct
6 Correct 10 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 7424 KB Output is correct
12 Correct 10 ms 7552 KB Output is correct
13 Correct 10 ms 7552 KB Output is correct
14 Correct 10 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 7552 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 9 ms 7552 KB Output is correct
26 Correct 9 ms 7552 KB Output is correct
27 Correct 10 ms 7552 KB Output is correct
28 Correct 9 ms 7552 KB Output is correct
29 Correct 9 ms 7552 KB Output is correct
30 Correct 9 ms 7424 KB Output is correct
31 Correct 262 ms 21808 KB Output is correct
32 Correct 239 ms 19476 KB Output is correct
33 Correct 292 ms 20964 KB Output is correct
34 Correct 255 ms 21548 KB Output is correct
35 Correct 272 ms 20920 KB Output is correct
36 Correct 321 ms 21156 KB Output is correct
37 Correct 249 ms 21104 KB Output is correct
38 Correct 267 ms 20700 KB Output is correct
39 Correct 218 ms 21032 KB Output is correct
40 Correct 230 ms 20728 KB Output is correct
41 Correct 195 ms 20932 KB Output is correct
42 Correct 198 ms 21308 KB Output is correct
43 Correct 152 ms 20916 KB Output is correct
44 Correct 187 ms 21172 KB Output is correct
45 Correct 179 ms 20944 KB Output is correct
46 Correct 171 ms 20764 KB Output is correct
47 Correct 154 ms 20572 KB Output is correct
48 Correct 147 ms 20488 KB Output is correct
49 Correct 164 ms 20820 KB Output is correct
50 Correct 185 ms 21464 KB Output is correct
51 Correct 159 ms 20680 KB Output is correct
52 Correct 863 ms 64040 KB Output is correct
53 Correct 1244 ms 61352 KB Output is correct
54 Correct 1061 ms 83692 KB Output is correct
55 Correct 905 ms 64564 KB Output is correct
56 Correct 1787 ms 68204 KB Output is correct
57 Correct 1336 ms 62036 KB Output is correct
58 Correct 911 ms 83288 KB Output is correct
59 Correct 800 ms 63532 KB Output is correct
60 Correct 801 ms 62200 KB Output is correct
61 Correct 980 ms 60928 KB Output is correct
62 Correct 904 ms 60032 KB Output is correct
63 Correct 869 ms 61216 KB Output is correct
64 Correct 1172 ms 62072 KB Output is correct
65 Correct 1168 ms 61100 KB Output is correct
66 Correct 1654 ms 60824 KB Output is correct
67 Correct 1360 ms 82800 KB Output is correct
68 Correct 1207 ms 63732 KB Output is correct
69 Correct 1227 ms 64192 KB Output is correct
70 Correct 2383 ms 67828 KB Output is correct
71 Correct 1727 ms 61660 KB Output is correct
72 Correct 1121 ms 82788 KB Output is correct
73 Correct 1022 ms 63436 KB Output is correct
74 Correct 1067 ms 61536 KB Output is correct
75 Correct 1270 ms 60100 KB Output is correct
76 Correct 921 ms 59320 KB Output is correct
77 Correct 942 ms 59788 KB Output is correct
78 Correct 1020 ms 59396 KB Output is correct
79 Correct 1036 ms 60916 KB Output is correct
80 Correct 1115 ms 59620 KB Output is correct
81 Correct 265 ms 22864 KB Output is correct
82 Correct 269 ms 22780 KB Output is correct
83 Correct 237 ms 21872 KB Output is correct
84 Correct 215 ms 21760 KB Output is correct
85 Correct 217 ms 21976 KB Output is correct
86 Correct 200 ms 21088 KB Output is correct
87 Correct 220 ms 22032 KB Output is correct
88 Correct 218 ms 22108 KB Output is correct
89 Correct 203 ms 21464 KB Output is correct
90 Correct 175 ms 22300 KB Output is correct
91 Correct 245 ms 22792 KB Output is correct
92 Correct 237 ms 22216 KB Output is correct
93 Correct 224 ms 21796 KB Output is correct
94 Correct 215 ms 21448 KB Output is correct
95 Correct 197 ms 21296 KB Output is correct
96 Correct 187 ms 19544 KB Output is correct
97 Correct 1539 ms 82256 KB Output is correct
98 Correct 1210 ms 60292 KB Output is correct
99 Correct 1755 ms 59584 KB Output is correct
100 Correct 1542 ms 82428 KB Output is correct
101 Correct 1391 ms 63512 KB Output is correct
102 Correct 1846 ms 60252 KB Output is correct
103 Correct 1412 ms 59604 KB Output is correct
104 Correct 1551 ms 58992 KB Output is correct
105 Correct 1211 ms 59368 KB Output is correct
106 Correct 1282 ms 58584 KB Output is correct
107 Correct 1160 ms 62108 KB Output is correct
108 Correct 1201 ms 80312 KB Output is correct
109 Correct 1102 ms 61456 KB Output is correct
110 Correct 1181 ms 63024 KB Output is correct
111 Correct 1235 ms 79996 KB Output is correct
112 Correct 1156 ms 60916 KB Output is correct
113 Correct 904 ms 81520 KB Output is correct
114 Correct 1345 ms 81412 KB Output is correct
115 Correct 1286 ms 79892 KB Output is correct
116 Correct 1272 ms 61816 KB Output is correct
117 Correct 1193 ms 60740 KB Output is correct
118 Correct 1107 ms 60448 KB Output is correct
119 Correct 949 ms 60316 KB Output is correct
120 Correct 736 ms 56696 KB Output is correct
121 Correct 833 ms 57024 KB Output is correct
122 Correct 765 ms 57328 KB Output is correct
123 Correct 840 ms 57508 KB Output is correct
124 Correct 942 ms 58988 KB Output is correct
125 Correct 827 ms 57620 KB Output is correct
126 Correct 966 ms 61080 KB Output is correct