#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 600005, INF = 2e8 + 10;
int n, k, A[N], TP[N], L[N], R[N];
int q, B[N], T[N], P[N], rev[N], res[N];
vector < int > U, S[N], E[N], Q[N];
multiset < int > ST[N];
struct SEGT
{
multiset < int > MS[N * 2];
inline void Add(int le, int ri, int val)
{
le += q; ri += q;
for (; le < ri; le >>= 1, ri >>= 1)
{
if (le & 1) MS[le ++].insert(val);
if (ri & 1) MS[-- ri].insert(val);
}
}
inline void Del(multiset < int > &SS, int val)
{
auto it = SS.lower_bound(val);
if ((*it) == val)
SS.erase(it);
}
inline void Del(int le, int ri, int val)
{
le += q; ri += q;
for (; le < ri; le >>= 1, ri >>= 1)
{
if (le & 1) Del(MS[le], val), le ++;
if (ri & 1) ri --, Del(MS[ri], val);
}
}
inline int Get(int i)
{
int Mn = INT_MAX, Mx = INT_MIN;
for (int id = i + q; id; id >>= 1)
if (MS[id].size())
{
Mn = min(Mn, *MS[id].begin());
Mx = max(Mx, *MS[id].rbegin());
}
return (max(Mx - B[P[i]], B[P[i]] - Mn));
}
};
SEGT SG;
inline bool CMP(int i, int j)
{
return (B[i] < B[j]);
}
inline void Fix(int l, int r, int tp)
{
B[q] = l; int le = lower_bound(P, P + q, q, CMP) - P;
B[q] = r; int ri = upper_bound(P, P + q, q, CMP) - P;
B[q] = (l + r) >> 1; int md = upper_bound(P, P + q, q, CMP) - P;
if (tp == 1)
{
SG.Add(le, md, l);
SG.Add(md, ri, r);
}
else
{
SG.Del(le, md, l);
SG.Del(md, ri, r);
}
}
int main()
{
scanf("%d%d%d", &n, &k, &q);
for (int i = 0; i < n; i++)
scanf("%d%d%d%d", &A[i], &TP[i], &L[i], &R[i]), U.pb(L[i]), U.pb(R[i] + 1);
for (int i = 0; i < q; i++)
scanf("%d%d", &B[i], &T[i]);
for (int i = 0; i < 10; i++)
U.pb(i);
sort(U.begin(), U.end());
U.resize(unique(U.begin(), U.end()) - U.begin());
for (int i = 0; i < n; i++)
{
L[i] = (int)(lower_bound(U.begin(), U.end(), L[i]) - U.begin());
R[i] = (int)(lower_bound(U.begin(), U.end(), R[i] + 1) - U.begin());
S[L[i]].pb(i); E[R[i]].pb(i);
}
for (int i = 0; i < q; i++)
{
T[i] = (int)(upper_bound(U.begin(), U.end(), T[i]) - U.begin()) - 1;
Q[T[i]].pb(i); P[i] = i;
}
sort(P, P + q, CMP);
for (int i = 0; i < q; i++)
rev[P[i]] = i;
int bad = k;
for (int i = 1; i <= k; i++)
{
ST[i].insert(-INF);
ST[i].insert(INF);
SG.Add(0, q, INF);
}
for (int i = 0; i <= (int)U.size(); i++)
{
for (int &id : E[i])
{
int tp = TP[id], l, r;
auto it = ST[tp].lower_bound(A[id]);
it = ST[tp].erase(it);
r = * it; it --; l = * it;
Fix(l, A[id], -1);
Fix(A[id], r, -1);
Fix(l, r, 1);
bad += (ST[tp].size() == 2);
}
for (int &id : S[i])
{
int tp = TP[id], l, r;
bad -= (ST[tp].size() == 2);
auto it = ST[tp].lower_bound(A[id]);
r = * it; it --; l = * it;
ST[tp].insert(A[id]);
Fix(l, r, -1);
Fix(l, A[id], 1);
Fix(A[id], r, 1);
}
for (int &id : Q[i])
{
if (bad)
res[id] = -1;
else
res[id] = SG.Get(rev[id]);
}
}
for (int i = 0; i < q; i++)
printf("%d\n", res[i]);
return 0;
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:72:7: 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:74:61: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &A[i], &TP[i], &L[i], &R[i]), U.pb(L[i]), U.pb(R[i] + 1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
new_home.cpp:76:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &B[i], &T[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
127224 KB |
Output is correct |
2 |
Correct |
112 ms |
127144 KB |
Output is correct |
3 |
Correct |
108 ms |
127348 KB |
Output is correct |
4 |
Correct |
110 ms |
127364 KB |
Output is correct |
5 |
Correct |
164 ms |
127268 KB |
Output is correct |
6 |
Correct |
109 ms |
127352 KB |
Output is correct |
7 |
Correct |
108 ms |
127480 KB |
Output is correct |
8 |
Correct |
111 ms |
127372 KB |
Output is correct |
9 |
Correct |
111 ms |
127608 KB |
Output is correct |
10 |
Correct |
110 ms |
127352 KB |
Output is correct |
11 |
Correct |
110 ms |
127224 KB |
Output is correct |
12 |
Correct |
113 ms |
127224 KB |
Output is correct |
13 |
Correct |
112 ms |
127224 KB |
Output is correct |
14 |
Correct |
109 ms |
127224 KB |
Output is correct |
15 |
Correct |
109 ms |
127352 KB |
Output is correct |
16 |
Correct |
111 ms |
127448 KB |
Output is correct |
17 |
Correct |
111 ms |
127404 KB |
Output is correct |
18 |
Correct |
108 ms |
127408 KB |
Output is correct |
19 |
Correct |
111 ms |
127416 KB |
Output is correct |
20 |
Correct |
115 ms |
127352 KB |
Output is correct |
21 |
Correct |
110 ms |
127352 KB |
Output is correct |
22 |
Correct |
114 ms |
127552 KB |
Output is correct |
23 |
Correct |
124 ms |
127536 KB |
Output is correct |
24 |
Correct |
111 ms |
127364 KB |
Output is correct |
25 |
Correct |
114 ms |
127256 KB |
Output is correct |
26 |
Correct |
157 ms |
127352 KB |
Output is correct |
27 |
Correct |
110 ms |
127292 KB |
Output is correct |
28 |
Correct |
109 ms |
127248 KB |
Output is correct |
29 |
Correct |
112 ms |
127332 KB |
Output is correct |
30 |
Correct |
108 ms |
127256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
127224 KB |
Output is correct |
2 |
Correct |
112 ms |
127144 KB |
Output is correct |
3 |
Correct |
108 ms |
127348 KB |
Output is correct |
4 |
Correct |
110 ms |
127364 KB |
Output is correct |
5 |
Correct |
164 ms |
127268 KB |
Output is correct |
6 |
Correct |
109 ms |
127352 KB |
Output is correct |
7 |
Correct |
108 ms |
127480 KB |
Output is correct |
8 |
Correct |
111 ms |
127372 KB |
Output is correct |
9 |
Correct |
111 ms |
127608 KB |
Output is correct |
10 |
Correct |
110 ms |
127352 KB |
Output is correct |
11 |
Correct |
110 ms |
127224 KB |
Output is correct |
12 |
Correct |
113 ms |
127224 KB |
Output is correct |
13 |
Correct |
112 ms |
127224 KB |
Output is correct |
14 |
Correct |
109 ms |
127224 KB |
Output is correct |
15 |
Correct |
109 ms |
127352 KB |
Output is correct |
16 |
Correct |
111 ms |
127448 KB |
Output is correct |
17 |
Correct |
111 ms |
127404 KB |
Output is correct |
18 |
Correct |
108 ms |
127408 KB |
Output is correct |
19 |
Correct |
111 ms |
127416 KB |
Output is correct |
20 |
Correct |
115 ms |
127352 KB |
Output is correct |
21 |
Correct |
110 ms |
127352 KB |
Output is correct |
22 |
Correct |
114 ms |
127552 KB |
Output is correct |
23 |
Correct |
124 ms |
127536 KB |
Output is correct |
24 |
Correct |
111 ms |
127364 KB |
Output is correct |
25 |
Correct |
114 ms |
127256 KB |
Output is correct |
26 |
Correct |
157 ms |
127352 KB |
Output is correct |
27 |
Correct |
110 ms |
127292 KB |
Output is correct |
28 |
Correct |
109 ms |
127248 KB |
Output is correct |
29 |
Correct |
112 ms |
127332 KB |
Output is correct |
30 |
Correct |
108 ms |
127256 KB |
Output is correct |
31 |
Correct |
3718 ms |
179256 KB |
Output is correct |
32 |
Correct |
2237 ms |
146596 KB |
Output is correct |
33 |
Correct |
1276 ms |
145544 KB |
Output is correct |
34 |
Correct |
3379 ms |
156172 KB |
Output is correct |
35 |
Correct |
2626 ms |
170708 KB |
Output is correct |
36 |
Correct |
1219 ms |
152696 KB |
Output is correct |
37 |
Correct |
885 ms |
140024 KB |
Output is correct |
38 |
Correct |
628 ms |
139096 KB |
Output is correct |
39 |
Correct |
510 ms |
138120 KB |
Output is correct |
40 |
Correct |
486 ms |
138088 KB |
Output is correct |
41 |
Correct |
1355 ms |
138992 KB |
Output is correct |
42 |
Correct |
1355 ms |
139128 KB |
Output is correct |
43 |
Correct |
318 ms |
136556 KB |
Output is correct |
44 |
Correct |
1317 ms |
138888 KB |
Output is correct |
45 |
Correct |
1035 ms |
138480 KB |
Output is correct |
46 |
Correct |
731 ms |
138200 KB |
Output is correct |
47 |
Correct |
473 ms |
137772 KB |
Output is correct |
48 |
Correct |
450 ms |
137676 KB |
Output is correct |
49 |
Correct |
621 ms |
138000 KB |
Output is correct |
50 |
Correct |
977 ms |
138580 KB |
Output is correct |
51 |
Correct |
592 ms |
137980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5025 ms |
312100 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5026 ms |
273540 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
127224 KB |
Output is correct |
2 |
Correct |
112 ms |
127144 KB |
Output is correct |
3 |
Correct |
108 ms |
127348 KB |
Output is correct |
4 |
Correct |
110 ms |
127364 KB |
Output is correct |
5 |
Correct |
164 ms |
127268 KB |
Output is correct |
6 |
Correct |
109 ms |
127352 KB |
Output is correct |
7 |
Correct |
108 ms |
127480 KB |
Output is correct |
8 |
Correct |
111 ms |
127372 KB |
Output is correct |
9 |
Correct |
111 ms |
127608 KB |
Output is correct |
10 |
Correct |
110 ms |
127352 KB |
Output is correct |
11 |
Correct |
110 ms |
127224 KB |
Output is correct |
12 |
Correct |
113 ms |
127224 KB |
Output is correct |
13 |
Correct |
112 ms |
127224 KB |
Output is correct |
14 |
Correct |
109 ms |
127224 KB |
Output is correct |
15 |
Correct |
109 ms |
127352 KB |
Output is correct |
16 |
Correct |
111 ms |
127448 KB |
Output is correct |
17 |
Correct |
111 ms |
127404 KB |
Output is correct |
18 |
Correct |
108 ms |
127408 KB |
Output is correct |
19 |
Correct |
111 ms |
127416 KB |
Output is correct |
20 |
Correct |
115 ms |
127352 KB |
Output is correct |
21 |
Correct |
110 ms |
127352 KB |
Output is correct |
22 |
Correct |
114 ms |
127552 KB |
Output is correct |
23 |
Correct |
124 ms |
127536 KB |
Output is correct |
24 |
Correct |
111 ms |
127364 KB |
Output is correct |
25 |
Correct |
114 ms |
127256 KB |
Output is correct |
26 |
Correct |
157 ms |
127352 KB |
Output is correct |
27 |
Correct |
110 ms |
127292 KB |
Output is correct |
28 |
Correct |
109 ms |
127248 KB |
Output is correct |
29 |
Correct |
112 ms |
127332 KB |
Output is correct |
30 |
Correct |
108 ms |
127256 KB |
Output is correct |
31 |
Correct |
3718 ms |
179256 KB |
Output is correct |
32 |
Correct |
2237 ms |
146596 KB |
Output is correct |
33 |
Correct |
1276 ms |
145544 KB |
Output is correct |
34 |
Correct |
3379 ms |
156172 KB |
Output is correct |
35 |
Correct |
2626 ms |
170708 KB |
Output is correct |
36 |
Correct |
1219 ms |
152696 KB |
Output is correct |
37 |
Correct |
885 ms |
140024 KB |
Output is correct |
38 |
Correct |
628 ms |
139096 KB |
Output is correct |
39 |
Correct |
510 ms |
138120 KB |
Output is correct |
40 |
Correct |
486 ms |
138088 KB |
Output is correct |
41 |
Correct |
1355 ms |
138992 KB |
Output is correct |
42 |
Correct |
1355 ms |
139128 KB |
Output is correct |
43 |
Correct |
318 ms |
136556 KB |
Output is correct |
44 |
Correct |
1317 ms |
138888 KB |
Output is correct |
45 |
Correct |
1035 ms |
138480 KB |
Output is correct |
46 |
Correct |
731 ms |
138200 KB |
Output is correct |
47 |
Correct |
473 ms |
137772 KB |
Output is correct |
48 |
Correct |
450 ms |
137676 KB |
Output is correct |
49 |
Correct |
621 ms |
138000 KB |
Output is correct |
50 |
Correct |
977 ms |
138580 KB |
Output is correct |
51 |
Correct |
592 ms |
137980 KB |
Output is correct |
52 |
Correct |
2797 ms |
214492 KB |
Output is correct |
53 |
Correct |
2541 ms |
189504 KB |
Output is correct |
54 |
Correct |
4481 ms |
207972 KB |
Output is correct |
55 |
Correct |
2481 ms |
164972 KB |
Output is correct |
56 |
Correct |
2570 ms |
177840 KB |
Output is correct |
57 |
Correct |
2126 ms |
146804 KB |
Output is correct |
58 |
Correct |
2650 ms |
165360 KB |
Output is correct |
59 |
Correct |
2706 ms |
178420 KB |
Output is correct |
60 |
Correct |
2253 ms |
147116 KB |
Output is correct |
61 |
Correct |
890 ms |
173040 KB |
Output is correct |
62 |
Correct |
2872 ms |
214256 KB |
Output is correct |
63 |
Correct |
3827 ms |
199676 KB |
Output is correct |
64 |
Correct |
4090 ms |
186944 KB |
Output is correct |
65 |
Correct |
3849 ms |
154580 KB |
Output is correct |
66 |
Correct |
1508 ms |
140004 KB |
Output is correct |
67 |
Execution timed out |
5031 ms |
148988 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
127224 KB |
Output is correct |
2 |
Correct |
112 ms |
127144 KB |
Output is correct |
3 |
Correct |
108 ms |
127348 KB |
Output is correct |
4 |
Correct |
110 ms |
127364 KB |
Output is correct |
5 |
Correct |
164 ms |
127268 KB |
Output is correct |
6 |
Correct |
109 ms |
127352 KB |
Output is correct |
7 |
Correct |
108 ms |
127480 KB |
Output is correct |
8 |
Correct |
111 ms |
127372 KB |
Output is correct |
9 |
Correct |
111 ms |
127608 KB |
Output is correct |
10 |
Correct |
110 ms |
127352 KB |
Output is correct |
11 |
Correct |
110 ms |
127224 KB |
Output is correct |
12 |
Correct |
113 ms |
127224 KB |
Output is correct |
13 |
Correct |
112 ms |
127224 KB |
Output is correct |
14 |
Correct |
109 ms |
127224 KB |
Output is correct |
15 |
Correct |
109 ms |
127352 KB |
Output is correct |
16 |
Correct |
111 ms |
127448 KB |
Output is correct |
17 |
Correct |
111 ms |
127404 KB |
Output is correct |
18 |
Correct |
108 ms |
127408 KB |
Output is correct |
19 |
Correct |
111 ms |
127416 KB |
Output is correct |
20 |
Correct |
115 ms |
127352 KB |
Output is correct |
21 |
Correct |
110 ms |
127352 KB |
Output is correct |
22 |
Correct |
114 ms |
127552 KB |
Output is correct |
23 |
Correct |
124 ms |
127536 KB |
Output is correct |
24 |
Correct |
111 ms |
127364 KB |
Output is correct |
25 |
Correct |
114 ms |
127256 KB |
Output is correct |
26 |
Correct |
157 ms |
127352 KB |
Output is correct |
27 |
Correct |
110 ms |
127292 KB |
Output is correct |
28 |
Correct |
109 ms |
127248 KB |
Output is correct |
29 |
Correct |
112 ms |
127332 KB |
Output is correct |
30 |
Correct |
108 ms |
127256 KB |
Output is correct |
31 |
Correct |
3718 ms |
179256 KB |
Output is correct |
32 |
Correct |
2237 ms |
146596 KB |
Output is correct |
33 |
Correct |
1276 ms |
145544 KB |
Output is correct |
34 |
Correct |
3379 ms |
156172 KB |
Output is correct |
35 |
Correct |
2626 ms |
170708 KB |
Output is correct |
36 |
Correct |
1219 ms |
152696 KB |
Output is correct |
37 |
Correct |
885 ms |
140024 KB |
Output is correct |
38 |
Correct |
628 ms |
139096 KB |
Output is correct |
39 |
Correct |
510 ms |
138120 KB |
Output is correct |
40 |
Correct |
486 ms |
138088 KB |
Output is correct |
41 |
Correct |
1355 ms |
138992 KB |
Output is correct |
42 |
Correct |
1355 ms |
139128 KB |
Output is correct |
43 |
Correct |
318 ms |
136556 KB |
Output is correct |
44 |
Correct |
1317 ms |
138888 KB |
Output is correct |
45 |
Correct |
1035 ms |
138480 KB |
Output is correct |
46 |
Correct |
731 ms |
138200 KB |
Output is correct |
47 |
Correct |
473 ms |
137772 KB |
Output is correct |
48 |
Correct |
450 ms |
137676 KB |
Output is correct |
49 |
Correct |
621 ms |
138000 KB |
Output is correct |
50 |
Correct |
977 ms |
138580 KB |
Output is correct |
51 |
Correct |
592 ms |
137980 KB |
Output is correct |
52 |
Execution timed out |
5025 ms |
312100 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |