답안 #658993

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
658993 2022-11-15T17:56:03 Z 600Mihnea 새 집 (APIO18_new_home) C++17
0 / 100
5 ms 7308 KB
bool home = 1;

#include <bits/stdc++.h>

using namespace std;

struct Store {
  int x;
  int type;
  int first_time;
  int last_time;
};

struct Query {
  int x;
  int t;
};

const int N = (int) 3e5 + 7;
int n;
int k;
int q;
vector<int> whereType[N];
Store stores[N];
Query queries[N];

int main() {
  if (home) {
    freopen ("input.txt", "r", stdin);
  } else {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  }
  {
    /// Read
    cin >> n >> k >> q;
    for (int i = 1; i <= n; i++) {
      cin >> stores[i].x >> stores[i].type >> stores[i].first_time >> stores[i].last_time;
      whereType[stores[i].type].push_back(i);
    }
    for (int i = 1; i <= q; i++) {
      cin >> queries[i].x >> queries[i].t;
    }
  }
  {
    /// Normalize time
    vector<int> interestingTimes;
    for (int i = 1; i <= q; i++) {
      interestingTimes.push_back(queries[i].t);
    }
    sort(interestingTimes.begin(), interestingTimes.end());
    interestingTimes.resize(unique(interestingTimes.begin(), interestingTimes.end()) - interestingTimes.begin());
    for (int i = 1; i <= q; i++) {
      queries[i].t = lower_bound(interestingTimes.begin(), interestingTimes.end(), queries[i].t) - interestingTimes.begin();
    }
    for (int i = 1; i <= n; i++) {
      int L = stores[i].first_time, R = stores[i].last_time;
      stores[i].first_time = stores[i].last_time = 0;

      stores[i].first_time = (int) interestingTimes.size();
      for (int j = 0; j < (int) interestingTimes.size(); j++) {
        if (L <= interestingTimes[j]) {
          stores[i].first_time = j;
          break;
        }
      }

      assert(stores[i].first_time == lower_bound(interestingTimes.begin(), interestingTimes.end(), L) - interestingTimes.begin());

      stores[i].last_time = -1;
      for (int j = (int) interestingTimes.size() - 1; j >= 0; j--) {
        if (interestingTimes[j] <= R) {
          stores[i].last_time = j;
          break;
        }
      }
      assert(stores[i].last_time == lower_bound(interestingTimes.begin(), interestingTimes.end(), R + 1) - interestingTimes.begin() - 1);
    }
  }
  {
    /// Normalize positions

  }
  {
    /// Brute
    for (int iq = 1; iq <= q; iq++) {
      int maxDist = 0;
      for (int t = 1; t <= k; t++) {
        int minDist = (int) 1e9 + 7;
        for (auto &i : whereType[t]) {
          if (stores[i].first_time <= queries[iq].t && queries[iq].t <= stores[i].last_time) {
            minDist = min(minDist, abs(stores[i].x - queries[iq].x));
          }
        }
        maxDist = max(maxDist, minDist);
      }
      if (maxDist == (int) 1e9 + 7) {
        maxDist = -1;
      }
      cout << maxDist << "\n";
    }
  }
  return 0;
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:29:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen ("input.txt", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 7308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -