// Why am I so stupid? :c
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int MAXN = 3e5+5;
const int INF = 1e9;
struct shop {
int x, tp, l, r;
shop() {
x = tp = l = r = 0;
}
} arr[MAXN];
struct que {
int x, t, id;
que() {
x = t = id = 0;
}
} req[MAXN];
vector < pair <int, int> > addEl[MAXN * 2];
vector < pair <int, int> > delEl[MAXN * 2];
multiset < pair <int, int> > ms;
vector <int> mm[MAXN];
int rl[MAXN * 2];
int ans[MAXN];
int mn[MAXN];
int n, k, q;
int m, m2;
void compressX() {
vector <int> vv;
for (int i = 1; i <= n; ++i) {
vv.pb(arr[i].x);
}
for (int i = 1; i <= q; ++i) {
vv.pb(req[i].x);
}
sort(all(vv));
vv.resize(unique(all(vv)) - vv.begin());
m2 = vv.size();
for (int i = 1, ps; i <= n; ++i) {
ps = upper_bound(all(vv), arr[i].x) - vv.begin();
rl[ps] = arr[i].x;
arr[i].x = ps;
}
for (int i = 1, ps; i <= q; ++i) {
ps = upper_bound(all(vv), req[i].x) - vv.begin();
rl[ps] = req[i].x;
req[i].x = ps;
}
}
bool cmp(que a, que b) {
return a.x < b.x;
}
bool cmp2(shop a, shop b) {
return a.x < b.x;
}
void solve() {
scanf("%d %d %d", &n, &k, &q);
for (int i = 1; i <= n; ++i) {
scanf("%d %d", &arr[i].x, &arr[i].tp);
scanf("%d %d", &arr[i].l, &arr[i].r);
}
for (int i = 1; i <= q; ++i) {
scanf("%d %d", &req[i].x, &req[i].t);
req[i].id = i;
}
compressX();
sort(arr + 1, arr + n + 1, cmp2);
sort(req + 1, req + q + 1, cmp);
for (int i = 1; i <= n; ++i) {
mm[arr[i].tp].pb(arr[i].x);
}
bool ex = 0;
for (int i = 1; i <= k; ++i) {
if (mm[i].empty()) {
ex = 1;
}
mm[i].resize(unique(all(mm[i])) - mm[i].begin());
}
if (ex) {
for (int i = 1; i <= q; ++i) {
printf("-1\n");
}
return;
}
for (int i = 1; i <= k; ++i) {
addEl[1].pb(mp(0, mm[i][0]));
delEl[mm[i][0] + 1].pb(mp(0, mm[i][0]));
for (int j = 0; j < mm[i].size(); ++j) {
int nxt = m2 + 1;
if (j + 1 < mm[i].size()) {
nxt = mm[i][j + 1];
}
addEl[mm[i][j]].pb(mp(mm[i][j], nxt));
delEl[nxt + 1].pb(mp(mm[i][j], nxt));
}
}
int ptr = 1;
for (int i = 1; i <= m2; ++i) {
for (auto it : addEl[i]) {
ms.insert(it);
}
for (auto it : delEl[i]) {
ms.erase(ms.find(it));
}
while (ptr <= q && req[ptr].x == i) {
for (auto it : ms) {
int curD = INF;
if (it.fi > 0) {
curD = min(curD, rl[i] - rl[it.fi]);
}
if (it.se <= m2) {
curD = min(curD, rl[it.se] - rl[i]);
}
ans[req[ptr].id] = max(ans[req[ptr].id], curD);
}
++ptr;
}
}
for (int i = 1; i <= q; ++i) {
if (ans[i] == INF) {
ans[i] = -1;
}
printf("%d\n", ans[i]);
}
}
int main() {
#ifdef BThero
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // BThero
int tt = 1;
while (tt--) {
solve();
}
return 0;
}
Compilation message
new_home.cpp: In function 'void solve()':
new_home.cpp:135:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < mm[i].size(); ++j) {
~~^~~~~~~~~~~~~~
new_home.cpp:138:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (j + 1 < mm[i].size()) {
~~~~~~^~~~~~~~~~~~~~
new_home.cpp:92: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:95:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &arr[i].x, &arr[i].tp);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:96:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &arr[i].l, &arr[i].r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:100:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &req[i].x, &req[i].t);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
43768 KB |
Output is correct |
2 |
Incorrect |
35 ms |
43768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
43768 KB |
Output is correct |
2 |
Incorrect |
35 ms |
43768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5021 ms |
72648 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5031 ms |
72648 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
43768 KB |
Output is correct |
2 |
Incorrect |
35 ms |
43768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
43768 KB |
Output is correct |
2 |
Incorrect |
35 ms |
43768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |