# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
60960 |
2018-07-25T04:23:55 Z |
ainta(#1756) |
Abduction 2 (JOI17_abduction2) |
C++11 |
|
4331 ms |
274988 KB |
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#define N_ 51000
#define SZ 65536
using namespace std;
int n, m, Q;
map<long long, long long>Map;
int X[N_], Y[N_];
long long Num(int x, int y, int dir) {
return ((((long long)x << 16) + y) << 2) + dir;
}
struct Tree {
int M[SZ+SZ];
void Put(int a, int b) {
a += SZ;
M[a] = b;
while (a != 1) {
a >>= 1;
M[a] = max(M[a * 2], M[a * 2 + 1]);
}
}
int Before(int a, int g) {
int b = SZ, e = a + SZ - 1, r = 0;
while (b <= e) {
if (M[e] > g) {
r = e;
break;
}
b = (b + 1) >> 1, e = (e - 1) >> 1;
}
if (r == 0)return r;
while (r < SZ) {
r *= 2;
if (M[r + 1] > g)r++;
}
return r - SZ;
}
int Next(int a, int g) {
int b = a + SZ + 1, e = SZ + SZ - 1, r = 1e9;
while (b <= e) {
if (M[b] > g) {
r = b;
break;
}
b = (b + 1) >> 1, e = (e - 1) >> 1;
}
if (r > 8e8)return r;
while (r < SZ) {
r *= 2;
if (M[r] <= g)r++;
}
return r - SZ;
}
}IT[2];
int Calc(int x, int y, int dir) {
if (dir == 0)return x - 1;
if (dir == 1)return n - x;
if (dir == 2)return y - 1;
if (dir == 3)return m - y;
}
long long Get(int x, int y, int dir) {
long long tp = Num(x, y, dir);
if (Map.count(tp))return Map[tp];
if (x == 2 && y == 2 && dir == 1) {
int ck = -1;
}
int t;
if (dir == 0) t = IT[0].Before(x, Y[y]);
if (dir == 1) t = IT[0].Next(x, Y[y]);
if (dir == 2) t = IT[1].Before(y, X[x]);
if (dir == 3) t = IT[1].Next(y, X[x]);
long long Mn = 0;
if (t<1 || t>1e6) {
Map[tp] = Calc(x, y, dir);
return Map[tp];
}
if (dir == 0 || dir == 1) {
Mn = max(Mn, Get(t, y, 2) + abs(t - x));
Mn = max(Mn, Get(t, y, 3) + abs(t - x));
}
else {
Mn = max(Mn, Get(x, t, 0) + abs(t - y));
Mn = max(Mn, Get(x, t, 1) + abs(t - y));
}
Map[tp] = Mn;
return Mn;
}
int main() {
int i, x, y;
scanf("%d%d%d", &n, &m, &Q);
for (i = 1; i <= n; i++) {
scanf("%d", &X[i]);
IT[0].Put(i, X[i]);
}
for (i = 1; i <= m; i++) {
scanf("%d", &Y[i]);
IT[1].Put(i, Y[i]);
}
while (Q--) {
scanf("%d%d", &x, &y);
long long Mn = 0;
for (i = 0; i < 4; i++) {
Mn = max(Mn, Get(x, y, i));
}
printf("%lld\n", Mn);
}
}
Compilation message
abduction2.cpp: In function 'long long int Get(int, int, int)':
abduction2.cpp:67:7: warning: unused variable 'ck' [-Wunused-variable]
int ck = -1;
^~
abduction2.cpp: In function 'int Calc(int, int, int)':
abduction2.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
abduction2.cpp: In function 'int main()':
abduction2.cpp:92:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &n, &m, &Q);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
abduction2.cpp:94:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &X[i]);
~~~~~^~~~~~~~~~~~~
abduction2.cpp:98:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &Y[i]);
~~~~~^~~~~~~~~~~~~
abduction2.cpp:102:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &x, &y);
~~~~~^~~~~~~~~~~~~~~~
abduction2.cpp: In function 'long long int Get(int, int, int)':
abduction2.cpp:75:2: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (t<1 || t>1e6) {
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
400 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
2 ms |
644 KB |
Output is correct |
6 |
Correct |
2 ms |
644 KB |
Output is correct |
7 |
Correct |
2 ms |
736 KB |
Output is correct |
8 |
Correct |
3 ms |
736 KB |
Output is correct |
9 |
Correct |
3 ms |
736 KB |
Output is correct |
10 |
Correct |
3 ms |
736 KB |
Output is correct |
11 |
Correct |
3 ms |
736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
400 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
2 ms |
644 KB |
Output is correct |
6 |
Correct |
2 ms |
644 KB |
Output is correct |
7 |
Correct |
2 ms |
736 KB |
Output is correct |
8 |
Correct |
3 ms |
736 KB |
Output is correct |
9 |
Correct |
3 ms |
736 KB |
Output is correct |
10 |
Correct |
3 ms |
736 KB |
Output is correct |
11 |
Correct |
3 ms |
736 KB |
Output is correct |
12 |
Correct |
6 ms |
888 KB |
Output is correct |
13 |
Correct |
4 ms |
928 KB |
Output is correct |
14 |
Correct |
4 ms |
984 KB |
Output is correct |
15 |
Correct |
5 ms |
1024 KB |
Output is correct |
16 |
Correct |
4 ms |
1080 KB |
Output is correct |
17 |
Correct |
3 ms |
1124 KB |
Output is correct |
18 |
Correct |
4 ms |
1176 KB |
Output is correct |
19 |
Correct |
8 ms |
1476 KB |
Output is correct |
20 |
Correct |
9 ms |
1772 KB |
Output is correct |
21 |
Correct |
7 ms |
1772 KB |
Output is correct |
22 |
Correct |
12 ms |
2108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
400 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
2 ms |
644 KB |
Output is correct |
6 |
Correct |
2 ms |
644 KB |
Output is correct |
7 |
Correct |
2 ms |
736 KB |
Output is correct |
8 |
Correct |
3 ms |
736 KB |
Output is correct |
9 |
Correct |
3 ms |
736 KB |
Output is correct |
10 |
Correct |
3 ms |
736 KB |
Output is correct |
11 |
Correct |
3 ms |
736 KB |
Output is correct |
12 |
Correct |
6 ms |
888 KB |
Output is correct |
13 |
Correct |
4 ms |
928 KB |
Output is correct |
14 |
Correct |
4 ms |
984 KB |
Output is correct |
15 |
Correct |
5 ms |
1024 KB |
Output is correct |
16 |
Correct |
4 ms |
1080 KB |
Output is correct |
17 |
Correct |
3 ms |
1124 KB |
Output is correct |
18 |
Correct |
4 ms |
1176 KB |
Output is correct |
19 |
Correct |
8 ms |
1476 KB |
Output is correct |
20 |
Correct |
9 ms |
1772 KB |
Output is correct |
21 |
Correct |
7 ms |
1772 KB |
Output is correct |
22 |
Correct |
12 ms |
2108 KB |
Output is correct |
23 |
Correct |
29 ms |
3368 KB |
Output is correct |
24 |
Correct |
37 ms |
4404 KB |
Output is correct |
25 |
Correct |
32 ms |
5340 KB |
Output is correct |
26 |
Correct |
31 ms |
6336 KB |
Output is correct |
27 |
Correct |
36 ms |
7220 KB |
Output is correct |
28 |
Correct |
66 ms |
14292 KB |
Output is correct |
29 |
Correct |
37 ms |
14292 KB |
Output is correct |
30 |
Correct |
153 ms |
20728 KB |
Output is correct |
31 |
Correct |
204 ms |
24704 KB |
Output is correct |
32 |
Correct |
36 ms |
24704 KB |
Output is correct |
33 |
Correct |
86 ms |
24704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
24704 KB |
Output is correct |
2 |
Correct |
7 ms |
24704 KB |
Output is correct |
3 |
Correct |
8 ms |
24704 KB |
Output is correct |
4 |
Correct |
9 ms |
24704 KB |
Output is correct |
5 |
Correct |
9 ms |
24704 KB |
Output is correct |
6 |
Correct |
8 ms |
24704 KB |
Output is correct |
7 |
Correct |
7 ms |
24704 KB |
Output is correct |
8 |
Correct |
13 ms |
24704 KB |
Output is correct |
9 |
Correct |
14 ms |
24704 KB |
Output is correct |
10 |
Correct |
14 ms |
24704 KB |
Output is correct |
11 |
Correct |
13 ms |
24704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
400 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
2 ms |
644 KB |
Output is correct |
6 |
Correct |
2 ms |
644 KB |
Output is correct |
7 |
Correct |
2 ms |
736 KB |
Output is correct |
8 |
Correct |
3 ms |
736 KB |
Output is correct |
9 |
Correct |
3 ms |
736 KB |
Output is correct |
10 |
Correct |
3 ms |
736 KB |
Output is correct |
11 |
Correct |
3 ms |
736 KB |
Output is correct |
12 |
Correct |
6 ms |
888 KB |
Output is correct |
13 |
Correct |
4 ms |
928 KB |
Output is correct |
14 |
Correct |
4 ms |
984 KB |
Output is correct |
15 |
Correct |
5 ms |
1024 KB |
Output is correct |
16 |
Correct |
4 ms |
1080 KB |
Output is correct |
17 |
Correct |
3 ms |
1124 KB |
Output is correct |
18 |
Correct |
4 ms |
1176 KB |
Output is correct |
19 |
Correct |
8 ms |
1476 KB |
Output is correct |
20 |
Correct |
9 ms |
1772 KB |
Output is correct |
21 |
Correct |
7 ms |
1772 KB |
Output is correct |
22 |
Correct |
12 ms |
2108 KB |
Output is correct |
23 |
Correct |
29 ms |
3368 KB |
Output is correct |
24 |
Correct |
37 ms |
4404 KB |
Output is correct |
25 |
Correct |
32 ms |
5340 KB |
Output is correct |
26 |
Correct |
31 ms |
6336 KB |
Output is correct |
27 |
Correct |
36 ms |
7220 KB |
Output is correct |
28 |
Correct |
66 ms |
14292 KB |
Output is correct |
29 |
Correct |
37 ms |
14292 KB |
Output is correct |
30 |
Correct |
153 ms |
20728 KB |
Output is correct |
31 |
Correct |
204 ms |
24704 KB |
Output is correct |
32 |
Correct |
36 ms |
24704 KB |
Output is correct |
33 |
Correct |
86 ms |
24704 KB |
Output is correct |
34 |
Correct |
8 ms |
24704 KB |
Output is correct |
35 |
Correct |
7 ms |
24704 KB |
Output is correct |
36 |
Correct |
8 ms |
24704 KB |
Output is correct |
37 |
Correct |
9 ms |
24704 KB |
Output is correct |
38 |
Correct |
9 ms |
24704 KB |
Output is correct |
39 |
Correct |
8 ms |
24704 KB |
Output is correct |
40 |
Correct |
7 ms |
24704 KB |
Output is correct |
41 |
Correct |
13 ms |
24704 KB |
Output is correct |
42 |
Correct |
14 ms |
24704 KB |
Output is correct |
43 |
Correct |
14 ms |
24704 KB |
Output is correct |
44 |
Correct |
13 ms |
24704 KB |
Output is correct |
45 |
Correct |
43 ms |
24704 KB |
Output is correct |
46 |
Correct |
45 ms |
24704 KB |
Output is correct |
47 |
Correct |
50 ms |
24704 KB |
Output is correct |
48 |
Correct |
47 ms |
24704 KB |
Output is correct |
49 |
Correct |
53 ms |
24704 KB |
Output is correct |
50 |
Correct |
70 ms |
26132 KB |
Output is correct |
51 |
Correct |
78 ms |
27720 KB |
Output is correct |
52 |
Correct |
235 ms |
40268 KB |
Output is correct |
53 |
Correct |
245 ms |
40644 KB |
Output is correct |
54 |
Correct |
240 ms |
40644 KB |
Output is correct |
55 |
Correct |
489 ms |
50384 KB |
Output is correct |
56 |
Correct |
4331 ms |
274988 KB |
Output is correct |
57 |
Correct |
792 ms |
274988 KB |
Output is correct |
58 |
Correct |
772 ms |
274988 KB |
Output is correct |
59 |
Correct |
826 ms |
274988 KB |
Output is correct |