제출 #48845

#제출 시각아이디문제언어결과실행 시간메모리
48845model_code새 집 (APIO18_new_home)C++17
12 / 100
5089 ms30976 KiB
#include <bits/stdc++.h> using namespace std; const int INF = (int)1.01e9; void print(vector<int> v) { for (int x : v) printf("%d\n", x); } struct Shop { int x, type, a, b; }; struct Query { int x, time; }; vector<int> slow(vector<Shop> a, int k, vector<Query> b) { int n = a.size(), m = b.size(); vector<int> ans(m); struct Event { int time, type, id; bool operator< (const Event &ev) const { return make_pair(time, -type) < make_pair(ev.time, -ev.type); } }; vector<Event> events; for (int i = 0; i < (int)a.size(); i++) { events.push_back({ a[i].a, +1, i }); events.push_back({ a[i].b, -1, i }); } for (int i = 0; i < (int)b.size(); i++) { events.push_back({ b[i].time, 0, i }); } sort(events.begin(), events.end()); vector<vector<int>> vct(k); int empty = k; for (auto ev : events) { if (ev.type == +1) { int tp = a[ev.id].type; int id = lower_bound(vct[tp].begin(), vct[tp].end(), a[ev.id].x) - vct[tp].begin(); empty -= vct[tp].size() == 0; vct[tp].insert(vct[tp].begin() + id, a[ev.id].x); } if (ev.type == 0) { int cur = 0; if (empty) cur = INF; for (int i = 0; i < k; i++) { int id = lower_bound(vct[i].begin(), vct[i].end(), b[ev.id].x) - vct[i].begin(); int ccur = INF; if (id < (int)vct[i].size()) ccur = min(ccur, abs(b[ev.id].x - vct[i][id])); if (id > 0) ccur = min(ccur, abs(b[ev.id].x - vct[i][id - 1])); cur = max(cur, ccur); if (cur >= INF / 2) break; } if (cur >= INF / 2) cur = -1; ans[ev.id] = cur; } if (ev.type == -1) { int tp = a[ev.id].type; int id = lower_bound(vct[tp].begin(), vct[tp].end(), a[ev.id].x) - vct[tp].begin(); vct[tp].erase(vct[tp].begin() + id); empty += vct[tp].size() == 0; } } return ans; } int main() { int n, k, q; scanf("%d%d%d", &n, &k, &q); vector<Shop> a(n); for (int i = 0; i < n; i++) { scanf("%d%d%d%d", &a[i].x, &a[i].type, &a[i].a, &a[i].b); a[i].type--; } vector<Query> b(q); for (int i = 0; i < q; i++) scanf("%d%d", &b[i].x, &b[i].time); print(slow(a, k, b)); }

컴파일 시 표준 에러 (stderr) 메시지

new_home.cpp: In function 'std::vector<int> slow(std::vector<Shop>, int, std::vector<Query>)':
new_home.cpp:18:9: warning: unused variable 'n' [-Wunused-variable]
     int n = a.size(), m = b.size();
         ^
new_home.cpp: In function 'int main()':
new_home.cpp:70:10: 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:73:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d", &a[i].x, &a[i].type, &a[i].a, &a[i].b);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:77:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 0; i < q; i++) scanf("%d%d", &b[i].x, &b[i].time);
                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...