#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];
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, a, b;
cin >> x >> t >> a >> b;
qr[t].pb(x);
}
set <pair <int, int> > se; se.clear();
for (int i = 1; i <= k; i++) sort(qr[i].begin(), qr[i].end());
bool f = 1;
for (int i = 1; i <= k; i++)
{
if (sz(qr[i]) == 0) {f = 0; break;}
se.insert({qr[i][0], i});
int lst = qr[i][0];
for (int j = 1; j < sz(qr[i]); j++)
{
int mid = (lst + qr[i][j] + 1) / 2;
vr.pb({mid, i});
lst = qr[i][j];
}
}
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());
sort(vr.begin(), vr.end());
int 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;
se.erase({qr[tp][pos[tp]], tp});
pos[tp]++;
se.insert({qr[tp][pos[tp]], tp});
j++;
}
ans[nm] = max(abs((*se.begin()).F - x), abs((*se.rbegin()).F - x));
}
for (int i = 0; i < q; i++) cout << ans[i] << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
11 ms |
7424 KB |
Output is correct |
9 |
Correct |
10 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 |
12 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 |
12 ms |
7552 KB |
Output is correct |
16 |
Correct |
11 ms |
7424 KB |
Output is correct |
17 |
Correct |
12 ms |
7424 KB |
Output is correct |
18 |
Correct |
10 ms |
7424 KB |
Output is correct |
19 |
Correct |
12 ms |
7424 KB |
Output is correct |
20 |
Correct |
14 ms |
7424 KB |
Output is correct |
21 |
Correct |
11 ms |
7552 KB |
Output is correct |
22 |
Correct |
11 ms |
7424 KB |
Output is correct |
23 |
Correct |
11 ms |
7424 KB |
Output is correct |
24 |
Correct |
13 ms |
7472 KB |
Output is correct |
25 |
Correct |
10 ms |
7552 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
11 ms |
7424 KB |
Output is correct |
9 |
Correct |
10 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 |
12 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 |
12 ms |
7552 KB |
Output is correct |
16 |
Correct |
11 ms |
7424 KB |
Output is correct |
17 |
Correct |
12 ms |
7424 KB |
Output is correct |
18 |
Correct |
10 ms |
7424 KB |
Output is correct |
19 |
Correct |
12 ms |
7424 KB |
Output is correct |
20 |
Correct |
14 ms |
7424 KB |
Output is correct |
21 |
Correct |
11 ms |
7552 KB |
Output is correct |
22 |
Correct |
11 ms |
7424 KB |
Output is correct |
23 |
Correct |
11 ms |
7424 KB |
Output is correct |
24 |
Correct |
13 ms |
7472 KB |
Output is correct |
25 |
Correct |
10 ms |
7552 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 |
2766 ms |
20424 KB |
Output is correct |
32 |
Correct |
183 ms |
11368 KB |
Output is correct |
33 |
Correct |
374 ms |
18256 KB |
Output is correct |
34 |
Correct |
1999 ms |
18640 KB |
Output is correct |
35 |
Correct |
1324 ms |
20328 KB |
Output is correct |
36 |
Correct |
419 ms |
20200 KB |
Output is correct |
37 |
Correct |
370 ms |
17644 KB |
Output is correct |
38 |
Correct |
277 ms |
17384 KB |
Output is correct |
39 |
Correct |
251 ms |
17256 KB |
Output is correct |
40 |
Correct |
252 ms |
17260 KB |
Output is correct |
41 |
Correct |
487 ms |
17512 KB |
Output is correct |
42 |
Correct |
407 ms |
17568 KB |
Output is correct |
43 |
Correct |
265 ms |
13160 KB |
Output is correct |
44 |
Correct |
449 ms |
17504 KB |
Output is correct |
45 |
Correct |
296 ms |
17384 KB |
Output is correct |
46 |
Correct |
251 ms |
17384 KB |
Output is correct |
47 |
Correct |
226 ms |
16744 KB |
Output is correct |
48 |
Correct |
249 ms |
16744 KB |
Output is correct |
49 |
Correct |
245 ms |
17000 KB |
Output is correct |
50 |
Correct |
394 ms |
17128 KB |
Output is correct |
51 |
Correct |
237 ms |
17000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1156 ms |
35300 KB |
Output is correct |
2 |
Correct |
900 ms |
28964 KB |
Output is correct |
3 |
Correct |
1146 ms |
51220 KB |
Output is correct |
4 |
Correct |
1199 ms |
37396 KB |
Output is correct |
5 |
Correct |
895 ms |
28256 KB |
Output is correct |
6 |
Correct |
917 ms |
28684 KB |
Output is correct |
7 |
Correct |
1044 ms |
51172 KB |
Output is correct |
8 |
Correct |
1115 ms |
37348 KB |
Output is correct |
9 |
Correct |
1079 ms |
32952 KB |
Output is correct |
10 |
Correct |
957 ms |
30428 KB |
Output is correct |
11 |
Correct |
891 ms |
29092 KB |
Output is correct |
12 |
Correct |
923 ms |
30440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1014 ms |
30944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
11 ms |
7424 KB |
Output is correct |
9 |
Correct |
10 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 |
12 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 |
12 ms |
7552 KB |
Output is correct |
16 |
Correct |
11 ms |
7424 KB |
Output is correct |
17 |
Correct |
12 ms |
7424 KB |
Output is correct |
18 |
Correct |
10 ms |
7424 KB |
Output is correct |
19 |
Correct |
12 ms |
7424 KB |
Output is correct |
20 |
Correct |
14 ms |
7424 KB |
Output is correct |
21 |
Correct |
11 ms |
7552 KB |
Output is correct |
22 |
Correct |
11 ms |
7424 KB |
Output is correct |
23 |
Correct |
11 ms |
7424 KB |
Output is correct |
24 |
Correct |
13 ms |
7472 KB |
Output is correct |
25 |
Correct |
10 ms |
7552 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 |
2766 ms |
20424 KB |
Output is correct |
32 |
Correct |
183 ms |
11368 KB |
Output is correct |
33 |
Correct |
374 ms |
18256 KB |
Output is correct |
34 |
Correct |
1999 ms |
18640 KB |
Output is correct |
35 |
Correct |
1324 ms |
20328 KB |
Output is correct |
36 |
Correct |
419 ms |
20200 KB |
Output is correct |
37 |
Correct |
370 ms |
17644 KB |
Output is correct |
38 |
Correct |
277 ms |
17384 KB |
Output is correct |
39 |
Correct |
251 ms |
17256 KB |
Output is correct |
40 |
Correct |
252 ms |
17260 KB |
Output is correct |
41 |
Correct |
487 ms |
17512 KB |
Output is correct |
42 |
Correct |
407 ms |
17568 KB |
Output is correct |
43 |
Correct |
265 ms |
13160 KB |
Output is correct |
44 |
Correct |
449 ms |
17504 KB |
Output is correct |
45 |
Correct |
296 ms |
17384 KB |
Output is correct |
46 |
Correct |
251 ms |
17384 KB |
Output is correct |
47 |
Correct |
226 ms |
16744 KB |
Output is correct |
48 |
Correct |
249 ms |
16744 KB |
Output is correct |
49 |
Correct |
245 ms |
17000 KB |
Output is correct |
50 |
Correct |
394 ms |
17128 KB |
Output is correct |
51 |
Correct |
237 ms |
17000 KB |
Output is correct |
52 |
Runtime error |
87 ms |
23144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
53 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
11 ms |
7424 KB |
Output is correct |
9 |
Correct |
10 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 |
12 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 |
12 ms |
7552 KB |
Output is correct |
16 |
Correct |
11 ms |
7424 KB |
Output is correct |
17 |
Correct |
12 ms |
7424 KB |
Output is correct |
18 |
Correct |
10 ms |
7424 KB |
Output is correct |
19 |
Correct |
12 ms |
7424 KB |
Output is correct |
20 |
Correct |
14 ms |
7424 KB |
Output is correct |
21 |
Correct |
11 ms |
7552 KB |
Output is correct |
22 |
Correct |
11 ms |
7424 KB |
Output is correct |
23 |
Correct |
11 ms |
7424 KB |
Output is correct |
24 |
Correct |
13 ms |
7472 KB |
Output is correct |
25 |
Correct |
10 ms |
7552 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 |
2766 ms |
20424 KB |
Output is correct |
32 |
Correct |
183 ms |
11368 KB |
Output is correct |
33 |
Correct |
374 ms |
18256 KB |
Output is correct |
34 |
Correct |
1999 ms |
18640 KB |
Output is correct |
35 |
Correct |
1324 ms |
20328 KB |
Output is correct |
36 |
Correct |
419 ms |
20200 KB |
Output is correct |
37 |
Correct |
370 ms |
17644 KB |
Output is correct |
38 |
Correct |
277 ms |
17384 KB |
Output is correct |
39 |
Correct |
251 ms |
17256 KB |
Output is correct |
40 |
Correct |
252 ms |
17260 KB |
Output is correct |
41 |
Correct |
487 ms |
17512 KB |
Output is correct |
42 |
Correct |
407 ms |
17568 KB |
Output is correct |
43 |
Correct |
265 ms |
13160 KB |
Output is correct |
44 |
Correct |
449 ms |
17504 KB |
Output is correct |
45 |
Correct |
296 ms |
17384 KB |
Output is correct |
46 |
Correct |
251 ms |
17384 KB |
Output is correct |
47 |
Correct |
226 ms |
16744 KB |
Output is correct |
48 |
Correct |
249 ms |
16744 KB |
Output is correct |
49 |
Correct |
245 ms |
17000 KB |
Output is correct |
50 |
Correct |
394 ms |
17128 KB |
Output is correct |
51 |
Correct |
237 ms |
17000 KB |
Output is correct |
52 |
Correct |
1156 ms |
35300 KB |
Output is correct |
53 |
Correct |
900 ms |
28964 KB |
Output is correct |
54 |
Correct |
1146 ms |
51220 KB |
Output is correct |
55 |
Correct |
1199 ms |
37396 KB |
Output is correct |
56 |
Correct |
895 ms |
28256 KB |
Output is correct |
57 |
Correct |
917 ms |
28684 KB |
Output is correct |
58 |
Correct |
1044 ms |
51172 KB |
Output is correct |
59 |
Correct |
1115 ms |
37348 KB |
Output is correct |
60 |
Correct |
1079 ms |
32952 KB |
Output is correct |
61 |
Correct |
957 ms |
30428 KB |
Output is correct |
62 |
Correct |
891 ms |
29092 KB |
Output is correct |
63 |
Correct |
923 ms |
30440 KB |
Output is correct |
64 |
Incorrect |
1014 ms |
30944 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |