답안 #399827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
399827 2021-05-06T17:36:56 Z my99n 새 집 (APIO18_new_home) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
 
struct event {
  int et, x, t, y, i;
  bool operator < (const event & o) const {
    if (y == o.y) return et < o.et; // open query close
    return y < o.y;
  }
};
vector<event> e;
set<pair<int,int>> s[500];
int ans[100100];
 
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k, q; cin >> n >> k >> q;
  assert(k < 500);
  for (int i = 1; i <= n; i++) {
    int x, t, a, b; cin >> x >> t >> a >> b;
    e.push_back({1, x, t, a, i});
    e.push_back({3, x, t, b, i});
  }
  for (int i = 1; i <= q; i++) {
    int l, y; cin >> l >> y;
    e.push_back({2, l, 0, y, i});
  }
  sort(e.begin(), e.end());
  for (auto [et, x, t, y, i] : e) {
    if (et == 1) s[t].insert({x, i});
    if (et == 3) s[t].erase({x, i});
    if (et == 2) {
      for (int type = 1; type <= k; type++) {
        if (s[type].empty()) {
          ans[i] = -1;
          break;
        }
        int mn = 1e9;

        for (auto a = s[type].begin(); a != s[type].end(); a++) {
          mn = min(mn, abs(x - a->first));
        }
        auto lb = s[type].lower_bound({x, -1});
        assert(mn < abs(x - (lb->first))
        // mn = min(mn, abs(x-(a->first)));
        // if (a != s[type].end()) mn = min(mn, abs(x-(next(a)->first)));
        // if (a != s[type].begin()) mn = min(mn, abs(x-(prev(a)->first)));

        ans[i] = max(ans[i], mn);
      }
    }
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << endl;
  return 0;
}
/*
4 2 4
3 1 1 10
9 2 2 4
7 2 5 7 
4 1 8 10
5 3
5 6 
5 9
1 10
*/

Compilation message

new_home.cpp:67: error: unterminated argument list invoking macro "assert"
   67 | */
      | 
new_home.cpp: In function 'int main()':
new_home.cpp:30:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   30 |   for (auto [et, x, t, y, i] : e) {
      |             ^
new_home.cpp:45:9: error: 'assert' was not declared in this scope
   45 |         assert(mn < abs(x - (lb->first))
      |         ^~~~~~
new_home.cpp:2:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
    1 | #include<bits/stdc++.h>
  +++ |+#include <cassert>
    2 | using namespace std;
new_home.cpp:45:9: error: expected '}' at end of input
   45 |         assert(mn < abs(x - (lb->first))
      |         ^~~~~~
new_home.cpp:34:45: note: to match this '{'
   34 |       for (int type = 1; type <= k; type++) {
      |                                             ^
new_home.cpp:45:9: error: expected '}' at end of input
   45 |         assert(mn < abs(x - (lb->first))
      |         ^~~~~~
new_home.cpp:33:18: note: to match this '{'
   33 |     if (et == 2) {
      |                  ^
new_home.cpp:45:9: error: expected '}' at end of input
   45 |         assert(mn < abs(x - (lb->first))
      |         ^~~~~~
new_home.cpp:30:35: note: to match this '{'
   30 |   for (auto [et, x, t, y, i] : e) {
      |                                   ^
new_home.cpp:45:9: error: expected '}' at end of input
   45 |         assert(mn < abs(x - (lb->first))
      |         ^~~~~~
new_home.cpp:15:11: note: to match this '{'
   15 | int main(){
      |           ^