#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 (int)(lower_bound(com.begin(), com.end(), x) - com.begin());
}
struct eve
{
int t, x, d;
bool operator <(const eve &e) const
{
return t != e.t ? t < e.t : d > e.d;
}
};
struct pos
{
int c, l, lt, r, rt;
};
vector<eve> arr;
map<int, pos> loc[MAXN + 10];
struct seg
{
int t1, t2, x, y;
bool operator <(const seg &e) const
{
return x < e.x;
}
};
vector<seg> sor[2];
void add_seg(int t1, int t2, int x, int y)
{
if(t1 > t2 || x == y)
return;
int nt1 = bp + idx(t1);
int nt2 = bp + idx(t2 + 1) - 1;
if(nt1 > nt2)
return;
if(y < x)
sor[0].push_back({ nt1, nt2, y, x });
else
sor[1].push_back({ nt1, nt2, INF - y + 1, INF - x + 1 });
}
struct ent
{
// v0 : dec, v1 : inc, q : query
// v : { x, y }
// q : { x, i }
vector<pair<int, int>> v[2];
vector<pair<int, int>> q;
};
ent mem[MAXI + 10];
struct que
{
int l, y, i;
bool operator <(const que &x) const
{
return l < x.l;
}
};
vector<que> inp;
bool chk[MAXN + 10];
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);
arr.push_back({ a, x, t });
arr.push_back({ b, x, -t });
}
for(int i = 0; i < q; i++)
{
int l, y;
scanf("%d%d", &l, &y);
inp.push_back({ l, y, i });
com.push_back(y);
}
sort(inp.begin(), inp.end());
sort(com.begin(), com.end());
com.erase(unique(com.begin(), com.end()), com.end());
int sz = (int)com.size();
for(bp = 1; bp < sz; bp *= 2);
sort(arr.begin(), arr.end());
int cur, cnt = 0;
for(eve &e : arr)
{
if(e.d > 0)
{
if(loc[e.d].size() == 0)
{
cnt++;
if(cnt == k)
cur = e.t;
}
auto it = loc[e.d].find(e.x);
if(it != loc[e.d].end())
{
it->second.c++;
continue;
}
it = loc[e.d].insert({ e.x,{ 1, 1, e.t, INF, e.t } }).first;
pos &p = it->second;
if(it != loc[e.d].begin())
{
int x = prev(it)->first;
pos &q = prev(it)->second;
add_seg(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) != loc[e.d].end())
{
int x = next(it)->first;
pos &q = next(it)->second;
add_seg(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 = loc[e.d].find(e.x);
pos &p = it->second;
if(p.c > 1)
{
p.c--;
continue;
}
add_seg(p.lt, e.t, e.x, p.l);
add_seg(p.rt, e.t, e.x, p.r);
if(it != loc[e.d].begin())
{
int x = prev(it)->first;
pos &q = prev(it)->second;
add_seg(q.rt, e.t, x, q.r);
q.rt = e.t + 1;
if(next(it) != loc[e.d].end())
{
int y = next(it)->first;
q.r = (x + y) / 2;
}
else
q.r = INF;
}
if(next(it) != loc[e.d].end())
{
int x = next(it)->first;
pos &q = next(it)->second;
add_seg(q.lt, e.t, x, q.l);
q.lt = e.t + 1;
if(it != loc[e.d].begin())
{
int y = prev(it)->first;
q.l = (y + x + 1) / 2;
}
else
q.l = 1;
}
loc[e.d].erase(it);
if(loc[e.d].size() == 0)
{
if(cnt == k)
{
int t1 = idx(cur);
int t2 = idx(e.t + 1) - 1;
for(int i = t1; i <= t2; i++)
chk[i] = 1;
}
cnt--;
}
}
}
for(que &e : inp)
{
int x = idx(e.y);
if(chk[x])
{
x += bp;
while(x)
{
mem[x].q.push_back({ e.l, e.i });
x /= 2;
}
}
else
ans[e.i] = -1;
}
for(int i = 0; i < 2; i++)
{
sort(sor[i].begin(), sor[i].end());
for(seg &e : sor[i])
{
int t1 = e.t1;
int t2 = e.t2;
while(t1 < t2)
{
if(t1 % 2 == 1)
{
mem[t1].v[i].push_back({ e.x, e.y });
t1++;
}
if(t2 % 2 == 0)
{
mem[t2].v[i].push_back({ e.x, e.y });
t2--;
}
t1 /= 2;
t2 /= 2;
}
if(t1 == t2)
mem[t1].v[i].push_back({ e.x, e.y });
}
}
for(int x = 1; x <= bp + sz - 1; x++)
{
for(int i = 0; i < 2; i++)
{
int mx, p1, p2, sz1, sz2;
mx = p1 = p2 = 0;
sz1 = (int)mem[x].v[i].size();
sz2 = (int)mem[x].q.size();
if(i == 1)
reverse(mem[x].q.begin(), mem[x].q.end());
while(p2 < sz2)
{
int qx, qi;
tie(qx, qi) = mem[x].q[p2];
if(i == 1)
qx = INF - qx + 1;
if(p1 != sz1 && mem[x].v[i][p1].first <= qx)
{
mx = max(mx, mem[x].v[i][p1].second);
p1++;
}
else
{
ans[qi] = max(ans[qi], mx - qx);
p2++;
}
}
}
}
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:104: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:108: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:116:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &l, &y);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
88308 KB |
Output is correct |
2 |
Correct |
73 ms |
88424 KB |
Output is correct |
3 |
Correct |
75 ms |
88424 KB |
Output is correct |
4 |
Correct |
80 ms |
88528 KB |
Output is correct |
5 |
Correct |
80 ms |
88592 KB |
Output is correct |
6 |
Correct |
78 ms |
88764 KB |
Output is correct |
7 |
Correct |
76 ms |
88764 KB |
Output is correct |
8 |
Correct |
80 ms |
88764 KB |
Output is correct |
9 |
Correct |
77 ms |
88764 KB |
Output is correct |
10 |
Correct |
77 ms |
88764 KB |
Output is correct |
11 |
Correct |
83 ms |
88764 KB |
Output is correct |
12 |
Correct |
77 ms |
88764 KB |
Output is correct |
13 |
Correct |
82 ms |
88764 KB |
Output is correct |
14 |
Correct |
79 ms |
88764 KB |
Output is correct |
15 |
Correct |
83 ms |
88764 KB |
Output is correct |
16 |
Correct |
83 ms |
88764 KB |
Output is correct |
17 |
Correct |
75 ms |
88764 KB |
Output is correct |
18 |
Correct |
80 ms |
88804 KB |
Output is correct |
19 |
Correct |
77 ms |
88804 KB |
Output is correct |
20 |
Correct |
78 ms |
88804 KB |
Output is correct |
21 |
Correct |
81 ms |
88804 KB |
Output is correct |
22 |
Correct |
78 ms |
88804 KB |
Output is correct |
23 |
Correct |
78 ms |
88804 KB |
Output is correct |
24 |
Correct |
73 ms |
88804 KB |
Output is correct |
25 |
Correct |
81 ms |
88828 KB |
Output is correct |
26 |
Correct |
79 ms |
88828 KB |
Output is correct |
27 |
Correct |
76 ms |
88828 KB |
Output is correct |
28 |
Correct |
79 ms |
88828 KB |
Output is correct |
29 |
Correct |
83 ms |
88828 KB |
Output is correct |
30 |
Correct |
84 ms |
88828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
88308 KB |
Output is correct |
2 |
Correct |
73 ms |
88424 KB |
Output is correct |
3 |
Correct |
75 ms |
88424 KB |
Output is correct |
4 |
Correct |
80 ms |
88528 KB |
Output is correct |
5 |
Correct |
80 ms |
88592 KB |
Output is correct |
6 |
Correct |
78 ms |
88764 KB |
Output is correct |
7 |
Correct |
76 ms |
88764 KB |
Output is correct |
8 |
Correct |
80 ms |
88764 KB |
Output is correct |
9 |
Correct |
77 ms |
88764 KB |
Output is correct |
10 |
Correct |
77 ms |
88764 KB |
Output is correct |
11 |
Correct |
83 ms |
88764 KB |
Output is correct |
12 |
Correct |
77 ms |
88764 KB |
Output is correct |
13 |
Correct |
82 ms |
88764 KB |
Output is correct |
14 |
Correct |
79 ms |
88764 KB |
Output is correct |
15 |
Correct |
83 ms |
88764 KB |
Output is correct |
16 |
Correct |
83 ms |
88764 KB |
Output is correct |
17 |
Correct |
75 ms |
88764 KB |
Output is correct |
18 |
Correct |
80 ms |
88804 KB |
Output is correct |
19 |
Correct |
77 ms |
88804 KB |
Output is correct |
20 |
Correct |
78 ms |
88804 KB |
Output is correct |
21 |
Correct |
81 ms |
88804 KB |
Output is correct |
22 |
Correct |
78 ms |
88804 KB |
Output is correct |
23 |
Correct |
78 ms |
88804 KB |
Output is correct |
24 |
Correct |
73 ms |
88804 KB |
Output is correct |
25 |
Correct |
81 ms |
88828 KB |
Output is correct |
26 |
Correct |
79 ms |
88828 KB |
Output is correct |
27 |
Correct |
76 ms |
88828 KB |
Output is correct |
28 |
Correct |
79 ms |
88828 KB |
Output is correct |
29 |
Correct |
83 ms |
88828 KB |
Output is correct |
30 |
Correct |
84 ms |
88828 KB |
Output is correct |
31 |
Correct |
1081 ms |
155380 KB |
Output is correct |
32 |
Correct |
136 ms |
155380 KB |
Output is correct |
33 |
Correct |
870 ms |
155380 KB |
Output is correct |
34 |
Correct |
1018 ms |
155380 KB |
Output is correct |
35 |
Correct |
957 ms |
156308 KB |
Output is correct |
36 |
Correct |
962 ms |
156456 KB |
Output is correct |
37 |
Correct |
605 ms |
156456 KB |
Output is correct |
38 |
Correct |
753 ms |
156456 KB |
Output is correct |
39 |
Correct |
554 ms |
156456 KB |
Output is correct |
40 |
Correct |
611 ms |
156456 KB |
Output is correct |
41 |
Correct |
657 ms |
156456 KB |
Output is correct |
42 |
Correct |
549 ms |
156456 KB |
Output is correct |
43 |
Correct |
127 ms |
156456 KB |
Output is correct |
44 |
Correct |
595 ms |
156456 KB |
Output is correct |
45 |
Correct |
572 ms |
156456 KB |
Output is correct |
46 |
Correct |
499 ms |
156456 KB |
Output is correct |
47 |
Correct |
323 ms |
156456 KB |
Output is correct |
48 |
Correct |
312 ms |
156456 KB |
Output is correct |
49 |
Correct |
375 ms |
156456 KB |
Output is correct |
50 |
Correct |
391 ms |
156456 KB |
Output is correct |
51 |
Correct |
386 ms |
156456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2128 ms |
241616 KB |
Output is correct |
2 |
Correct |
2181 ms |
241616 KB |
Output is correct |
3 |
Correct |
1774 ms |
241616 KB |
Output is correct |
4 |
Correct |
1910 ms |
241996 KB |
Output is correct |
5 |
Correct |
2617 ms |
255488 KB |
Output is correct |
6 |
Correct |
2455 ms |
255488 KB |
Output is correct |
7 |
Correct |
2150 ms |
255488 KB |
Output is correct |
8 |
Correct |
2232 ms |
255488 KB |
Output is correct |
9 |
Correct |
2277 ms |
264752 KB |
Output is correct |
10 |
Correct |
2263 ms |
264752 KB |
Output is correct |
11 |
Correct |
1412 ms |
264752 KB |
Output is correct |
12 |
Correct |
1441 ms |
264752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5028 ms |
324120 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
88308 KB |
Output is correct |
2 |
Correct |
73 ms |
88424 KB |
Output is correct |
3 |
Correct |
75 ms |
88424 KB |
Output is correct |
4 |
Correct |
80 ms |
88528 KB |
Output is correct |
5 |
Correct |
80 ms |
88592 KB |
Output is correct |
6 |
Correct |
78 ms |
88764 KB |
Output is correct |
7 |
Correct |
76 ms |
88764 KB |
Output is correct |
8 |
Correct |
80 ms |
88764 KB |
Output is correct |
9 |
Correct |
77 ms |
88764 KB |
Output is correct |
10 |
Correct |
77 ms |
88764 KB |
Output is correct |
11 |
Correct |
83 ms |
88764 KB |
Output is correct |
12 |
Correct |
77 ms |
88764 KB |
Output is correct |
13 |
Correct |
82 ms |
88764 KB |
Output is correct |
14 |
Correct |
79 ms |
88764 KB |
Output is correct |
15 |
Correct |
83 ms |
88764 KB |
Output is correct |
16 |
Correct |
83 ms |
88764 KB |
Output is correct |
17 |
Correct |
75 ms |
88764 KB |
Output is correct |
18 |
Correct |
80 ms |
88804 KB |
Output is correct |
19 |
Correct |
77 ms |
88804 KB |
Output is correct |
20 |
Correct |
78 ms |
88804 KB |
Output is correct |
21 |
Correct |
81 ms |
88804 KB |
Output is correct |
22 |
Correct |
78 ms |
88804 KB |
Output is correct |
23 |
Correct |
78 ms |
88804 KB |
Output is correct |
24 |
Correct |
73 ms |
88804 KB |
Output is correct |
25 |
Correct |
81 ms |
88828 KB |
Output is correct |
26 |
Correct |
79 ms |
88828 KB |
Output is correct |
27 |
Correct |
76 ms |
88828 KB |
Output is correct |
28 |
Correct |
79 ms |
88828 KB |
Output is correct |
29 |
Correct |
83 ms |
88828 KB |
Output is correct |
30 |
Correct |
84 ms |
88828 KB |
Output is correct |
31 |
Correct |
1081 ms |
155380 KB |
Output is correct |
32 |
Correct |
136 ms |
155380 KB |
Output is correct |
33 |
Correct |
870 ms |
155380 KB |
Output is correct |
34 |
Correct |
1018 ms |
155380 KB |
Output is correct |
35 |
Correct |
957 ms |
156308 KB |
Output is correct |
36 |
Correct |
962 ms |
156456 KB |
Output is correct |
37 |
Correct |
605 ms |
156456 KB |
Output is correct |
38 |
Correct |
753 ms |
156456 KB |
Output is correct |
39 |
Correct |
554 ms |
156456 KB |
Output is correct |
40 |
Correct |
611 ms |
156456 KB |
Output is correct |
41 |
Correct |
657 ms |
156456 KB |
Output is correct |
42 |
Correct |
549 ms |
156456 KB |
Output is correct |
43 |
Correct |
127 ms |
156456 KB |
Output is correct |
44 |
Correct |
595 ms |
156456 KB |
Output is correct |
45 |
Correct |
572 ms |
156456 KB |
Output is correct |
46 |
Correct |
499 ms |
156456 KB |
Output is correct |
47 |
Correct |
323 ms |
156456 KB |
Output is correct |
48 |
Correct |
312 ms |
156456 KB |
Output is correct |
49 |
Correct |
375 ms |
156456 KB |
Output is correct |
50 |
Correct |
391 ms |
156456 KB |
Output is correct |
51 |
Correct |
386 ms |
156456 KB |
Output is correct |
52 |
Correct |
389 ms |
324120 KB |
Output is correct |
53 |
Correct |
413 ms |
324120 KB |
Output is correct |
54 |
Correct |
653 ms |
324120 KB |
Output is correct |
55 |
Correct |
618 ms |
324120 KB |
Output is correct |
56 |
Correct |
624 ms |
324120 KB |
Output is correct |
57 |
Correct |
612 ms |
324120 KB |
Output is correct |
58 |
Correct |
600 ms |
324120 KB |
Output is correct |
59 |
Correct |
565 ms |
324120 KB |
Output is correct |
60 |
Correct |
597 ms |
324120 KB |
Output is correct |
61 |
Correct |
148 ms |
324120 KB |
Output is correct |
62 |
Correct |
390 ms |
324120 KB |
Output is correct |
63 |
Correct |
526 ms |
324120 KB |
Output is correct |
64 |
Correct |
508 ms |
324120 KB |
Output is correct |
65 |
Correct |
744 ms |
324120 KB |
Output is correct |
66 |
Correct |
710 ms |
324120 KB |
Output is correct |
67 |
Correct |
208 ms |
324120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
88308 KB |
Output is correct |
2 |
Correct |
73 ms |
88424 KB |
Output is correct |
3 |
Correct |
75 ms |
88424 KB |
Output is correct |
4 |
Correct |
80 ms |
88528 KB |
Output is correct |
5 |
Correct |
80 ms |
88592 KB |
Output is correct |
6 |
Correct |
78 ms |
88764 KB |
Output is correct |
7 |
Correct |
76 ms |
88764 KB |
Output is correct |
8 |
Correct |
80 ms |
88764 KB |
Output is correct |
9 |
Correct |
77 ms |
88764 KB |
Output is correct |
10 |
Correct |
77 ms |
88764 KB |
Output is correct |
11 |
Correct |
83 ms |
88764 KB |
Output is correct |
12 |
Correct |
77 ms |
88764 KB |
Output is correct |
13 |
Correct |
82 ms |
88764 KB |
Output is correct |
14 |
Correct |
79 ms |
88764 KB |
Output is correct |
15 |
Correct |
83 ms |
88764 KB |
Output is correct |
16 |
Correct |
83 ms |
88764 KB |
Output is correct |
17 |
Correct |
75 ms |
88764 KB |
Output is correct |
18 |
Correct |
80 ms |
88804 KB |
Output is correct |
19 |
Correct |
77 ms |
88804 KB |
Output is correct |
20 |
Correct |
78 ms |
88804 KB |
Output is correct |
21 |
Correct |
81 ms |
88804 KB |
Output is correct |
22 |
Correct |
78 ms |
88804 KB |
Output is correct |
23 |
Correct |
78 ms |
88804 KB |
Output is correct |
24 |
Correct |
73 ms |
88804 KB |
Output is correct |
25 |
Correct |
81 ms |
88828 KB |
Output is correct |
26 |
Correct |
79 ms |
88828 KB |
Output is correct |
27 |
Correct |
76 ms |
88828 KB |
Output is correct |
28 |
Correct |
79 ms |
88828 KB |
Output is correct |
29 |
Correct |
83 ms |
88828 KB |
Output is correct |
30 |
Correct |
84 ms |
88828 KB |
Output is correct |
31 |
Correct |
1081 ms |
155380 KB |
Output is correct |
32 |
Correct |
136 ms |
155380 KB |
Output is correct |
33 |
Correct |
870 ms |
155380 KB |
Output is correct |
34 |
Correct |
1018 ms |
155380 KB |
Output is correct |
35 |
Correct |
957 ms |
156308 KB |
Output is correct |
36 |
Correct |
962 ms |
156456 KB |
Output is correct |
37 |
Correct |
605 ms |
156456 KB |
Output is correct |
38 |
Correct |
753 ms |
156456 KB |
Output is correct |
39 |
Correct |
554 ms |
156456 KB |
Output is correct |
40 |
Correct |
611 ms |
156456 KB |
Output is correct |
41 |
Correct |
657 ms |
156456 KB |
Output is correct |
42 |
Correct |
549 ms |
156456 KB |
Output is correct |
43 |
Correct |
127 ms |
156456 KB |
Output is correct |
44 |
Correct |
595 ms |
156456 KB |
Output is correct |
45 |
Correct |
572 ms |
156456 KB |
Output is correct |
46 |
Correct |
499 ms |
156456 KB |
Output is correct |
47 |
Correct |
323 ms |
156456 KB |
Output is correct |
48 |
Correct |
312 ms |
156456 KB |
Output is correct |
49 |
Correct |
375 ms |
156456 KB |
Output is correct |
50 |
Correct |
391 ms |
156456 KB |
Output is correct |
51 |
Correct |
386 ms |
156456 KB |
Output is correct |
52 |
Correct |
2128 ms |
241616 KB |
Output is correct |
53 |
Correct |
2181 ms |
241616 KB |
Output is correct |
54 |
Correct |
1774 ms |
241616 KB |
Output is correct |
55 |
Correct |
1910 ms |
241996 KB |
Output is correct |
56 |
Correct |
2617 ms |
255488 KB |
Output is correct |
57 |
Correct |
2455 ms |
255488 KB |
Output is correct |
58 |
Correct |
2150 ms |
255488 KB |
Output is correct |
59 |
Correct |
2232 ms |
255488 KB |
Output is correct |
60 |
Correct |
2277 ms |
264752 KB |
Output is correct |
61 |
Correct |
2263 ms |
264752 KB |
Output is correct |
62 |
Correct |
1412 ms |
264752 KB |
Output is correct |
63 |
Correct |
1441 ms |
264752 KB |
Output is correct |
64 |
Execution timed out |
5028 ms |
324120 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |