#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
char c = getchar_unlocked();
int x = 0;
while (c < '0' || c > '9')
{
c = getchar_unlocked();
}
while (c >= '0' && c <= '9')
{
x = (x << 1) + (x << 3) + c - '0';
c = getchar_unlocked();
}
return x;
}
void phongbeo();
const int inf = 1e14;
const int mod2 = 1e9 + 7;
const int mod1 = 998244353;
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a, b, c;
};
struct id
{
int a, b, c, d;
};
struct ie
{
int a, b, c, d, e;
};
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, l, r, mid, l2, r2, center;
int i, s10, s12,k1,k2,s11;
int kk;
int el = 19;
main()
{
if(fopen(task".inp","r"))
{
fin(task);
fou(task);
}
NHP
/// cin>>s1;
///modwwe
phongbeo();
// checktime
}
int a[50001];
int b[50001];
struct SPT
{
int st[16][50001];
int f;
void init(int n,int a[])
{
f=n;
for(int i=1; i<=n; i++)
st[0][i]=a[i];
for(int i=1; i<16; i++)
for(int j=1; j+(1<<i)-1<=n; j++)
st[i][j]=max(st[i-1][j],st[i-1][j+(1<<(i-1))]);
}
int get_mx(int l,int r)
{
int k=31-__builtin_clz(r-l+1);
return max(st[k][l],st[k][r-(1<<k)+1]);
}
int get_left(int x,int y)
{
l2=1;
r2=x-1;
while(l2<=r2)
{
int mid=l2+r2>>1;
if(get_mx(mid,x-1)>y)
{
l2=mid+1;
}
else r2=mid-1;
}
return l2-1;
}
int get_right(int x,int y)
{
l2=x+1;
r2=f;
while(l2<=r2)
{
int mid=l2+r2>>1;
if(get_mx(x+1,mid)>y)r2=mid-1;
else l2=mid+1;
}
return r2+1;
}
} sp[2];
unordered_map<int,ll>dp[2][50001];
ll calc(int l ,int r,bool c)
{
if(l==0||l==n+1||r==0||r==m+1) return -1;
if(dp[c][l].find(r)!=dp[c][l].end()) return dp[c][l][r];
long long ss=0;
if(!c)
{
int ss2=sp[0].get_left(l,b[r]);
int ss3=sp[0].get_right(l,b[r]);
ss=max(calc(ss2,r,1)+l-ss2,calc(ss3,r,1)+ss3-l);
}
else
{
int ss2=sp[1].get_left(r,a[l]);
int ss3=sp[1].get_right(r,a[l]);
ss=max(calc(l,ss2,0)+r-ss2,calc(l,ss3,0)+ss3-r);
}
dp[c][l][r]=ss;
return ss;
}
void phongbeo()
{
n=scan();
m=scan();
k=scan();
for(int i=1; i<=n; i++)
a[i]=scan();
for(int j=1; j<=m; j++)
b[j]=scan();
sp[0].init(n,a);
sp[1].init(m,b);
for(int i=1; i<=k; i++)
{
s2=scan();
s3=scan();
cout<<max(calc(s2,s3,0),calc(s2,s3,1)),down
}
}
Compilation message
abduction2.cpp:36:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+14' to '2147483647' [-Woverflow]
36 | const int inf = 1e14;
| ^~~~
abduction2.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
67 | main()
| ^~~~
abduction2.cpp: In member function 'int SPT::get_left(int, int)':
abduction2.cpp:106:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
106 | int mid=l2+r2>>1;
| ~~^~~
abduction2.cpp: In member function 'int SPT::get_right(int, int)':
abduction2.cpp:121:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
121 | int mid=l2+r2>>1;
| ~~^~~
abduction2.cpp: In function 'int main()':
abduction2.cpp:12:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define fin(x) freopen(x".inp","r",stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
abduction2.cpp:71:9: note: in expansion of macro 'fin'
71 | fin(task);
| ^~~
abduction2.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define fou(x) freopen(x".out","w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
abduction2.cpp:72:9: note: in expansion of macro 'fou'
72 | fou(task);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
5976 KB |
Output is correct |
3 |
Correct |
2 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
5980 KB |
Output is correct |
5 |
Correct |
3 ms |
5980 KB |
Output is correct |
6 |
Correct |
2 ms |
5980 KB |
Output is correct |
7 |
Correct |
3 ms |
5976 KB |
Output is correct |
8 |
Correct |
2 ms |
5980 KB |
Output is correct |
9 |
Correct |
2 ms |
5980 KB |
Output is correct |
10 |
Correct |
3 ms |
5980 KB |
Output is correct |
11 |
Correct |
3 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
5976 KB |
Output is correct |
3 |
Correct |
2 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
5980 KB |
Output is correct |
5 |
Correct |
3 ms |
5980 KB |
Output is correct |
6 |
Correct |
2 ms |
5980 KB |
Output is correct |
7 |
Correct |
3 ms |
5976 KB |
Output is correct |
8 |
Correct |
2 ms |
5980 KB |
Output is correct |
9 |
Correct |
2 ms |
5980 KB |
Output is correct |
10 |
Correct |
3 ms |
5980 KB |
Output is correct |
11 |
Correct |
3 ms |
5980 KB |
Output is correct |
12 |
Correct |
3 ms |
6232 KB |
Output is correct |
13 |
Correct |
3 ms |
6236 KB |
Output is correct |
14 |
Correct |
3 ms |
6216 KB |
Output is correct |
15 |
Correct |
3 ms |
6236 KB |
Output is correct |
16 |
Correct |
3 ms |
6476 KB |
Output is correct |
17 |
Correct |
3 ms |
6232 KB |
Output is correct |
18 |
Correct |
3 ms |
6236 KB |
Output is correct |
19 |
Correct |
3 ms |
6492 KB |
Output is correct |
20 |
Correct |
5 ms |
6476 KB |
Output is correct |
21 |
Correct |
4 ms |
6492 KB |
Output is correct |
22 |
Correct |
4 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
5976 KB |
Output is correct |
3 |
Correct |
2 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
5980 KB |
Output is correct |
5 |
Correct |
3 ms |
5980 KB |
Output is correct |
6 |
Correct |
2 ms |
5980 KB |
Output is correct |
7 |
Correct |
3 ms |
5976 KB |
Output is correct |
8 |
Correct |
2 ms |
5980 KB |
Output is correct |
9 |
Correct |
2 ms |
5980 KB |
Output is correct |
10 |
Correct |
3 ms |
5980 KB |
Output is correct |
11 |
Correct |
3 ms |
5980 KB |
Output is correct |
12 |
Correct |
3 ms |
6232 KB |
Output is correct |
13 |
Correct |
3 ms |
6236 KB |
Output is correct |
14 |
Correct |
3 ms |
6216 KB |
Output is correct |
15 |
Correct |
3 ms |
6236 KB |
Output is correct |
16 |
Correct |
3 ms |
6476 KB |
Output is correct |
17 |
Correct |
3 ms |
6232 KB |
Output is correct |
18 |
Correct |
3 ms |
6236 KB |
Output is correct |
19 |
Correct |
3 ms |
6492 KB |
Output is correct |
20 |
Correct |
5 ms |
6476 KB |
Output is correct |
21 |
Correct |
4 ms |
6492 KB |
Output is correct |
22 |
Correct |
4 ms |
6748 KB |
Output is correct |
23 |
Correct |
8 ms |
12892 KB |
Output is correct |
24 |
Correct |
8 ms |
12892 KB |
Output is correct |
25 |
Correct |
8 ms |
12892 KB |
Output is correct |
26 |
Correct |
9 ms |
12892 KB |
Output is correct |
27 |
Correct |
9 ms |
12904 KB |
Output is correct |
28 |
Correct |
20 ms |
20648 KB |
Output is correct |
29 |
Correct |
10 ms |
14172 KB |
Output is correct |
30 |
Correct |
37 ms |
21128 KB |
Output is correct |
31 |
Correct |
43 ms |
23376 KB |
Output is correct |
32 |
Correct |
10 ms |
13400 KB |
Output is correct |
33 |
Correct |
15 ms |
15452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6236 KB |
Output is correct |
2 |
Correct |
4 ms |
6300 KB |
Output is correct |
3 |
Correct |
4 ms |
6316 KB |
Output is correct |
4 |
Correct |
5 ms |
6236 KB |
Output is correct |
5 |
Correct |
4 ms |
6236 KB |
Output is correct |
6 |
Correct |
4 ms |
6676 KB |
Output is correct |
7 |
Correct |
4 ms |
6492 KB |
Output is correct |
8 |
Correct |
6 ms |
6744 KB |
Output is correct |
9 |
Correct |
6 ms |
6744 KB |
Output is correct |
10 |
Correct |
5 ms |
6744 KB |
Output is correct |
11 |
Correct |
5 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
5976 KB |
Output is correct |
3 |
Correct |
2 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
5980 KB |
Output is correct |
5 |
Correct |
3 ms |
5980 KB |
Output is correct |
6 |
Correct |
2 ms |
5980 KB |
Output is correct |
7 |
Correct |
3 ms |
5976 KB |
Output is correct |
8 |
Correct |
2 ms |
5980 KB |
Output is correct |
9 |
Correct |
2 ms |
5980 KB |
Output is correct |
10 |
Correct |
3 ms |
5980 KB |
Output is correct |
11 |
Correct |
3 ms |
5980 KB |
Output is correct |
12 |
Correct |
3 ms |
6232 KB |
Output is correct |
13 |
Correct |
3 ms |
6236 KB |
Output is correct |
14 |
Correct |
3 ms |
6216 KB |
Output is correct |
15 |
Correct |
3 ms |
6236 KB |
Output is correct |
16 |
Correct |
3 ms |
6476 KB |
Output is correct |
17 |
Correct |
3 ms |
6232 KB |
Output is correct |
18 |
Correct |
3 ms |
6236 KB |
Output is correct |
19 |
Correct |
3 ms |
6492 KB |
Output is correct |
20 |
Correct |
5 ms |
6476 KB |
Output is correct |
21 |
Correct |
4 ms |
6492 KB |
Output is correct |
22 |
Correct |
4 ms |
6748 KB |
Output is correct |
23 |
Correct |
8 ms |
12892 KB |
Output is correct |
24 |
Correct |
8 ms |
12892 KB |
Output is correct |
25 |
Correct |
8 ms |
12892 KB |
Output is correct |
26 |
Correct |
9 ms |
12892 KB |
Output is correct |
27 |
Correct |
9 ms |
12904 KB |
Output is correct |
28 |
Correct |
20 ms |
20648 KB |
Output is correct |
29 |
Correct |
10 ms |
14172 KB |
Output is correct |
30 |
Correct |
37 ms |
21128 KB |
Output is correct |
31 |
Correct |
43 ms |
23376 KB |
Output is correct |
32 |
Correct |
10 ms |
13400 KB |
Output is correct |
33 |
Correct |
15 ms |
15452 KB |
Output is correct |
34 |
Correct |
4 ms |
6236 KB |
Output is correct |
35 |
Correct |
4 ms |
6300 KB |
Output is correct |
36 |
Correct |
4 ms |
6316 KB |
Output is correct |
37 |
Correct |
5 ms |
6236 KB |
Output is correct |
38 |
Correct |
4 ms |
6236 KB |
Output is correct |
39 |
Correct |
4 ms |
6676 KB |
Output is correct |
40 |
Correct |
4 ms |
6492 KB |
Output is correct |
41 |
Correct |
6 ms |
6744 KB |
Output is correct |
42 |
Correct |
6 ms |
6744 KB |
Output is correct |
43 |
Correct |
5 ms |
6744 KB |
Output is correct |
44 |
Correct |
5 ms |
6748 KB |
Output is correct |
45 |
Correct |
12 ms |
13400 KB |
Output is correct |
46 |
Correct |
12 ms |
13404 KB |
Output is correct |
47 |
Correct |
10 ms |
13384 KB |
Output is correct |
48 |
Correct |
12 ms |
13404 KB |
Output is correct |
49 |
Correct |
11 ms |
13404 KB |
Output is correct |
50 |
Correct |
25 ms |
21084 KB |
Output is correct |
51 |
Correct |
32 ms |
21844 KB |
Output is correct |
52 |
Correct |
54 ms |
26716 KB |
Output is correct |
53 |
Correct |
58 ms |
26192 KB |
Output is correct |
54 |
Correct |
51 ms |
25552 KB |
Output is correct |
55 |
Correct |
78 ms |
32080 KB |
Output is correct |
56 |
Correct |
560 ms |
100432 KB |
Output is correct |
57 |
Correct |
152 ms |
37396 KB |
Output is correct |
58 |
Correct |
132 ms |
37260 KB |
Output is correct |
59 |
Correct |
150 ms |
37716 KB |
Output is correct |