#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>
using namespace std;
const int MAXN = 300000;
const int MAXI = 1048576;
const int INF = 100000000;
int n, k, q, bp;
vector<int> com;
inline int idx(int x)
{
return lower_bound(com.begin(), com.end(), x) - com.begin();
}
struct eve1
{
int t, x, d;
bool operator <(const eve1 &e) const
{
return t != e.t ? t < e.t : d > e.d;
}
};
struct ent1
{
int c, l, lt, r, rt;
};
vector<eve1> arr1;
map<int, ent1> loc1[MAXN + 10];
// segment: [t, t2] time, [x -> y] loc
// query : t time, t2 = -1, x loc, y idx
struct eve2
{
int t, t2, x, y;
bool operator <(const eve2 &e) const
{
return t != e.t ? t < e.t : t2 > e.t2;
}
};
struct ent2
{
// list<pair<int, int>> a;
// list<pair<int, int>> b;
vector<pair<int, int>> a;
vector<pair<int, int>> b;
};
vector<eve2> arr2;
ent2 mem2[MAXI + 10];
void upd(int x, int t, int v, int v2)
{
if(v < v2)
mem2[x].a.push_back({ v, t });
else
mem2[x].b.push_back({ v, t });
}
void add(const eve2 &e)
{
if(e.t > e.t2 || e.x == e.y)
return;
int x = bp + idx(min(e.x, e.y));
int y = bp + idx(max(e.x, e.y) + 1) - 1;
if(x > y)
return;
while(x < y)
{
if(x % 2 == 1)
{
upd(x, e.t2, e.x, e.y);
x++;
}
if(y % 2 == 0)
{
upd(y, e.t2, e.x, e.y);
y--;
}
x /= 2;
y /= 2;
}
if(x == y)
upd(x, e.t2, e.x, e.y);
}
int get(int t, int p)
{
int r = 0;
int x = bp + idx(p);
while(x)
{
for(auto &e : mem2[x].a)
if(t <= e.second)
r = max(r, abs(p - e.first));
for(auto &e : mem2[x].b)
if(t <= e.second)
r = max(r, abs(p - e.first));
x /= 2;
}
return r;
}
vector<pair<int, int>> can;
int ans[MAXN + 10];
int main()
{
//freopen("in", "r", stdin);
//freopen("out", "w", stdout);
scanf("%d%d%d", &n, &k, &q);
for(int i = 0; i < n; i++)
{
int x, t, a, b;
scanf("%d%d%d%d", &x, &t, &a, &b);
arr1.push_back({ a, x, t });
arr1.push_back({ b, x, -t });
}
for(int i = 0; i < q; i++)
{
int l, y;
scanf("%d%d", &l, &y);
arr2.push_back({ y, -1, l, i });
com.push_back(l);
}
sort(com.begin(), com.end());
com.erase(unique(com.begin(), com.end()), com.end());
int isz = (int)com.size();
for(bp = 1; bp < isz; bp *= 2);
sort(arr1.begin(), arr1.end());
int cur, cnt = 0;
for(eve1 &e : arr1)
{
if(e.d > 0)
{
if(loc1[e.d].size() == 0)
{
cnt++;
if(cnt == k)
cur = e.t;
}
auto it = loc1[e.d].find(e.x);
if(it != loc1[e.d].end())
{
it->second.c++;
continue;
}
it = loc1[e.d].insert({ e.x, { 1, 1, e.t, INF, e.t } }).first;
ent1 &p = it->second;
if(it != loc1[e.d].begin())
{
int x = prev(it)->first;
ent1 &q = prev(it)->second;
arr2.push_back({ q.rt, e.t - 1, x, q.r });
q.rt = e.t;
q.r = (x + e.x) / 2;
p.l = (x + e.x + 1) / 2;
}
if(next(it) != loc1[e.d].end())
{
int x = next(it)->first;
ent1 &q = next(it)->second;
arr2.push_back({ q.lt, e.t - 1, x, q.l });
q.lt = e.t;
q.l = (x + e.x + 1) / 2;
p.r = (x + e.x) / 2;
}
}
else
{
e.d = -e.d;
auto it = loc1[e.d].find(e.x);
ent1 &p = it->second;
if(p.c > 1)
{
p.c--;
continue;
}
arr2.push_back({ p.lt, e.t, e.x, p.l });
arr2.push_back({ p.rt, e.t, e.x, p.r });
if(it != loc1[e.d].begin())
{
int x = prev(it)->first;
ent1 &q = prev(it)->second;
arr2.push_back({ q.rt, e.t, x, q.r });
q.rt = e.t + 1;
if(next(it) != loc1[e.d].end())
{
int y = next(it)->first;
q.r = (x + y) / 2;
}
else
q.r = INF;
}
if(next(it) != loc1[e.d].end())
{
int x = next(it)->first;
ent1 &q = next(it)->second;
arr2.push_back({ q.lt, e.t, x, q.l });
q.lt = e.t + 1;
if(it != loc1[e.d].begin())
{
int y = prev(it)->first;
q.l = (y + x + 1) / 2;
}
else
q.l = 1;
}
loc1[e.d].erase(it);
if(loc1[e.d].size() == 0)
{
if(cnt == k)
can.push_back({ cur, e.t });
cnt--;
}
}
}
sort(arr2.begin(), arr2.end());
int p = 0, sz = (int)can.size();
for(eve2 &e : arr2)
{
if(e.t2 != -1)
add(e);
else
{
while(p < sz && can[p].second < e.t)
p++;
if(p < sz && can[p].first <= e.t)
ans[e.y] = get(e.t, e.x);
else
ans[e.y] = -1;
}
}
for(int i = 0; i < q; i++)
printf("%d\n", ans[i]);
return 0;
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:134: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:138:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &x, &t, &a, &b);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:145:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &l, &y);
~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
63608 KB |
Output is correct |
2 |
Correct |
59 ms |
63716 KB |
Output is correct |
3 |
Correct |
72 ms |
63772 KB |
Output is correct |
4 |
Correct |
57 ms |
63928 KB |
Output is correct |
5 |
Correct |
53 ms |
64036 KB |
Output is correct |
6 |
Correct |
60 ms |
64056 KB |
Output is correct |
7 |
Correct |
53 ms |
64056 KB |
Output is correct |
8 |
Correct |
56 ms |
64056 KB |
Output is correct |
9 |
Correct |
53 ms |
64056 KB |
Output is correct |
10 |
Correct |
54 ms |
64076 KB |
Output is correct |
11 |
Correct |
54 ms |
64076 KB |
Output is correct |
12 |
Correct |
59 ms |
64076 KB |
Output is correct |
13 |
Correct |
60 ms |
64076 KB |
Output is correct |
14 |
Correct |
57 ms |
64076 KB |
Output is correct |
15 |
Correct |
60 ms |
64124 KB |
Output is correct |
16 |
Correct |
58 ms |
64124 KB |
Output is correct |
17 |
Correct |
63 ms |
64124 KB |
Output is correct |
18 |
Correct |
58 ms |
64124 KB |
Output is correct |
19 |
Correct |
56 ms |
64124 KB |
Output is correct |
20 |
Correct |
55 ms |
64148 KB |
Output is correct |
21 |
Correct |
53 ms |
64148 KB |
Output is correct |
22 |
Correct |
56 ms |
64148 KB |
Output is correct |
23 |
Correct |
53 ms |
64148 KB |
Output is correct |
24 |
Correct |
53 ms |
64148 KB |
Output is correct |
25 |
Correct |
54 ms |
64148 KB |
Output is correct |
26 |
Correct |
55 ms |
64148 KB |
Output is correct |
27 |
Correct |
55 ms |
64148 KB |
Output is correct |
28 |
Correct |
60 ms |
64148 KB |
Output is correct |
29 |
Correct |
56 ms |
64148 KB |
Output is correct |
30 |
Correct |
54 ms |
64148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
63608 KB |
Output is correct |
2 |
Correct |
59 ms |
63716 KB |
Output is correct |
3 |
Correct |
72 ms |
63772 KB |
Output is correct |
4 |
Correct |
57 ms |
63928 KB |
Output is correct |
5 |
Correct |
53 ms |
64036 KB |
Output is correct |
6 |
Correct |
60 ms |
64056 KB |
Output is correct |
7 |
Correct |
53 ms |
64056 KB |
Output is correct |
8 |
Correct |
56 ms |
64056 KB |
Output is correct |
9 |
Correct |
53 ms |
64056 KB |
Output is correct |
10 |
Correct |
54 ms |
64076 KB |
Output is correct |
11 |
Correct |
54 ms |
64076 KB |
Output is correct |
12 |
Correct |
59 ms |
64076 KB |
Output is correct |
13 |
Correct |
60 ms |
64076 KB |
Output is correct |
14 |
Correct |
57 ms |
64076 KB |
Output is correct |
15 |
Correct |
60 ms |
64124 KB |
Output is correct |
16 |
Correct |
58 ms |
64124 KB |
Output is correct |
17 |
Correct |
63 ms |
64124 KB |
Output is correct |
18 |
Correct |
58 ms |
64124 KB |
Output is correct |
19 |
Correct |
56 ms |
64124 KB |
Output is correct |
20 |
Correct |
55 ms |
64148 KB |
Output is correct |
21 |
Correct |
53 ms |
64148 KB |
Output is correct |
22 |
Correct |
56 ms |
64148 KB |
Output is correct |
23 |
Correct |
53 ms |
64148 KB |
Output is correct |
24 |
Correct |
53 ms |
64148 KB |
Output is correct |
25 |
Correct |
54 ms |
64148 KB |
Output is correct |
26 |
Correct |
55 ms |
64148 KB |
Output is correct |
27 |
Correct |
55 ms |
64148 KB |
Output is correct |
28 |
Correct |
60 ms |
64148 KB |
Output is correct |
29 |
Correct |
56 ms |
64148 KB |
Output is correct |
30 |
Correct |
54 ms |
64148 KB |
Output is correct |
31 |
Correct |
1507 ms |
109840 KB |
Output is correct |
32 |
Correct |
126 ms |
109840 KB |
Output is correct |
33 |
Correct |
808 ms |
109840 KB |
Output is correct |
34 |
Correct |
1678 ms |
112460 KB |
Output is correct |
35 |
Correct |
1273 ms |
112460 KB |
Output is correct |
36 |
Correct |
695 ms |
112460 KB |
Output is correct |
37 |
Correct |
668 ms |
112460 KB |
Output is correct |
38 |
Correct |
544 ms |
112460 KB |
Output is correct |
39 |
Correct |
567 ms |
112460 KB |
Output is correct |
40 |
Correct |
468 ms |
112460 KB |
Output is correct |
41 |
Correct |
3424 ms |
112460 KB |
Output is correct |
42 |
Correct |
2162 ms |
112460 KB |
Output is correct |
43 |
Correct |
155 ms |
112460 KB |
Output is correct |
44 |
Correct |
3888 ms |
112460 KB |
Output is correct |
45 |
Correct |
3480 ms |
112460 KB |
Output is correct |
46 |
Correct |
3170 ms |
112460 KB |
Output is correct |
47 |
Correct |
1181 ms |
112460 KB |
Output is correct |
48 |
Correct |
1511 ms |
112460 KB |
Output is correct |
49 |
Correct |
1555 ms |
112460 KB |
Output is correct |
50 |
Correct |
1204 ms |
112460 KB |
Output is correct |
51 |
Correct |
1678 ms |
112460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5090 ms |
190964 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5117 ms |
212992 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
63608 KB |
Output is correct |
2 |
Correct |
59 ms |
63716 KB |
Output is correct |
3 |
Correct |
72 ms |
63772 KB |
Output is correct |
4 |
Correct |
57 ms |
63928 KB |
Output is correct |
5 |
Correct |
53 ms |
64036 KB |
Output is correct |
6 |
Correct |
60 ms |
64056 KB |
Output is correct |
7 |
Correct |
53 ms |
64056 KB |
Output is correct |
8 |
Correct |
56 ms |
64056 KB |
Output is correct |
9 |
Correct |
53 ms |
64056 KB |
Output is correct |
10 |
Correct |
54 ms |
64076 KB |
Output is correct |
11 |
Correct |
54 ms |
64076 KB |
Output is correct |
12 |
Correct |
59 ms |
64076 KB |
Output is correct |
13 |
Correct |
60 ms |
64076 KB |
Output is correct |
14 |
Correct |
57 ms |
64076 KB |
Output is correct |
15 |
Correct |
60 ms |
64124 KB |
Output is correct |
16 |
Correct |
58 ms |
64124 KB |
Output is correct |
17 |
Correct |
63 ms |
64124 KB |
Output is correct |
18 |
Correct |
58 ms |
64124 KB |
Output is correct |
19 |
Correct |
56 ms |
64124 KB |
Output is correct |
20 |
Correct |
55 ms |
64148 KB |
Output is correct |
21 |
Correct |
53 ms |
64148 KB |
Output is correct |
22 |
Correct |
56 ms |
64148 KB |
Output is correct |
23 |
Correct |
53 ms |
64148 KB |
Output is correct |
24 |
Correct |
53 ms |
64148 KB |
Output is correct |
25 |
Correct |
54 ms |
64148 KB |
Output is correct |
26 |
Correct |
55 ms |
64148 KB |
Output is correct |
27 |
Correct |
55 ms |
64148 KB |
Output is correct |
28 |
Correct |
60 ms |
64148 KB |
Output is correct |
29 |
Correct |
56 ms |
64148 KB |
Output is correct |
30 |
Correct |
54 ms |
64148 KB |
Output is correct |
31 |
Correct |
1507 ms |
109840 KB |
Output is correct |
32 |
Correct |
126 ms |
109840 KB |
Output is correct |
33 |
Correct |
808 ms |
109840 KB |
Output is correct |
34 |
Correct |
1678 ms |
112460 KB |
Output is correct |
35 |
Correct |
1273 ms |
112460 KB |
Output is correct |
36 |
Correct |
695 ms |
112460 KB |
Output is correct |
37 |
Correct |
668 ms |
112460 KB |
Output is correct |
38 |
Correct |
544 ms |
112460 KB |
Output is correct |
39 |
Correct |
567 ms |
112460 KB |
Output is correct |
40 |
Correct |
468 ms |
112460 KB |
Output is correct |
41 |
Correct |
3424 ms |
112460 KB |
Output is correct |
42 |
Correct |
2162 ms |
112460 KB |
Output is correct |
43 |
Correct |
155 ms |
112460 KB |
Output is correct |
44 |
Correct |
3888 ms |
112460 KB |
Output is correct |
45 |
Correct |
3480 ms |
112460 KB |
Output is correct |
46 |
Correct |
3170 ms |
112460 KB |
Output is correct |
47 |
Correct |
1181 ms |
112460 KB |
Output is correct |
48 |
Correct |
1511 ms |
112460 KB |
Output is correct |
49 |
Correct |
1555 ms |
112460 KB |
Output is correct |
50 |
Correct |
1204 ms |
112460 KB |
Output is correct |
51 |
Correct |
1678 ms |
112460 KB |
Output is correct |
52 |
Correct |
390 ms |
212992 KB |
Output is correct |
53 |
Correct |
344 ms |
212992 KB |
Output is correct |
54 |
Correct |
651 ms |
212992 KB |
Output is correct |
55 |
Correct |
4763 ms |
212992 KB |
Output is correct |
56 |
Execution timed out |
5021 ms |
212992 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
63608 KB |
Output is correct |
2 |
Correct |
59 ms |
63716 KB |
Output is correct |
3 |
Correct |
72 ms |
63772 KB |
Output is correct |
4 |
Correct |
57 ms |
63928 KB |
Output is correct |
5 |
Correct |
53 ms |
64036 KB |
Output is correct |
6 |
Correct |
60 ms |
64056 KB |
Output is correct |
7 |
Correct |
53 ms |
64056 KB |
Output is correct |
8 |
Correct |
56 ms |
64056 KB |
Output is correct |
9 |
Correct |
53 ms |
64056 KB |
Output is correct |
10 |
Correct |
54 ms |
64076 KB |
Output is correct |
11 |
Correct |
54 ms |
64076 KB |
Output is correct |
12 |
Correct |
59 ms |
64076 KB |
Output is correct |
13 |
Correct |
60 ms |
64076 KB |
Output is correct |
14 |
Correct |
57 ms |
64076 KB |
Output is correct |
15 |
Correct |
60 ms |
64124 KB |
Output is correct |
16 |
Correct |
58 ms |
64124 KB |
Output is correct |
17 |
Correct |
63 ms |
64124 KB |
Output is correct |
18 |
Correct |
58 ms |
64124 KB |
Output is correct |
19 |
Correct |
56 ms |
64124 KB |
Output is correct |
20 |
Correct |
55 ms |
64148 KB |
Output is correct |
21 |
Correct |
53 ms |
64148 KB |
Output is correct |
22 |
Correct |
56 ms |
64148 KB |
Output is correct |
23 |
Correct |
53 ms |
64148 KB |
Output is correct |
24 |
Correct |
53 ms |
64148 KB |
Output is correct |
25 |
Correct |
54 ms |
64148 KB |
Output is correct |
26 |
Correct |
55 ms |
64148 KB |
Output is correct |
27 |
Correct |
55 ms |
64148 KB |
Output is correct |
28 |
Correct |
60 ms |
64148 KB |
Output is correct |
29 |
Correct |
56 ms |
64148 KB |
Output is correct |
30 |
Correct |
54 ms |
64148 KB |
Output is correct |
31 |
Correct |
1507 ms |
109840 KB |
Output is correct |
32 |
Correct |
126 ms |
109840 KB |
Output is correct |
33 |
Correct |
808 ms |
109840 KB |
Output is correct |
34 |
Correct |
1678 ms |
112460 KB |
Output is correct |
35 |
Correct |
1273 ms |
112460 KB |
Output is correct |
36 |
Correct |
695 ms |
112460 KB |
Output is correct |
37 |
Correct |
668 ms |
112460 KB |
Output is correct |
38 |
Correct |
544 ms |
112460 KB |
Output is correct |
39 |
Correct |
567 ms |
112460 KB |
Output is correct |
40 |
Correct |
468 ms |
112460 KB |
Output is correct |
41 |
Correct |
3424 ms |
112460 KB |
Output is correct |
42 |
Correct |
2162 ms |
112460 KB |
Output is correct |
43 |
Correct |
155 ms |
112460 KB |
Output is correct |
44 |
Correct |
3888 ms |
112460 KB |
Output is correct |
45 |
Correct |
3480 ms |
112460 KB |
Output is correct |
46 |
Correct |
3170 ms |
112460 KB |
Output is correct |
47 |
Correct |
1181 ms |
112460 KB |
Output is correct |
48 |
Correct |
1511 ms |
112460 KB |
Output is correct |
49 |
Correct |
1555 ms |
112460 KB |
Output is correct |
50 |
Correct |
1204 ms |
112460 KB |
Output is correct |
51 |
Correct |
1678 ms |
112460 KB |
Output is correct |
52 |
Execution timed out |
5090 ms |
190964 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |