#include<stdio.h>
#include<memory.h>
#include<algorithm>
#include<map>
using namespace std;
typedef long long lld;
struct seg {
lld j2, itr[150000];
seg(){ j2 = 1<<16; memset(itr, 0x3f, sizeof(itr)); }
const lld& operator[] (const lld ix){ return itr[j2+ix]; }
void add(lld ix, lld val){
ix+=j2; itr[ix]=val;
for(ix>>=1; ix; ix>>=1) itr[ix]=max(itr[ix*2],itr[ix*2+1]);
}
lld getup(lld ix, lld val){
ix+=j2;
while(1){
if(itr[ix]>val){
if(ix>=j2) break;
if(itr[ix*2]>val) ix*=2;
else ix*=2, ix++;
}
else{
if(ix%2) ix++;
else ix>>=1;
}
}
return ix-j2;
}
lld getdown(lld ix, lld val){
ix+=j2;
while(1){
if(itr[ix]>val){
if(ix>=j2) break;
if(itr[ix*2+1]>val) ix*=2, ix++;
else ix*=2;
}
else{
if(ix%2 == 0) ix--;
else ix>>=1;
}
}
return ix-j2;
}
} ho, ver;
lld H, W, Q;
map<pair<lld,lld>, lld> vd, hd;
lld verti(lld, lld);
lld hori(lld, lld);
lld verti(lld h, lld v){
lld gap = vd[make_pair(h,v)];
if(gap) return gap;
lld up=0, down=0;
up = ho.getup(h+1, ver[v]);
if(up<=H) up = up-h + hori(v, up);
else up = H-h;
down = ho.getdown(h-1, ver[v]);
if(down>=1) down = h-down + hori(v, down);
else down = h-1;
return vd[make_pair(h,v)] = max(up, down);
}
lld hori(lld v, lld h){
lld gap = hd[make_pair(h,v)];
if(gap) return gap;
lld up=0, down=0;
up = ver.getup(v+1, ho[h]);
if(up<=W) up = up-v + verti(h, up);
else up = W-v;
down = ver.getdown(v-1, ho[h]);
if(down>=1) down = v-down + verti(h, down);
else down = v-1;
return hd[make_pair(h,v)] = max(up, down);
}
int main(){
scanf("%lld%lld%lld", &H, &W, &Q);
for(lld i=1; i<=H; i++){
lld a; scanf("%d", &a);
ho.add(i, a);
}
for(lld i=1; i<=W; i++){
lld a; scanf("%lld", &a);
ver.add(i, a);
}
while(Q--){
lld h, v;
scanf("%lld%lld", &h, &v);
printf("%lld\n", max(verti(h, v), hori(v, h)));
}
return 0;
}
Compilation message
abduction2.cpp: In function 'int main()':
abduction2.cpp:87:24: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'lld* {aka long long int*}' [-Wformat=]
lld a; scanf("%d", &a);
^
abduction2.cpp:85:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld", &H, &W, &Q);
^
abduction2.cpp:87:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
lld a; scanf("%d", &a);
^
abduction2.cpp:91:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
lld a; scanf("%lld", &a);
^
abduction2.cpp:96:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &h, &v);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3520 KB |
Output is correct |
2 |
Correct |
0 ms |
3520 KB |
Output is correct |
3 |
Correct |
0 ms |
3520 KB |
Output is correct |
4 |
Correct |
0 ms |
3520 KB |
Output is correct |
5 |
Correct |
0 ms |
3520 KB |
Output is correct |
6 |
Correct |
0 ms |
3520 KB |
Output is correct |
7 |
Correct |
0 ms |
3520 KB |
Output is correct |
8 |
Correct |
0 ms |
3520 KB |
Output is correct |
9 |
Correct |
0 ms |
3520 KB |
Output is correct |
10 |
Correct |
0 ms |
3520 KB |
Output is correct |
11 |
Correct |
0 ms |
3520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3520 KB |
Output is correct |
2 |
Correct |
0 ms |
3520 KB |
Output is correct |
3 |
Correct |
0 ms |
3520 KB |
Output is correct |
4 |
Correct |
0 ms |
3520 KB |
Output is correct |
5 |
Correct |
0 ms |
3520 KB |
Output is correct |
6 |
Correct |
0 ms |
3520 KB |
Output is correct |
7 |
Correct |
0 ms |
3520 KB |
Output is correct |
8 |
Correct |
0 ms |
3520 KB |
Output is correct |
9 |
Correct |
0 ms |
3520 KB |
Output is correct |
10 |
Correct |
0 ms |
3520 KB |
Output is correct |
11 |
Correct |
0 ms |
3520 KB |
Output is correct |
12 |
Correct |
0 ms |
3520 KB |
Output is correct |
13 |
Correct |
3 ms |
3520 KB |
Output is correct |
14 |
Correct |
3 ms |
3520 KB |
Output is correct |
15 |
Correct |
3 ms |
3520 KB |
Output is correct |
16 |
Correct |
3 ms |
3520 KB |
Output is correct |
17 |
Correct |
0 ms |
3520 KB |
Output is correct |
18 |
Correct |
3 ms |
3520 KB |
Output is correct |
19 |
Correct |
0 ms |
3652 KB |
Output is correct |
20 |
Correct |
3 ms |
3784 KB |
Output is correct |
21 |
Correct |
3 ms |
3784 KB |
Output is correct |
22 |
Correct |
6 ms |
3916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3520 KB |
Output is correct |
2 |
Correct |
0 ms |
3520 KB |
Output is correct |
3 |
Correct |
0 ms |
3520 KB |
Output is correct |
4 |
Correct |
0 ms |
3520 KB |
Output is correct |
5 |
Correct |
0 ms |
3520 KB |
Output is correct |
6 |
Correct |
0 ms |
3520 KB |
Output is correct |
7 |
Correct |
0 ms |
3520 KB |
Output is correct |
8 |
Correct |
0 ms |
3520 KB |
Output is correct |
9 |
Correct |
0 ms |
3520 KB |
Output is correct |
10 |
Correct |
0 ms |
3520 KB |
Output is correct |
11 |
Correct |
0 ms |
3520 KB |
Output is correct |
12 |
Correct |
0 ms |
3520 KB |
Output is correct |
13 |
Correct |
3 ms |
3520 KB |
Output is correct |
14 |
Correct |
3 ms |
3520 KB |
Output is correct |
15 |
Correct |
3 ms |
3520 KB |
Output is correct |
16 |
Correct |
3 ms |
3520 KB |
Output is correct |
17 |
Correct |
0 ms |
3520 KB |
Output is correct |
18 |
Correct |
3 ms |
3520 KB |
Output is correct |
19 |
Correct |
0 ms |
3652 KB |
Output is correct |
20 |
Correct |
3 ms |
3784 KB |
Output is correct |
21 |
Correct |
3 ms |
3784 KB |
Output is correct |
22 |
Correct |
6 ms |
3916 KB |
Output is correct |
23 |
Correct |
16 ms |
3520 KB |
Output is correct |
24 |
Correct |
26 ms |
3520 KB |
Output is correct |
25 |
Correct |
19 ms |
3520 KB |
Output is correct |
26 |
Correct |
33 ms |
3520 KB |
Output is correct |
27 |
Correct |
23 ms |
3520 KB |
Output is correct |
28 |
Correct |
43 ms |
8068 KB |
Output is correct |
29 |
Correct |
26 ms |
4024 KB |
Output is correct |
30 |
Correct |
76 ms |
9388 KB |
Output is correct |
31 |
Correct |
99 ms |
11208 KB |
Output is correct |
32 |
Correct |
26 ms |
3784 KB |
Output is correct |
33 |
Correct |
36 ms |
5296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3652 KB |
Output is correct |
2 |
Correct |
0 ms |
3652 KB |
Output is correct |
3 |
Correct |
3 ms |
3652 KB |
Output is correct |
4 |
Correct |
3 ms |
3652 KB |
Output is correct |
5 |
Correct |
3 ms |
3652 KB |
Output is correct |
6 |
Correct |
3 ms |
3652 KB |
Output is correct |
7 |
Correct |
0 ms |
3652 KB |
Output is correct |
8 |
Correct |
3 ms |
3916 KB |
Output is correct |
9 |
Correct |
3 ms |
3916 KB |
Output is correct |
10 |
Correct |
3 ms |
3916 KB |
Output is correct |
11 |
Correct |
3 ms |
4048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3520 KB |
Output is correct |
2 |
Correct |
0 ms |
3520 KB |
Output is correct |
3 |
Correct |
0 ms |
3520 KB |
Output is correct |
4 |
Correct |
0 ms |
3520 KB |
Output is correct |
5 |
Correct |
0 ms |
3520 KB |
Output is correct |
6 |
Correct |
0 ms |
3520 KB |
Output is correct |
7 |
Correct |
0 ms |
3520 KB |
Output is correct |
8 |
Correct |
0 ms |
3520 KB |
Output is correct |
9 |
Correct |
0 ms |
3520 KB |
Output is correct |
10 |
Correct |
0 ms |
3520 KB |
Output is correct |
11 |
Correct |
0 ms |
3520 KB |
Output is correct |
12 |
Correct |
0 ms |
3520 KB |
Output is correct |
13 |
Correct |
3 ms |
3520 KB |
Output is correct |
14 |
Correct |
3 ms |
3520 KB |
Output is correct |
15 |
Correct |
3 ms |
3520 KB |
Output is correct |
16 |
Correct |
3 ms |
3520 KB |
Output is correct |
17 |
Correct |
0 ms |
3520 KB |
Output is correct |
18 |
Correct |
3 ms |
3520 KB |
Output is correct |
19 |
Correct |
0 ms |
3652 KB |
Output is correct |
20 |
Correct |
3 ms |
3784 KB |
Output is correct |
21 |
Correct |
3 ms |
3784 KB |
Output is correct |
22 |
Correct |
6 ms |
3916 KB |
Output is correct |
23 |
Correct |
16 ms |
3520 KB |
Output is correct |
24 |
Correct |
26 ms |
3520 KB |
Output is correct |
25 |
Correct |
19 ms |
3520 KB |
Output is correct |
26 |
Correct |
33 ms |
3520 KB |
Output is correct |
27 |
Correct |
23 ms |
3520 KB |
Output is correct |
28 |
Correct |
43 ms |
8068 KB |
Output is correct |
29 |
Correct |
26 ms |
4024 KB |
Output is correct |
30 |
Correct |
76 ms |
9388 KB |
Output is correct |
31 |
Correct |
99 ms |
11208 KB |
Output is correct |
32 |
Correct |
26 ms |
3784 KB |
Output is correct |
33 |
Correct |
36 ms |
5296 KB |
Output is correct |
34 |
Correct |
0 ms |
3652 KB |
Output is correct |
35 |
Correct |
0 ms |
3652 KB |
Output is correct |
36 |
Correct |
3 ms |
3652 KB |
Output is correct |
37 |
Correct |
3 ms |
3652 KB |
Output is correct |
38 |
Correct |
3 ms |
3652 KB |
Output is correct |
39 |
Correct |
3 ms |
3652 KB |
Output is correct |
40 |
Correct |
0 ms |
3652 KB |
Output is correct |
41 |
Correct |
3 ms |
3916 KB |
Output is correct |
42 |
Correct |
3 ms |
3916 KB |
Output is correct |
43 |
Correct |
3 ms |
3916 KB |
Output is correct |
44 |
Correct |
3 ms |
4048 KB |
Output is correct |
45 |
Correct |
26 ms |
3784 KB |
Output is correct |
46 |
Correct |
29 ms |
3784 KB |
Output is correct |
47 |
Correct |
33 ms |
3784 KB |
Output is correct |
48 |
Correct |
33 ms |
3784 KB |
Output is correct |
49 |
Correct |
26 ms |
3784 KB |
Output is correct |
50 |
Correct |
53 ms |
7656 KB |
Output is correct |
51 |
Correct |
43 ms |
8248 KB |
Output is correct |
52 |
Correct |
129 ms |
13460 KB |
Output is correct |
53 |
Correct |
123 ms |
13132 KB |
Output is correct |
54 |
Correct |
123 ms |
12608 KB |
Output is correct |
55 |
Correct |
196 ms |
17536 KB |
Output is correct |
56 |
Correct |
1393 ms |
128528 KB |
Output is correct |
57 |
Correct |
296 ms |
35936 KB |
Output is correct |
58 |
Correct |
299 ms |
34240 KB |
Output is correct |
59 |
Correct |
283 ms |
34112 KB |
Output is correct |