# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
48865 |
2018-05-19T10:59:58 Z |
kriii |
New Home (APIO18_new_home) |
C++17 |
|
5000 ms |
249856 KB |
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
using namespace std;
int N,K,Q;
int C,XP[1001001];
struct query{
int y,o,x,t;
bool operator <(const query &t)const{
if (y == t.y) return o < t.o;
return y < t.y;
};
}qs[900900]; int qc;
map<int, int> make[300300];
int ans[300300];
const int non = 500000000;
const int Z = 1<<20;
multiset<int> upc[Z];
multiset<int, greater<int> > downc[Z];
int up[Z*2],down[Z*2];
void push(int v, int u, int d, bool in)
{
int p = lower_bound(XP, XP+C, v) - XP;
{
int x = p;
if (in) upc[x].insert(u);
else upc[x].erase(upc[x].find(u));
if (upc[x].empty()) up[x+Z] = non;
else up[x+Z] = *upc[x].begin();
x = (x + Z) / 2;
while (x){
up[x] = min(up[x*2], up[x*2+1]);
x /= 2;
}
}
{
int x = p;
if (in) downc[x].insert(d);
else downc[x].erase(downc[x].find(d));
if (downc[x].empty()) down[x+Z] = -non;
else down[x+Z] = *downc[x].begin();
x = (x + Z) / 2;
while (x){
down[x] = max(down[x*2], down[x*2+1]);
x /= 2;
}
}
}
int out(int v)
{
int u = non, d = -non;
{
int x = lower_bound(XP,XP+C,v) - XP + Z, y = C-1 + Z;
while (x < y){
if (x & 1) u = min(u, up[x++]);
if (~y & 1) u = min(u, up[y--]);
x /= 2; y /= 2;
}
if (x == y) u = min(u, up[x]);
}
{
int x = Z, y = upper_bound(XP,XP+C,v) - XP + Z - 1;
while (x < y){
if (x & 1) d = max(d, down[x++]);
if (~y & 1) d = max(d, down[y--]);
x /= 2; y /= 2;
}
if (x == y) d = max(d, down[x]);
}
return max(v-u,-v+d);
}
void mt(int s, int e, bool in)
{
push((s+e)/2,s,e,in);
}
int main()
{
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);
x *= 2;
qs[qc++] = {a,0,x,t};
qs[qc++] = {b+1,0,x,-t};
}
for (int i=0;i<Q;i++){
int l,y; scanf ("%d %d",&l,&y);
l *= 2;
qs[qc++] = {y,1,l,i};
}
sort(qs,qs+qc);
for (int i=1;i<=K;i++){
make[i][-non] = make[i][non] = 1;
}
XP[C++] = -non;
XP[C++] = non;
XP[C++] = 0;
for (int i=0;i<qc;i++){
auto &q = qs[i];
if (q.o == 0){
int x = q.x;
if (q.t > 0){
int t = q.t;
int &c = make[t][x];
if (c == 0){
auto I = make[t].find(x);
auto J = I, K = I; J--; K++;
XP[C++] = (J->first + I->first) / 2;
XP[C++] = (I->first + K->first) / 2;
}
c++;
}
else{
int t = -q.t;
int &c = make[t][x];
if (c == 1){
auto I = make[t].find(x);
auto J = I, K = I; J--; K++;
XP[C++] = (J->first + K->first) / 2;
make[t].erase(I);
}
else c--;
}
}
}
sort(XP,XP+C);
C = unique(XP,XP+C) - XP;
int v = lower_bound(XP,XP+C,0) - XP;
for (int i=1;i<K;i++){
upc[v].insert(-non);
downc[v].insert(non);
}
mt(-non,non,true);
for (int i=1;i<Z*2;i++) up[i] = non, down[i] = -non;
int have = 0;
for (int i=0;i<qc;i++){
auto &q = qs[i];
if (q.o == 0){
int x = q.x;
if (q.t > 0){
int t = q.t;
if (make[t].size() == 2) have++;
int &c = make[t][x];
if (c == 0){
auto I = make[t].find(x);
auto J = I, K = I; J--; K++;
mt(J->first,K->first,false);
mt(J->first,I->first,true);
mt(I->first,K->first,true);
}
c++;
}
else{
int t = -q.t;
int &c = make[t][x];
if (c == 1){
auto I = make[t].find(x);
auto J = I, K = I; J--; K++;
mt(J->first,I->first,false);
mt(I->first,K->first,false);
mt(J->first,K->first,true);
make[t].erase(I);
if (make[t].size() == 2) have--;
}
else c--;
}
}
else{
ans[q.t] = have == K ? out(q.x) / 2 : -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:94:8: 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:96:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int x,t,a,b; scanf ("%d %d %d %d",&x,&t,&a,&b);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:102:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int l,y; scanf ("%d %d",&l,&y);
~~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
129400 KB |
Output is correct |
2 |
Correct |
116 ms |
129496 KB |
Output is correct |
3 |
Correct |
132 ms |
129496 KB |
Output is correct |
4 |
Correct |
112 ms |
129556 KB |
Output is correct |
5 |
Correct |
118 ms |
129556 KB |
Output is correct |
6 |
Correct |
116 ms |
129556 KB |
Output is correct |
7 |
Correct |
124 ms |
129684 KB |
Output is correct |
8 |
Correct |
124 ms |
129684 KB |
Output is correct |
9 |
Correct |
121 ms |
129684 KB |
Output is correct |
10 |
Correct |
126 ms |
129684 KB |
Output is correct |
11 |
Correct |
115 ms |
129684 KB |
Output is correct |
12 |
Correct |
120 ms |
129684 KB |
Output is correct |
13 |
Correct |
113 ms |
129748 KB |
Output is correct |
14 |
Correct |
120 ms |
129748 KB |
Output is correct |
15 |
Correct |
116 ms |
129748 KB |
Output is correct |
16 |
Correct |
139 ms |
129748 KB |
Output is correct |
17 |
Correct |
118 ms |
129748 KB |
Output is correct |
18 |
Correct |
115 ms |
129748 KB |
Output is correct |
19 |
Correct |
122 ms |
129748 KB |
Output is correct |
20 |
Correct |
113 ms |
129748 KB |
Output is correct |
21 |
Correct |
114 ms |
129764 KB |
Output is correct |
22 |
Correct |
115 ms |
129764 KB |
Output is correct |
23 |
Correct |
118 ms |
129764 KB |
Output is correct |
24 |
Correct |
137 ms |
129764 KB |
Output is correct |
25 |
Correct |
118 ms |
129764 KB |
Output is correct |
26 |
Correct |
115 ms |
129764 KB |
Output is correct |
27 |
Correct |
120 ms |
129764 KB |
Output is correct |
28 |
Correct |
106 ms |
129764 KB |
Output is correct |
29 |
Correct |
120 ms |
129764 KB |
Output is correct |
30 |
Correct |
115 ms |
129764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
129400 KB |
Output is correct |
2 |
Correct |
116 ms |
129496 KB |
Output is correct |
3 |
Correct |
132 ms |
129496 KB |
Output is correct |
4 |
Correct |
112 ms |
129556 KB |
Output is correct |
5 |
Correct |
118 ms |
129556 KB |
Output is correct |
6 |
Correct |
116 ms |
129556 KB |
Output is correct |
7 |
Correct |
124 ms |
129684 KB |
Output is correct |
8 |
Correct |
124 ms |
129684 KB |
Output is correct |
9 |
Correct |
121 ms |
129684 KB |
Output is correct |
10 |
Correct |
126 ms |
129684 KB |
Output is correct |
11 |
Correct |
115 ms |
129684 KB |
Output is correct |
12 |
Correct |
120 ms |
129684 KB |
Output is correct |
13 |
Correct |
113 ms |
129748 KB |
Output is correct |
14 |
Correct |
120 ms |
129748 KB |
Output is correct |
15 |
Correct |
116 ms |
129748 KB |
Output is correct |
16 |
Correct |
139 ms |
129748 KB |
Output is correct |
17 |
Correct |
118 ms |
129748 KB |
Output is correct |
18 |
Correct |
115 ms |
129748 KB |
Output is correct |
19 |
Correct |
122 ms |
129748 KB |
Output is correct |
20 |
Correct |
113 ms |
129748 KB |
Output is correct |
21 |
Correct |
114 ms |
129764 KB |
Output is correct |
22 |
Correct |
115 ms |
129764 KB |
Output is correct |
23 |
Correct |
118 ms |
129764 KB |
Output is correct |
24 |
Correct |
137 ms |
129764 KB |
Output is correct |
25 |
Correct |
118 ms |
129764 KB |
Output is correct |
26 |
Correct |
115 ms |
129764 KB |
Output is correct |
27 |
Correct |
120 ms |
129764 KB |
Output is correct |
28 |
Correct |
106 ms |
129764 KB |
Output is correct |
29 |
Correct |
120 ms |
129764 KB |
Output is correct |
30 |
Correct |
115 ms |
129764 KB |
Output is correct |
31 |
Correct |
909 ms |
142444 KB |
Output is correct |
32 |
Correct |
252 ms |
142444 KB |
Output is correct |
33 |
Correct |
758 ms |
142444 KB |
Output is correct |
34 |
Correct |
723 ms |
142444 KB |
Output is correct |
35 |
Correct |
696 ms |
142508 KB |
Output is correct |
36 |
Correct |
714 ms |
142508 KB |
Output is correct |
37 |
Correct |
554 ms |
142508 KB |
Output is correct |
38 |
Correct |
552 ms |
142508 KB |
Output is correct |
39 |
Correct |
453 ms |
142508 KB |
Output is correct |
40 |
Correct |
441 ms |
142508 KB |
Output is correct |
41 |
Correct |
559 ms |
142508 KB |
Output is correct |
42 |
Correct |
540 ms |
142508 KB |
Output is correct |
43 |
Correct |
241 ms |
142508 KB |
Output is correct |
44 |
Correct |
523 ms |
142508 KB |
Output is correct |
45 |
Correct |
539 ms |
142508 KB |
Output is correct |
46 |
Correct |
509 ms |
142508 KB |
Output is correct |
47 |
Correct |
302 ms |
142508 KB |
Output is correct |
48 |
Correct |
333 ms |
142508 KB |
Output is correct |
49 |
Correct |
366 ms |
142508 KB |
Output is correct |
50 |
Correct |
406 ms |
142508 KB |
Output is correct |
51 |
Correct |
383 ms |
142508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4205 ms |
204876 KB |
Output is correct |
2 |
Correct |
4359 ms |
204876 KB |
Output is correct |
3 |
Correct |
3232 ms |
249856 KB |
Output is correct |
4 |
Correct |
3799 ms |
249856 KB |
Output is correct |
5 |
Correct |
4150 ms |
249856 KB |
Output is correct |
6 |
Correct |
4209 ms |
249856 KB |
Output is correct |
7 |
Correct |
3137 ms |
249856 KB |
Output is correct |
8 |
Correct |
3206 ms |
249856 KB |
Output is correct |
9 |
Correct |
3207 ms |
249856 KB |
Output is correct |
10 |
Correct |
3768 ms |
249856 KB |
Output is correct |
11 |
Correct |
2453 ms |
249856 KB |
Output is correct |
12 |
Correct |
2246 ms |
249856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5030 ms |
249856 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
129400 KB |
Output is correct |
2 |
Correct |
116 ms |
129496 KB |
Output is correct |
3 |
Correct |
132 ms |
129496 KB |
Output is correct |
4 |
Correct |
112 ms |
129556 KB |
Output is correct |
5 |
Correct |
118 ms |
129556 KB |
Output is correct |
6 |
Correct |
116 ms |
129556 KB |
Output is correct |
7 |
Correct |
124 ms |
129684 KB |
Output is correct |
8 |
Correct |
124 ms |
129684 KB |
Output is correct |
9 |
Correct |
121 ms |
129684 KB |
Output is correct |
10 |
Correct |
126 ms |
129684 KB |
Output is correct |
11 |
Correct |
115 ms |
129684 KB |
Output is correct |
12 |
Correct |
120 ms |
129684 KB |
Output is correct |
13 |
Correct |
113 ms |
129748 KB |
Output is correct |
14 |
Correct |
120 ms |
129748 KB |
Output is correct |
15 |
Correct |
116 ms |
129748 KB |
Output is correct |
16 |
Correct |
139 ms |
129748 KB |
Output is correct |
17 |
Correct |
118 ms |
129748 KB |
Output is correct |
18 |
Correct |
115 ms |
129748 KB |
Output is correct |
19 |
Correct |
122 ms |
129748 KB |
Output is correct |
20 |
Correct |
113 ms |
129748 KB |
Output is correct |
21 |
Correct |
114 ms |
129764 KB |
Output is correct |
22 |
Correct |
115 ms |
129764 KB |
Output is correct |
23 |
Correct |
118 ms |
129764 KB |
Output is correct |
24 |
Correct |
137 ms |
129764 KB |
Output is correct |
25 |
Correct |
118 ms |
129764 KB |
Output is correct |
26 |
Correct |
115 ms |
129764 KB |
Output is correct |
27 |
Correct |
120 ms |
129764 KB |
Output is correct |
28 |
Correct |
106 ms |
129764 KB |
Output is correct |
29 |
Correct |
120 ms |
129764 KB |
Output is correct |
30 |
Correct |
115 ms |
129764 KB |
Output is correct |
31 |
Correct |
909 ms |
142444 KB |
Output is correct |
32 |
Correct |
252 ms |
142444 KB |
Output is correct |
33 |
Correct |
758 ms |
142444 KB |
Output is correct |
34 |
Correct |
723 ms |
142444 KB |
Output is correct |
35 |
Correct |
696 ms |
142508 KB |
Output is correct |
36 |
Correct |
714 ms |
142508 KB |
Output is correct |
37 |
Correct |
554 ms |
142508 KB |
Output is correct |
38 |
Correct |
552 ms |
142508 KB |
Output is correct |
39 |
Correct |
453 ms |
142508 KB |
Output is correct |
40 |
Correct |
441 ms |
142508 KB |
Output is correct |
41 |
Correct |
559 ms |
142508 KB |
Output is correct |
42 |
Correct |
540 ms |
142508 KB |
Output is correct |
43 |
Correct |
241 ms |
142508 KB |
Output is correct |
44 |
Correct |
523 ms |
142508 KB |
Output is correct |
45 |
Correct |
539 ms |
142508 KB |
Output is correct |
46 |
Correct |
509 ms |
142508 KB |
Output is correct |
47 |
Correct |
302 ms |
142508 KB |
Output is correct |
48 |
Correct |
333 ms |
142508 KB |
Output is correct |
49 |
Correct |
366 ms |
142508 KB |
Output is correct |
50 |
Correct |
406 ms |
142508 KB |
Output is correct |
51 |
Correct |
383 ms |
142508 KB |
Output is correct |
52 |
Correct |
790 ms |
249856 KB |
Output is correct |
53 |
Correct |
735 ms |
249856 KB |
Output is correct |
54 |
Correct |
780 ms |
249856 KB |
Output is correct |
55 |
Correct |
627 ms |
249856 KB |
Output is correct |
56 |
Correct |
631 ms |
249856 KB |
Output is correct |
57 |
Correct |
618 ms |
249856 KB |
Output is correct |
58 |
Correct |
675 ms |
249856 KB |
Output is correct |
59 |
Correct |
522 ms |
249856 KB |
Output is correct |
60 |
Correct |
686 ms |
249856 KB |
Output is correct |
61 |
Correct |
416 ms |
249856 KB |
Output is correct |
62 |
Correct |
727 ms |
249856 KB |
Output is correct |
63 |
Correct |
805 ms |
249856 KB |
Output is correct |
64 |
Correct |
719 ms |
249856 KB |
Output is correct |
65 |
Correct |
744 ms |
249856 KB |
Output is correct |
66 |
Correct |
544 ms |
249856 KB |
Output is correct |
67 |
Correct |
522 ms |
249856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
129400 KB |
Output is correct |
2 |
Correct |
116 ms |
129496 KB |
Output is correct |
3 |
Correct |
132 ms |
129496 KB |
Output is correct |
4 |
Correct |
112 ms |
129556 KB |
Output is correct |
5 |
Correct |
118 ms |
129556 KB |
Output is correct |
6 |
Correct |
116 ms |
129556 KB |
Output is correct |
7 |
Correct |
124 ms |
129684 KB |
Output is correct |
8 |
Correct |
124 ms |
129684 KB |
Output is correct |
9 |
Correct |
121 ms |
129684 KB |
Output is correct |
10 |
Correct |
126 ms |
129684 KB |
Output is correct |
11 |
Correct |
115 ms |
129684 KB |
Output is correct |
12 |
Correct |
120 ms |
129684 KB |
Output is correct |
13 |
Correct |
113 ms |
129748 KB |
Output is correct |
14 |
Correct |
120 ms |
129748 KB |
Output is correct |
15 |
Correct |
116 ms |
129748 KB |
Output is correct |
16 |
Correct |
139 ms |
129748 KB |
Output is correct |
17 |
Correct |
118 ms |
129748 KB |
Output is correct |
18 |
Correct |
115 ms |
129748 KB |
Output is correct |
19 |
Correct |
122 ms |
129748 KB |
Output is correct |
20 |
Correct |
113 ms |
129748 KB |
Output is correct |
21 |
Correct |
114 ms |
129764 KB |
Output is correct |
22 |
Correct |
115 ms |
129764 KB |
Output is correct |
23 |
Correct |
118 ms |
129764 KB |
Output is correct |
24 |
Correct |
137 ms |
129764 KB |
Output is correct |
25 |
Correct |
118 ms |
129764 KB |
Output is correct |
26 |
Correct |
115 ms |
129764 KB |
Output is correct |
27 |
Correct |
120 ms |
129764 KB |
Output is correct |
28 |
Correct |
106 ms |
129764 KB |
Output is correct |
29 |
Correct |
120 ms |
129764 KB |
Output is correct |
30 |
Correct |
115 ms |
129764 KB |
Output is correct |
31 |
Correct |
909 ms |
142444 KB |
Output is correct |
32 |
Correct |
252 ms |
142444 KB |
Output is correct |
33 |
Correct |
758 ms |
142444 KB |
Output is correct |
34 |
Correct |
723 ms |
142444 KB |
Output is correct |
35 |
Correct |
696 ms |
142508 KB |
Output is correct |
36 |
Correct |
714 ms |
142508 KB |
Output is correct |
37 |
Correct |
554 ms |
142508 KB |
Output is correct |
38 |
Correct |
552 ms |
142508 KB |
Output is correct |
39 |
Correct |
453 ms |
142508 KB |
Output is correct |
40 |
Correct |
441 ms |
142508 KB |
Output is correct |
41 |
Correct |
559 ms |
142508 KB |
Output is correct |
42 |
Correct |
540 ms |
142508 KB |
Output is correct |
43 |
Correct |
241 ms |
142508 KB |
Output is correct |
44 |
Correct |
523 ms |
142508 KB |
Output is correct |
45 |
Correct |
539 ms |
142508 KB |
Output is correct |
46 |
Correct |
509 ms |
142508 KB |
Output is correct |
47 |
Correct |
302 ms |
142508 KB |
Output is correct |
48 |
Correct |
333 ms |
142508 KB |
Output is correct |
49 |
Correct |
366 ms |
142508 KB |
Output is correct |
50 |
Correct |
406 ms |
142508 KB |
Output is correct |
51 |
Correct |
383 ms |
142508 KB |
Output is correct |
52 |
Correct |
4205 ms |
204876 KB |
Output is correct |
53 |
Correct |
4359 ms |
204876 KB |
Output is correct |
54 |
Correct |
3232 ms |
249856 KB |
Output is correct |
55 |
Correct |
3799 ms |
249856 KB |
Output is correct |
56 |
Correct |
4150 ms |
249856 KB |
Output is correct |
57 |
Correct |
4209 ms |
249856 KB |
Output is correct |
58 |
Correct |
3137 ms |
249856 KB |
Output is correct |
59 |
Correct |
3206 ms |
249856 KB |
Output is correct |
60 |
Correct |
3207 ms |
249856 KB |
Output is correct |
61 |
Correct |
3768 ms |
249856 KB |
Output is correct |
62 |
Correct |
2453 ms |
249856 KB |
Output is correct |
63 |
Correct |
2246 ms |
249856 KB |
Output is correct |
64 |
Execution timed out |
5030 ms |
249856 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |