#include <bits/stdc++.h>
using namespace std;
const int N = 300005, M = 60004;
int n, q, k;
int ans[N];
struct ban0
{
int x;
int u;
int t;
int i;
ban0(){}
ban0(int x, int u, int t, int i)
{
this->x = x;
this->u = u;
this->t = t;
this->i = i;
}
};
bool operator<(const ban0& a, const ban0& b)
{
if (a.u < b.u)
return true;
if (a.u > b.u)
return false;
if (a.t == 0)
return false;
if (b.t == 0)
return true;
return false;
}
void solv0()
{
vector<ban0> v;
for (int i = 1; i <= n; ++i)
{
int x, t, l, r;
cin >> x >> t >> l >> r;
v.push_back(ban0(x, l, t, i));
v.push_back(ban0(x, r + 1, -t, i));
}
for (int i = 1; i <= q; ++i)
{
int x, u;
cin >> x >> u;
v.push_back(ban0(x, u, 0, i));
}
sort(v.begin(), v.end());
multiset<int> s[M];
for (int ii = 0; ii < v.size(); ++ii)
{
int x = v[ii].x;
int t = v[ii].t;
if (t > 0)
{
s[t].insert(x);
}
else if (t < 0)
{
s[-t].erase(s[-t].find(x));
}
else
{
bool z = false;
int maxu = 0;
for (int i = 1; i <= k; ++i)
{
if (s[i].empty())
{
z = true;
break;
}
multiset<int>::iterator it = s[i].lower_bound(x);
int minu = 1000000000;
if (it != s[i].end())
minu = abs(*it - x);
--it;
if (it != s[i].end())
minu = min(minu, abs(*it - x));
maxu = max(maxu, minu);
}
if (z)
ans[v[ii].i] = -1;
else
ans[v[ii].i] = maxu;
}
}
for (int i = 1; i <= q; ++i)
cout << ans[i] << endl;
}
int main()
{
//freopen("input.txt", "r", stdin);
cin >> n >> k >> q;
//if (n <= 60000 && k <= 400)
solv0();
return 0;
}
Compilation message
new_home.cpp: In function 'void solv0()':
new_home.cpp:55:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int ii = 0; ii < v.size(); ++ii)
~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3328 KB |
Output is correct |
2 |
Correct |
4 ms |
3200 KB |
Output is correct |
3 |
Correct |
4 ms |
3072 KB |
Output is correct |
4 |
Correct |
5 ms |
3072 KB |
Output is correct |
5 |
Correct |
7 ms |
3200 KB |
Output is correct |
6 |
Correct |
9 ms |
3200 KB |
Output is correct |
7 |
Correct |
6 ms |
3200 KB |
Output is correct |
8 |
Correct |
6 ms |
3200 KB |
Output is correct |
9 |
Correct |
6 ms |
3200 KB |
Output is correct |
10 |
Correct |
7 ms |
3200 KB |
Output is correct |
11 |
Correct |
6 ms |
3200 KB |
Output is correct |
12 |
Correct |
7 ms |
3200 KB |
Output is correct |
13 |
Correct |
6 ms |
3200 KB |
Output is correct |
14 |
Correct |
8 ms |
3200 KB |
Output is correct |
15 |
Correct |
7 ms |
3200 KB |
Output is correct |
16 |
Correct |
7 ms |
3200 KB |
Output is correct |
17 |
Correct |
6 ms |
3200 KB |
Output is correct |
18 |
Correct |
8 ms |
3200 KB |
Output is correct |
19 |
Correct |
9 ms |
3200 KB |
Output is correct |
20 |
Correct |
8 ms |
3200 KB |
Output is correct |
21 |
Correct |
8 ms |
3200 KB |
Output is correct |
22 |
Correct |
9 ms |
3200 KB |
Output is correct |
23 |
Correct |
7 ms |
3200 KB |
Output is correct |
24 |
Correct |
9 ms |
3200 KB |
Output is correct |
25 |
Correct |
6 ms |
3200 KB |
Output is correct |
26 |
Correct |
6 ms |
3200 KB |
Output is correct |
27 |
Correct |
6 ms |
3200 KB |
Output is correct |
28 |
Correct |
6 ms |
3200 KB |
Output is correct |
29 |
Correct |
6 ms |
3200 KB |
Output is correct |
30 |
Correct |
6 ms |
3200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3328 KB |
Output is correct |
2 |
Correct |
4 ms |
3200 KB |
Output is correct |
3 |
Correct |
4 ms |
3072 KB |
Output is correct |
4 |
Correct |
5 ms |
3072 KB |
Output is correct |
5 |
Correct |
7 ms |
3200 KB |
Output is correct |
6 |
Correct |
9 ms |
3200 KB |
Output is correct |
7 |
Correct |
6 ms |
3200 KB |
Output is correct |
8 |
Correct |
6 ms |
3200 KB |
Output is correct |
9 |
Correct |
6 ms |
3200 KB |
Output is correct |
10 |
Correct |
7 ms |
3200 KB |
Output is correct |
11 |
Correct |
6 ms |
3200 KB |
Output is correct |
12 |
Correct |
7 ms |
3200 KB |
Output is correct |
13 |
Correct |
6 ms |
3200 KB |
Output is correct |
14 |
Correct |
8 ms |
3200 KB |
Output is correct |
15 |
Correct |
7 ms |
3200 KB |
Output is correct |
16 |
Correct |
7 ms |
3200 KB |
Output is correct |
17 |
Correct |
6 ms |
3200 KB |
Output is correct |
18 |
Correct |
8 ms |
3200 KB |
Output is correct |
19 |
Correct |
9 ms |
3200 KB |
Output is correct |
20 |
Correct |
8 ms |
3200 KB |
Output is correct |
21 |
Correct |
8 ms |
3200 KB |
Output is correct |
22 |
Correct |
9 ms |
3200 KB |
Output is correct |
23 |
Correct |
7 ms |
3200 KB |
Output is correct |
24 |
Correct |
9 ms |
3200 KB |
Output is correct |
25 |
Correct |
6 ms |
3200 KB |
Output is correct |
26 |
Correct |
6 ms |
3200 KB |
Output is correct |
27 |
Correct |
6 ms |
3200 KB |
Output is correct |
28 |
Correct |
6 ms |
3200 KB |
Output is correct |
29 |
Correct |
6 ms |
3200 KB |
Output is correct |
30 |
Correct |
6 ms |
3200 KB |
Output is correct |
31 |
Correct |
2983 ms |
9596 KB |
Output is correct |
32 |
Correct |
233 ms |
7520 KB |
Output is correct |
33 |
Correct |
399 ms |
7644 KB |
Output is correct |
34 |
Correct |
2323 ms |
7708 KB |
Output is correct |
35 |
Correct |
1598 ms |
9504 KB |
Output is correct |
36 |
Correct |
456 ms |
9440 KB |
Output is correct |
37 |
Correct |
359 ms |
6900 KB |
Output is correct |
38 |
Correct |
314 ms |
6924 KB |
Output is correct |
39 |
Correct |
303 ms |
6772 KB |
Output is correct |
40 |
Correct |
292 ms |
6704 KB |
Output is correct |
41 |
Correct |
442 ms |
7000 KB |
Output is correct |
42 |
Correct |
378 ms |
6720 KB |
Output is correct |
43 |
Correct |
730 ms |
9692 KB |
Output is correct |
44 |
Correct |
442 ms |
7052 KB |
Output is correct |
45 |
Correct |
383 ms |
6920 KB |
Output is correct |
46 |
Correct |
263 ms |
6960 KB |
Output is correct |
47 |
Correct |
251 ms |
6600 KB |
Output is correct |
48 |
Correct |
271 ms |
6620 KB |
Output is correct |
49 |
Correct |
259 ms |
6748 KB |
Output is correct |
50 |
Correct |
398 ms |
6832 KB |
Output is correct |
51 |
Correct |
244 ms |
6760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5076 ms |
32440 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5076 ms |
32588 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3328 KB |
Output is correct |
2 |
Correct |
4 ms |
3200 KB |
Output is correct |
3 |
Correct |
4 ms |
3072 KB |
Output is correct |
4 |
Correct |
5 ms |
3072 KB |
Output is correct |
5 |
Correct |
7 ms |
3200 KB |
Output is correct |
6 |
Correct |
9 ms |
3200 KB |
Output is correct |
7 |
Correct |
6 ms |
3200 KB |
Output is correct |
8 |
Correct |
6 ms |
3200 KB |
Output is correct |
9 |
Correct |
6 ms |
3200 KB |
Output is correct |
10 |
Correct |
7 ms |
3200 KB |
Output is correct |
11 |
Correct |
6 ms |
3200 KB |
Output is correct |
12 |
Correct |
7 ms |
3200 KB |
Output is correct |
13 |
Correct |
6 ms |
3200 KB |
Output is correct |
14 |
Correct |
8 ms |
3200 KB |
Output is correct |
15 |
Correct |
7 ms |
3200 KB |
Output is correct |
16 |
Correct |
7 ms |
3200 KB |
Output is correct |
17 |
Correct |
6 ms |
3200 KB |
Output is correct |
18 |
Correct |
8 ms |
3200 KB |
Output is correct |
19 |
Correct |
9 ms |
3200 KB |
Output is correct |
20 |
Correct |
8 ms |
3200 KB |
Output is correct |
21 |
Correct |
8 ms |
3200 KB |
Output is correct |
22 |
Correct |
9 ms |
3200 KB |
Output is correct |
23 |
Correct |
7 ms |
3200 KB |
Output is correct |
24 |
Correct |
9 ms |
3200 KB |
Output is correct |
25 |
Correct |
6 ms |
3200 KB |
Output is correct |
26 |
Correct |
6 ms |
3200 KB |
Output is correct |
27 |
Correct |
6 ms |
3200 KB |
Output is correct |
28 |
Correct |
6 ms |
3200 KB |
Output is correct |
29 |
Correct |
6 ms |
3200 KB |
Output is correct |
30 |
Correct |
6 ms |
3200 KB |
Output is correct |
31 |
Correct |
2983 ms |
9596 KB |
Output is correct |
32 |
Correct |
233 ms |
7520 KB |
Output is correct |
33 |
Correct |
399 ms |
7644 KB |
Output is correct |
34 |
Correct |
2323 ms |
7708 KB |
Output is correct |
35 |
Correct |
1598 ms |
9504 KB |
Output is correct |
36 |
Correct |
456 ms |
9440 KB |
Output is correct |
37 |
Correct |
359 ms |
6900 KB |
Output is correct |
38 |
Correct |
314 ms |
6924 KB |
Output is correct |
39 |
Correct |
303 ms |
6772 KB |
Output is correct |
40 |
Correct |
292 ms |
6704 KB |
Output is correct |
41 |
Correct |
442 ms |
7000 KB |
Output is correct |
42 |
Correct |
378 ms |
6720 KB |
Output is correct |
43 |
Correct |
730 ms |
9692 KB |
Output is correct |
44 |
Correct |
442 ms |
7052 KB |
Output is correct |
45 |
Correct |
383 ms |
6920 KB |
Output is correct |
46 |
Correct |
263 ms |
6960 KB |
Output is correct |
47 |
Correct |
251 ms |
6600 KB |
Output is correct |
48 |
Correct |
271 ms |
6620 KB |
Output is correct |
49 |
Correct |
259 ms |
6748 KB |
Output is correct |
50 |
Correct |
398 ms |
6832 KB |
Output is correct |
51 |
Correct |
244 ms |
6760 KB |
Output is correct |
52 |
Correct |
293 ms |
9236 KB |
Output is correct |
53 |
Correct |
268 ms |
7576 KB |
Output is correct |
54 |
Correct |
350 ms |
9248 KB |
Output is correct |
55 |
Execution timed out |
5062 ms |
7132 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3328 KB |
Output is correct |
2 |
Correct |
4 ms |
3200 KB |
Output is correct |
3 |
Correct |
4 ms |
3072 KB |
Output is correct |
4 |
Correct |
5 ms |
3072 KB |
Output is correct |
5 |
Correct |
7 ms |
3200 KB |
Output is correct |
6 |
Correct |
9 ms |
3200 KB |
Output is correct |
7 |
Correct |
6 ms |
3200 KB |
Output is correct |
8 |
Correct |
6 ms |
3200 KB |
Output is correct |
9 |
Correct |
6 ms |
3200 KB |
Output is correct |
10 |
Correct |
7 ms |
3200 KB |
Output is correct |
11 |
Correct |
6 ms |
3200 KB |
Output is correct |
12 |
Correct |
7 ms |
3200 KB |
Output is correct |
13 |
Correct |
6 ms |
3200 KB |
Output is correct |
14 |
Correct |
8 ms |
3200 KB |
Output is correct |
15 |
Correct |
7 ms |
3200 KB |
Output is correct |
16 |
Correct |
7 ms |
3200 KB |
Output is correct |
17 |
Correct |
6 ms |
3200 KB |
Output is correct |
18 |
Correct |
8 ms |
3200 KB |
Output is correct |
19 |
Correct |
9 ms |
3200 KB |
Output is correct |
20 |
Correct |
8 ms |
3200 KB |
Output is correct |
21 |
Correct |
8 ms |
3200 KB |
Output is correct |
22 |
Correct |
9 ms |
3200 KB |
Output is correct |
23 |
Correct |
7 ms |
3200 KB |
Output is correct |
24 |
Correct |
9 ms |
3200 KB |
Output is correct |
25 |
Correct |
6 ms |
3200 KB |
Output is correct |
26 |
Correct |
6 ms |
3200 KB |
Output is correct |
27 |
Correct |
6 ms |
3200 KB |
Output is correct |
28 |
Correct |
6 ms |
3200 KB |
Output is correct |
29 |
Correct |
6 ms |
3200 KB |
Output is correct |
30 |
Correct |
6 ms |
3200 KB |
Output is correct |
31 |
Correct |
2983 ms |
9596 KB |
Output is correct |
32 |
Correct |
233 ms |
7520 KB |
Output is correct |
33 |
Correct |
399 ms |
7644 KB |
Output is correct |
34 |
Correct |
2323 ms |
7708 KB |
Output is correct |
35 |
Correct |
1598 ms |
9504 KB |
Output is correct |
36 |
Correct |
456 ms |
9440 KB |
Output is correct |
37 |
Correct |
359 ms |
6900 KB |
Output is correct |
38 |
Correct |
314 ms |
6924 KB |
Output is correct |
39 |
Correct |
303 ms |
6772 KB |
Output is correct |
40 |
Correct |
292 ms |
6704 KB |
Output is correct |
41 |
Correct |
442 ms |
7000 KB |
Output is correct |
42 |
Correct |
378 ms |
6720 KB |
Output is correct |
43 |
Correct |
730 ms |
9692 KB |
Output is correct |
44 |
Correct |
442 ms |
7052 KB |
Output is correct |
45 |
Correct |
383 ms |
6920 KB |
Output is correct |
46 |
Correct |
263 ms |
6960 KB |
Output is correct |
47 |
Correct |
251 ms |
6600 KB |
Output is correct |
48 |
Correct |
271 ms |
6620 KB |
Output is correct |
49 |
Correct |
259 ms |
6748 KB |
Output is correct |
50 |
Correct |
398 ms |
6832 KB |
Output is correct |
51 |
Correct |
244 ms |
6760 KB |
Output is correct |
52 |
Execution timed out |
5076 ms |
32440 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |