#include <bits/stdc++.h>
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 300005
#define M ll(998244353)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef short int si;
vector <pair <pair <pair <int, int>, int>, int> > sost;
set <int> se[410];
map <pair <int, int>, int > mp;
vector <pair <int, int> > vr;
vector <int> qr[N];
pair <int, int> dist[N];
int pos[N];
int main()
{
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, k, q;
cin >> n >> k >> q;
if (n <= 60000)
{
for (int i = 0; i < n; i++)
{
int x, t, l, r;
cin >> x >> t >> l >> r;
sost.pb({{{l, x}, t}, i});
sost.pb({{{r + 1, x}, -t}, i});
}
vector <pair <pair <int, int>, int> > gr; gr.resize(q);
for (int i = 0; i < q; i++) {cin >> gr[i].F.S >> gr[i].F.F; gr[i].S = i;}
sort(sost.begin(), sost.end());
sort(gr.begin(), gr.end());
int ans[q];
int j = 0;
for (auto it : gr)
{
int nm = it.S, x = it.F.S, tr = it.F.F;
while (j < n + n && sost[j].F.F.F <= tr)
{
int tp = abs(sost[j].F.S);
if (sost[j].F.S > 0) {mp[{tp, sost[j].F.F.S}]++; if (mp[{tp, sost[j].F.F.S}] == 1) se[tp].insert(sost[j].F.F.S);}
else {mp[{tp, sost[j].F.F.S}]--; if (mp[{tp, sost[j].F.F.S}] == 0) se[tp].erase(sost[j].F.F.S);}
j++;
}
bool f = 1;
int mx = 0;
for (int i = 1; i <= k; i++)
{
if (sz(se[i]) == 0) {f = 0; break;}
auto it = se[i].lower_bound(x);
int mn = 1e9;
if (it != se[i].end()) mn = min(mn, abs(*it - x));
if (it != se[i].begin()) {it--; mn = min(mn, abs(*it - x)); }
mx = max(mx, mn);
}
if (!f) ans[nm] = -1; else ans[nm] = mx;
}
for (int i = 0; i < q; i++) cout << ans[i] << endl;
}
else
{
for (int i = 0; i < n; i++)
{
int x, t;
cin >> x >> t;
vr.pb({x, t});
qr[t].pb(x);
}
set <pair <int, int> > sel, ser; sel.clear(); ser.clear();
for (int i = 1; i <= k; i++) sort(qr[i].begin(), qr[i].end());
sort(vr.begin(), vr.end());
bool f = 1;
for (int i = 1; i <= k; i++)
{
if (sz(qr[i]) == 0) {f = 0; break;}
dist[i] = {-1, qr[i][0]};
ser.insert({qr[i][0], i});
}
if (!f) {for (int i = 0; i < q; i++) cout << -1 << endl; exit(0);}
vector <pair <int, int> > v; v.resize(q);
for (int i = 0; i < q; i++) {cin >> v[i].F >> v[i].S; v[i].S = i;}
sort(v.begin(), v.end());
int lst = 0, ans[q], j = 0;
for (auto it : v)
{
int nm = it.S, x = it.F;
while (j < sz(vr) && vr[j].F <= x)
{
int tp = vr[j].S, xr = vr[j].F;
if (dist[tp].F != -1) sel.erase({qr[tp][pos[tp] - 1], tp});
ser.erase({qr[tp][pos[tp]], tp});
sel.insert({qr[tp][pos[tp]], tp});
dist[tp].F = qr[tp][pos[tp]];
pos[tp]++;
if (pos[tp] != sz(qr[tp])) ser.insert({qr[tp][pos[tp]], tp});
j++;
}
int mx = 0;
if (sz(sel) != 0) mx = max(mx, x - (*sel.begin()).F);
if (sz(ser) != 0) mx = max(mx, (*ser.rbegin()).F - x);
ans[nm] = mx;
}
for (int i = 0; i < q; i++) cout << ans[i] << endl;
}
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:148:35: warning: unused variable 'xr' [-Wunused-variable]
int tp = vr[j].S, xr = vr[j].F;
^~
new_home.cpp:140:13: warning: unused variable 'lst' [-Wunused-variable]
int lst = 0, ans[q], j = 0;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7424 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
10 ms |
7424 KB |
Output is correct |
6 |
Correct |
10 ms |
7424 KB |
Output is correct |
7 |
Correct |
10 ms |
7424 KB |
Output is correct |
8 |
Correct |
10 ms |
7424 KB |
Output is correct |
9 |
Correct |
11 ms |
7552 KB |
Output is correct |
10 |
Correct |
10 ms |
7424 KB |
Output is correct |
11 |
Correct |
10 ms |
7424 KB |
Output is correct |
12 |
Correct |
10 ms |
7424 KB |
Output is correct |
13 |
Correct |
10 ms |
7424 KB |
Output is correct |
14 |
Correct |
10 ms |
7424 KB |
Output is correct |
15 |
Correct |
10 ms |
7424 KB |
Output is correct |
16 |
Correct |
10 ms |
7424 KB |
Output is correct |
17 |
Correct |
11 ms |
7424 KB |
Output is correct |
18 |
Correct |
10 ms |
7424 KB |
Output is correct |
19 |
Correct |
10 ms |
7424 KB |
Output is correct |
20 |
Correct |
10 ms |
7424 KB |
Output is correct |
21 |
Correct |
10 ms |
7424 KB |
Output is correct |
22 |
Correct |
10 ms |
7552 KB |
Output is correct |
23 |
Correct |
12 ms |
7424 KB |
Output is correct |
24 |
Correct |
10 ms |
7424 KB |
Output is correct |
25 |
Correct |
12 ms |
7424 KB |
Output is correct |
26 |
Correct |
10 ms |
7424 KB |
Output is correct |
27 |
Correct |
10 ms |
7424 KB |
Output is correct |
28 |
Correct |
10 ms |
7424 KB |
Output is correct |
29 |
Correct |
10 ms |
7424 KB |
Output is correct |
30 |
Correct |
10 ms |
7424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7424 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
10 ms |
7424 KB |
Output is correct |
6 |
Correct |
10 ms |
7424 KB |
Output is correct |
7 |
Correct |
10 ms |
7424 KB |
Output is correct |
8 |
Correct |
10 ms |
7424 KB |
Output is correct |
9 |
Correct |
11 ms |
7552 KB |
Output is correct |
10 |
Correct |
10 ms |
7424 KB |
Output is correct |
11 |
Correct |
10 ms |
7424 KB |
Output is correct |
12 |
Correct |
10 ms |
7424 KB |
Output is correct |
13 |
Correct |
10 ms |
7424 KB |
Output is correct |
14 |
Correct |
10 ms |
7424 KB |
Output is correct |
15 |
Correct |
10 ms |
7424 KB |
Output is correct |
16 |
Correct |
10 ms |
7424 KB |
Output is correct |
17 |
Correct |
11 ms |
7424 KB |
Output is correct |
18 |
Correct |
10 ms |
7424 KB |
Output is correct |
19 |
Correct |
10 ms |
7424 KB |
Output is correct |
20 |
Correct |
10 ms |
7424 KB |
Output is correct |
21 |
Correct |
10 ms |
7424 KB |
Output is correct |
22 |
Correct |
10 ms |
7552 KB |
Output is correct |
23 |
Correct |
12 ms |
7424 KB |
Output is correct |
24 |
Correct |
10 ms |
7424 KB |
Output is correct |
25 |
Correct |
12 ms |
7424 KB |
Output is correct |
26 |
Correct |
10 ms |
7424 KB |
Output is correct |
27 |
Correct |
10 ms |
7424 KB |
Output is correct |
28 |
Correct |
10 ms |
7424 KB |
Output is correct |
29 |
Correct |
10 ms |
7424 KB |
Output is correct |
30 |
Correct |
10 ms |
7424 KB |
Output is correct |
31 |
Correct |
2831 ms |
17488 KB |
Output is correct |
32 |
Correct |
184 ms |
10344 KB |
Output is correct |
33 |
Correct |
388 ms |
15464 KB |
Output is correct |
34 |
Correct |
2027 ms |
15540 KB |
Output is correct |
35 |
Correct |
1357 ms |
17384 KB |
Output is correct |
36 |
Correct |
437 ms |
17128 KB |
Output is correct |
37 |
Correct |
384 ms |
14620 KB |
Output is correct |
38 |
Correct |
272 ms |
14572 KB |
Output is correct |
39 |
Correct |
250 ms |
14440 KB |
Output is correct |
40 |
Correct |
252 ms |
14312 KB |
Output is correct |
41 |
Correct |
467 ms |
14568 KB |
Output is correct |
42 |
Correct |
403 ms |
14440 KB |
Output is correct |
43 |
Correct |
260 ms |
10856 KB |
Output is correct |
44 |
Correct |
427 ms |
14704 KB |
Output is correct |
45 |
Correct |
287 ms |
14568 KB |
Output is correct |
46 |
Correct |
252 ms |
14696 KB |
Output is correct |
47 |
Correct |
244 ms |
14056 KB |
Output is correct |
48 |
Correct |
214 ms |
14060 KB |
Output is correct |
49 |
Correct |
239 ms |
14332 KB |
Output is correct |
50 |
Correct |
404 ms |
14312 KB |
Output is correct |
51 |
Correct |
237 ms |
14312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
17 ms |
14720 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
25 ms |
14848 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7424 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
10 ms |
7424 KB |
Output is correct |
6 |
Correct |
10 ms |
7424 KB |
Output is correct |
7 |
Correct |
10 ms |
7424 KB |
Output is correct |
8 |
Correct |
10 ms |
7424 KB |
Output is correct |
9 |
Correct |
11 ms |
7552 KB |
Output is correct |
10 |
Correct |
10 ms |
7424 KB |
Output is correct |
11 |
Correct |
10 ms |
7424 KB |
Output is correct |
12 |
Correct |
10 ms |
7424 KB |
Output is correct |
13 |
Correct |
10 ms |
7424 KB |
Output is correct |
14 |
Correct |
10 ms |
7424 KB |
Output is correct |
15 |
Correct |
10 ms |
7424 KB |
Output is correct |
16 |
Correct |
10 ms |
7424 KB |
Output is correct |
17 |
Correct |
11 ms |
7424 KB |
Output is correct |
18 |
Correct |
10 ms |
7424 KB |
Output is correct |
19 |
Correct |
10 ms |
7424 KB |
Output is correct |
20 |
Correct |
10 ms |
7424 KB |
Output is correct |
21 |
Correct |
10 ms |
7424 KB |
Output is correct |
22 |
Correct |
10 ms |
7552 KB |
Output is correct |
23 |
Correct |
12 ms |
7424 KB |
Output is correct |
24 |
Correct |
10 ms |
7424 KB |
Output is correct |
25 |
Correct |
12 ms |
7424 KB |
Output is correct |
26 |
Correct |
10 ms |
7424 KB |
Output is correct |
27 |
Correct |
10 ms |
7424 KB |
Output is correct |
28 |
Correct |
10 ms |
7424 KB |
Output is correct |
29 |
Correct |
10 ms |
7424 KB |
Output is correct |
30 |
Correct |
10 ms |
7424 KB |
Output is correct |
31 |
Correct |
2831 ms |
17488 KB |
Output is correct |
32 |
Correct |
184 ms |
10344 KB |
Output is correct |
33 |
Correct |
388 ms |
15464 KB |
Output is correct |
34 |
Correct |
2027 ms |
15540 KB |
Output is correct |
35 |
Correct |
1357 ms |
17384 KB |
Output is correct |
36 |
Correct |
437 ms |
17128 KB |
Output is correct |
37 |
Correct |
384 ms |
14620 KB |
Output is correct |
38 |
Correct |
272 ms |
14572 KB |
Output is correct |
39 |
Correct |
250 ms |
14440 KB |
Output is correct |
40 |
Correct |
252 ms |
14312 KB |
Output is correct |
41 |
Correct |
467 ms |
14568 KB |
Output is correct |
42 |
Correct |
403 ms |
14440 KB |
Output is correct |
43 |
Correct |
260 ms |
10856 KB |
Output is correct |
44 |
Correct |
427 ms |
14704 KB |
Output is correct |
45 |
Correct |
287 ms |
14568 KB |
Output is correct |
46 |
Correct |
252 ms |
14696 KB |
Output is correct |
47 |
Correct |
244 ms |
14056 KB |
Output is correct |
48 |
Correct |
214 ms |
14060 KB |
Output is correct |
49 |
Correct |
239 ms |
14332 KB |
Output is correct |
50 |
Correct |
404 ms |
14312 KB |
Output is correct |
51 |
Correct |
237 ms |
14312 KB |
Output is correct |
52 |
Runtime error |
88 ms |
20072 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7424 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
10 ms |
7424 KB |
Output is correct |
6 |
Correct |
10 ms |
7424 KB |
Output is correct |
7 |
Correct |
10 ms |
7424 KB |
Output is correct |
8 |
Correct |
10 ms |
7424 KB |
Output is correct |
9 |
Correct |
11 ms |
7552 KB |
Output is correct |
10 |
Correct |
10 ms |
7424 KB |
Output is correct |
11 |
Correct |
10 ms |
7424 KB |
Output is correct |
12 |
Correct |
10 ms |
7424 KB |
Output is correct |
13 |
Correct |
10 ms |
7424 KB |
Output is correct |
14 |
Correct |
10 ms |
7424 KB |
Output is correct |
15 |
Correct |
10 ms |
7424 KB |
Output is correct |
16 |
Correct |
10 ms |
7424 KB |
Output is correct |
17 |
Correct |
11 ms |
7424 KB |
Output is correct |
18 |
Correct |
10 ms |
7424 KB |
Output is correct |
19 |
Correct |
10 ms |
7424 KB |
Output is correct |
20 |
Correct |
10 ms |
7424 KB |
Output is correct |
21 |
Correct |
10 ms |
7424 KB |
Output is correct |
22 |
Correct |
10 ms |
7552 KB |
Output is correct |
23 |
Correct |
12 ms |
7424 KB |
Output is correct |
24 |
Correct |
10 ms |
7424 KB |
Output is correct |
25 |
Correct |
12 ms |
7424 KB |
Output is correct |
26 |
Correct |
10 ms |
7424 KB |
Output is correct |
27 |
Correct |
10 ms |
7424 KB |
Output is correct |
28 |
Correct |
10 ms |
7424 KB |
Output is correct |
29 |
Correct |
10 ms |
7424 KB |
Output is correct |
30 |
Correct |
10 ms |
7424 KB |
Output is correct |
31 |
Correct |
2831 ms |
17488 KB |
Output is correct |
32 |
Correct |
184 ms |
10344 KB |
Output is correct |
33 |
Correct |
388 ms |
15464 KB |
Output is correct |
34 |
Correct |
2027 ms |
15540 KB |
Output is correct |
35 |
Correct |
1357 ms |
17384 KB |
Output is correct |
36 |
Correct |
437 ms |
17128 KB |
Output is correct |
37 |
Correct |
384 ms |
14620 KB |
Output is correct |
38 |
Correct |
272 ms |
14572 KB |
Output is correct |
39 |
Correct |
250 ms |
14440 KB |
Output is correct |
40 |
Correct |
252 ms |
14312 KB |
Output is correct |
41 |
Correct |
467 ms |
14568 KB |
Output is correct |
42 |
Correct |
403 ms |
14440 KB |
Output is correct |
43 |
Correct |
260 ms |
10856 KB |
Output is correct |
44 |
Correct |
427 ms |
14704 KB |
Output is correct |
45 |
Correct |
287 ms |
14568 KB |
Output is correct |
46 |
Correct |
252 ms |
14696 KB |
Output is correct |
47 |
Correct |
244 ms |
14056 KB |
Output is correct |
48 |
Correct |
214 ms |
14060 KB |
Output is correct |
49 |
Correct |
239 ms |
14332 KB |
Output is correct |
50 |
Correct |
404 ms |
14312 KB |
Output is correct |
51 |
Correct |
237 ms |
14312 KB |
Output is correct |
52 |
Runtime error |
17 ms |
14720 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
53 |
Halted |
0 ms |
0 KB |
- |