답안 #59286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59286 2018-07-21T11:55:00 Z Just_Solve_The_Problem 새 집 (APIO18_new_home) C++11
12 / 100
2780 ms 118444 KB
#include <bits/stdc++.h>

using namespace std;

#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

const int N = (int)3e5 + 7;
const int inf = (int)1e9 + 7;

int n, k, q;
int x[N], t[N], a[N], b[N];
multiset < int > s[404];
int ans[N];

struct query {
  int type, x, t, y, ind;
  query() {}
  query(int _type, int _x, int _t, int _y) {
    type = _type;
    x = _x;
    t = _t;
    y = _y;
  }
};
vector < query > vec;

bool cmp(query &A, query &B) {
  if (A.y != B.y)
    return A.y < B.y;
  return A.type < B.type;
}

main() {
	scanf("%d %d %d", &n, &k, &q);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d %d %d", &x[i], &t[i], &a[i], &b[i]);
    vec.pb(query(0, x[i], t[i], a[i]));
    vec.pb(query(1, x[i], t[i], b[i] + 1));
  }
  for (int i = 1, l, y; i <= q; i++) {
    scanf("%d %d", &l, &y);
    vec.pb(query(2, l, 0, y));
    vec.back().ind = i;
  }
  sort(all(vec), cmp);
  for (auto to : vec) {
    if (to.type == 0) {
      s[to.t].insert(to.x);
    } else if (to.type == 1) {
      s[to.t].erase(s[to.t].find(to.x));
    } else {
      int res = -1;
      for (int i = 1; i <= k; i++) {
        if (s[i].empty()) {
          res = -1;
          break;
        } else {
          auto it = s[i].lower_bound(to.x);
          int asd = inf;
          if (it != s[i].end())
            asd = min(asd, abs(to.x - (*it)));
          if (it != s[i].begin()) {
            it--;
            asd = min(asd, abs(to.x - (*it)));
          }
          res = max(res, asd);
        }
      }
      ans[to.ind] = res;
    }
  }
  for (int i = 1; i <= q; i++) {
    printf("%d\n", ans[i]);
  }
}

Compilation message

new_home.cpp:39:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
new_home.cpp: In function 'int main()':
new_home.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &k, &q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d %d", &x[i], &t[i], &a[i], &b[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &l, &y);
     ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 2 ms 676 KB Output is correct
4 Correct 3 ms 676 KB Output is correct
5 Correct 3 ms 676 KB Output is correct
6 Correct 5 ms 676 KB Output is correct
7 Correct 4 ms 708 KB Output is correct
8 Correct 3 ms 708 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 4 ms 928 KB Output is correct
12 Correct 4 ms 928 KB Output is correct
13 Correct 4 ms 928 KB Output is correct
14 Correct 4 ms 928 KB Output is correct
15 Correct 4 ms 928 KB Output is correct
16 Correct 6 ms 932 KB Output is correct
17 Correct 4 ms 932 KB Output is correct
18 Correct 3 ms 972 KB Output is correct
19 Correct 3 ms 972 KB Output is correct
20 Correct 4 ms 972 KB Output is correct
21 Correct 4 ms 972 KB Output is correct
22 Correct 5 ms 1052 KB Output is correct
23 Correct 4 ms 1052 KB Output is correct
24 Correct 4 ms 1052 KB Output is correct
25 Correct 4 ms 1052 KB Output is correct
26 Correct 3 ms 1276 KB Output is correct
27 Correct 4 ms 1276 KB Output is correct
28 Correct 3 ms 1276 KB Output is correct
29 Correct 3 ms 1276 KB Output is correct
30 Correct 4 ms 1276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 2 ms 676 KB Output is correct
4 Correct 3 ms 676 KB Output is correct
5 Correct 3 ms 676 KB Output is correct
6 Correct 5 ms 676 KB Output is correct
7 Correct 4 ms 708 KB Output is correct
8 Correct 3 ms 708 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 4 ms 928 KB Output is correct
12 Correct 4 ms 928 KB Output is correct
13 Correct 4 ms 928 KB Output is correct
14 Correct 4 ms 928 KB Output is correct
15 Correct 4 ms 928 KB Output is correct
16 Correct 6 ms 932 KB Output is correct
17 Correct 4 ms 932 KB Output is correct
18 Correct 3 ms 972 KB Output is correct
19 Correct 3 ms 972 KB Output is correct
20 Correct 4 ms 972 KB Output is correct
21 Correct 4 ms 972 KB Output is correct
22 Correct 5 ms 1052 KB Output is correct
23 Correct 4 ms 1052 KB Output is correct
24 Correct 4 ms 1052 KB Output is correct
25 Correct 4 ms 1052 KB Output is correct
26 Correct 3 ms 1276 KB Output is correct
27 Correct 4 ms 1276 KB Output is correct
28 Correct 3 ms 1276 KB Output is correct
29 Correct 3 ms 1276 KB Output is correct
30 Correct 4 ms 1276 KB Output is correct
31 Correct 2780 ms 12260 KB Output is correct
32 Correct 135 ms 12260 KB Output is correct
33 Correct 280 ms 14152 KB Output is correct
34 Correct 2345 ms 17232 KB Output is correct
35 Correct 1524 ms 21820 KB Output is correct
36 Correct 378 ms 24600 KB Output is correct
37 Correct 237 ms 25160 KB Output is correct
38 Correct 159 ms 27928 KB Output is correct
39 Correct 134 ms 30904 KB Output is correct
40 Correct 136 ms 33604 KB Output is correct
41 Correct 385 ms 36580 KB Output is correct
42 Correct 304 ms 39660 KB Output is correct
43 Correct 453 ms 44492 KB Output is correct
44 Correct 326 ms 44844 KB Output is correct
45 Correct 187 ms 47656 KB Output is correct
46 Correct 127 ms 50528 KB Output is correct
47 Correct 114 ms 53368 KB Output is correct
48 Correct 146 ms 56180 KB Output is correct
49 Correct 132 ms 58912 KB Output is correct
50 Correct 258 ms 61800 KB Output is correct
51 Correct 123 ms 64636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 485 ms 112812 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 453 ms 118444 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 2 ms 676 KB Output is correct
4 Correct 3 ms 676 KB Output is correct
5 Correct 3 ms 676 KB Output is correct
6 Correct 5 ms 676 KB Output is correct
7 Correct 4 ms 708 KB Output is correct
8 Correct 3 ms 708 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 4 ms 928 KB Output is correct
12 Correct 4 ms 928 KB Output is correct
13 Correct 4 ms 928 KB Output is correct
14 Correct 4 ms 928 KB Output is correct
15 Correct 4 ms 928 KB Output is correct
16 Correct 6 ms 932 KB Output is correct
17 Correct 4 ms 932 KB Output is correct
18 Correct 3 ms 972 KB Output is correct
19 Correct 3 ms 972 KB Output is correct
20 Correct 4 ms 972 KB Output is correct
21 Correct 4 ms 972 KB Output is correct
22 Correct 5 ms 1052 KB Output is correct
23 Correct 4 ms 1052 KB Output is correct
24 Correct 4 ms 1052 KB Output is correct
25 Correct 4 ms 1052 KB Output is correct
26 Correct 3 ms 1276 KB Output is correct
27 Correct 4 ms 1276 KB Output is correct
28 Correct 3 ms 1276 KB Output is correct
29 Correct 3 ms 1276 KB Output is correct
30 Correct 4 ms 1276 KB Output is correct
31 Correct 2780 ms 12260 KB Output is correct
32 Correct 135 ms 12260 KB Output is correct
33 Correct 280 ms 14152 KB Output is correct
34 Correct 2345 ms 17232 KB Output is correct
35 Correct 1524 ms 21820 KB Output is correct
36 Correct 378 ms 24600 KB Output is correct
37 Correct 237 ms 25160 KB Output is correct
38 Correct 159 ms 27928 KB Output is correct
39 Correct 134 ms 30904 KB Output is correct
40 Correct 136 ms 33604 KB Output is correct
41 Correct 385 ms 36580 KB Output is correct
42 Correct 304 ms 39660 KB Output is correct
43 Correct 453 ms 44492 KB Output is correct
44 Correct 326 ms 44844 KB Output is correct
45 Correct 187 ms 47656 KB Output is correct
46 Correct 127 ms 50528 KB Output is correct
47 Correct 114 ms 53368 KB Output is correct
48 Correct 146 ms 56180 KB Output is correct
49 Correct 132 ms 58912 KB Output is correct
50 Correct 258 ms 61800 KB Output is correct
51 Correct 123 ms 64636 KB Output is correct
52 Runtime error 135 ms 118444 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 2 ms 676 KB Output is correct
4 Correct 3 ms 676 KB Output is correct
5 Correct 3 ms 676 KB Output is correct
6 Correct 5 ms 676 KB Output is correct
7 Correct 4 ms 708 KB Output is correct
8 Correct 3 ms 708 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 4 ms 928 KB Output is correct
12 Correct 4 ms 928 KB Output is correct
13 Correct 4 ms 928 KB Output is correct
14 Correct 4 ms 928 KB Output is correct
15 Correct 4 ms 928 KB Output is correct
16 Correct 6 ms 932 KB Output is correct
17 Correct 4 ms 932 KB Output is correct
18 Correct 3 ms 972 KB Output is correct
19 Correct 3 ms 972 KB Output is correct
20 Correct 4 ms 972 KB Output is correct
21 Correct 4 ms 972 KB Output is correct
22 Correct 5 ms 1052 KB Output is correct
23 Correct 4 ms 1052 KB Output is correct
24 Correct 4 ms 1052 KB Output is correct
25 Correct 4 ms 1052 KB Output is correct
26 Correct 3 ms 1276 KB Output is correct
27 Correct 4 ms 1276 KB Output is correct
28 Correct 3 ms 1276 KB Output is correct
29 Correct 3 ms 1276 KB Output is correct
30 Correct 4 ms 1276 KB Output is correct
31 Correct 2780 ms 12260 KB Output is correct
32 Correct 135 ms 12260 KB Output is correct
33 Correct 280 ms 14152 KB Output is correct
34 Correct 2345 ms 17232 KB Output is correct
35 Correct 1524 ms 21820 KB Output is correct
36 Correct 378 ms 24600 KB Output is correct
37 Correct 237 ms 25160 KB Output is correct
38 Correct 159 ms 27928 KB Output is correct
39 Correct 134 ms 30904 KB Output is correct
40 Correct 136 ms 33604 KB Output is correct
41 Correct 385 ms 36580 KB Output is correct
42 Correct 304 ms 39660 KB Output is correct
43 Correct 453 ms 44492 KB Output is correct
44 Correct 326 ms 44844 KB Output is correct
45 Correct 187 ms 47656 KB Output is correct
46 Correct 127 ms 50528 KB Output is correct
47 Correct 114 ms 53368 KB Output is correct
48 Correct 146 ms 56180 KB Output is correct
49 Correct 132 ms 58912 KB Output is correct
50 Correct 258 ms 61800 KB Output is correct
51 Correct 123 ms 64636 KB Output is correct
52 Runtime error 485 ms 112812 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Halted 0 ms 0 KB -