#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
#define int2 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".ans","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=1e9;
const int mod2=1e9+9;
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;
int kk;
int el=29;
int2 a[200001];
int2 b[200001];
int dp1[4][200001];
int dp2[200001][4];
int2 dista[200001];
int2 distb[200001];
vector<int2> v;
int2 get(int l,int r)
{
if(l<=2)return dp1[l][r];
if(r<=2) return dp2[l][r];
int2 s=dp2[l][2]+dp1[2][r]-dp2[2][2];
l-=2;
r-=2;
if(r>l)
{
return distb[l]+dista[r]-a[1]*min(r,l)-dista[r-l]+s;
}
else
{
return dista[r]+distb[l]-a[1]*min(l,r)-distb[l-r]+s;
}
}
vector<long long> mosaic(vector<int> X, vector<int> Y,vector<int> T, vector<int> B,vector<int> L, vector<int> R)
{
n=X.size();
for(int i=1; i<=n; i++)
a[i]=X[i-1];
for(int i=1; i<=n; i++)
b[i]=Y[i-1];
for(int i=1; i<=n; i++)
dp1[1][i]=a[i];
dp1[2][1]=b[2];
dp1[3][1]=b[3];
for(int i=2; i<=3; i++)
for(int j=2; j<=n; j++)
dp1[i][j]=1-max(dp1[i-1][j],dp1[i][j-1]);
for(int i=1; i<=n; i++)
dp2[i][1]=b[i];
dp2[1][2]=a[2];
dp2[1][3]=a[3];
for(int i=2; i<=n; i++)
for(int j=2; j<=3; j++)
dp2[i][j]=1-max(dp2[i-1][j],dp2[i][j-1]);
for(int i=3; i<=n; i++)
{
a[i-2]=dp1[3][i],
b[i-2]=dp2[i][3];
}
for(int i=1; i<=n; i++)
for(int j=1; j<=3; j++)
dp2[i][j]+=dp2[i-1][j]+dp2[i][j-1]-dp2[i-1][j-1];
for(int i=1; i<=3; i++)
for(int j=1; j<=n; j++)
dp1[i][j]+=dp1[i-1][j]+dp1[i][j-1]-dp1[i-1][j-1];
n-=2;
for(int i=1; i<=n; i++)
{
a[i]+=a[i-1],dista[i]=dista[i-1]+a[i],
b[i]+=b[i-1],distb[i]=distb[i-1]+b[i];
}
/** for(int i=1;i<=n;i++)
cout<<a[i]<<" ";
down
for(int i=1;i<=n;i++)
cout<<b[i]<<" ";*/
m=T.size();
for(int i=1; i<=m; i++)
{
l=T[i-1]+1;
r=L[i-1]+1;
l2=B[i-1]+1;
r2=R[i-1]+1;
v.pb(get(l2,r2)+get(l-1,r-1)-get(l2,r-1)-get(l-1,r2));
}
return v;
}
/*
main()
{
freopen("test.inp","r",stdin);
freopen("test.ans","w",stdout);
cin>>n;
vector<int>a1,a2,a3,a4,a5,a6;
for(int i=1; i<=n; i++)
cin>>l,a1.pb(l);
for(int i=1; i<=n; i++)
cin>>l,a2.pb(l);
cin>>m;
for(int i=1; i<=m; i++)
{
cin>>l>>r>>l2>>r2;
a3.pb(l);
a5.pb(r);
a4.pb(l2);
a6.pb(r2);
}
vector<int2> vv=mosaic(a1,a2,a3,a4,a5,a6);
for(auto x:vv)
cout<<x,down
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8532 KB |
Output is correct |
2 |
Correct |
1 ms |
8532 KB |
Output is correct |
3 |
Correct |
2 ms |
8532 KB |
Output is correct |
4 |
Correct |
1 ms |
8532 KB |
Output is correct |
5 |
Correct |
1 ms |
8532 KB |
Output is correct |
6 |
Correct |
1 ms |
8532 KB |
Output is correct |
7 |
Correct |
2 ms |
8532 KB |
Output is correct |
8 |
Correct |
1 ms |
8532 KB |
Output is correct |
9 |
Correct |
1 ms |
8532 KB |
Output is correct |
10 |
Correct |
1 ms |
8532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8532 KB |
Output is correct |
2 |
Correct |
1 ms |
8532 KB |
Output is correct |
3 |
Correct |
2 ms |
8532 KB |
Output is correct |
4 |
Correct |
1 ms |
8532 KB |
Output is correct |
5 |
Correct |
1 ms |
8532 KB |
Output is correct |
6 |
Correct |
1 ms |
8532 KB |
Output is correct |
7 |
Correct |
2 ms |
8532 KB |
Output is correct |
8 |
Correct |
1 ms |
8532 KB |
Output is correct |
9 |
Correct |
1 ms |
8532 KB |
Output is correct |
10 |
Correct |
1 ms |
8532 KB |
Output is correct |
11 |
Correct |
2 ms |
8532 KB |
Output is correct |
12 |
Correct |
2 ms |
8532 KB |
Output is correct |
13 |
Correct |
2 ms |
8532 KB |
Output is correct |
14 |
Correct |
2 ms |
8532 KB |
Output is correct |
15 |
Correct |
2 ms |
8532 KB |
Output is correct |
16 |
Correct |
2 ms |
8532 KB |
Output is correct |
17 |
Correct |
2 ms |
8644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
30140 KB |
Output is correct |
2 |
Correct |
87 ms |
29984 KB |
Output is correct |
3 |
Correct |
83 ms |
29372 KB |
Output is correct |
4 |
Correct |
83 ms |
29828 KB |
Output is correct |
5 |
Correct |
73 ms |
27068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8532 KB |
Output is correct |
2 |
Correct |
1 ms |
8532 KB |
Output is correct |
3 |
Correct |
2 ms |
8532 KB |
Output is correct |
4 |
Correct |
1 ms |
8532 KB |
Output is correct |
5 |
Correct |
1 ms |
8532 KB |
Output is correct |
6 |
Correct |
1 ms |
8532 KB |
Output is correct |
7 |
Correct |
2 ms |
8532 KB |
Output is correct |
8 |
Correct |
1 ms |
8532 KB |
Output is correct |
9 |
Correct |
1 ms |
8532 KB |
Output is correct |
10 |
Correct |
1 ms |
8532 KB |
Output is correct |
11 |
Correct |
2 ms |
8532 KB |
Output is correct |
12 |
Correct |
2 ms |
8532 KB |
Output is correct |
13 |
Correct |
2 ms |
8532 KB |
Output is correct |
14 |
Correct |
2 ms |
8532 KB |
Output is correct |
15 |
Correct |
2 ms |
8532 KB |
Output is correct |
16 |
Correct |
2 ms |
8532 KB |
Output is correct |
17 |
Correct |
2 ms |
8644 KB |
Output is correct |
18 |
Correct |
66 ms |
22468 KB |
Output is correct |
19 |
Correct |
66 ms |
22212 KB |
Output is correct |
20 |
Correct |
62 ms |
22220 KB |
Output is correct |
21 |
Correct |
63 ms |
21956 KB |
Output is correct |
22 |
Correct |
65 ms |
22032 KB |
Output is correct |
23 |
Correct |
67 ms |
22128 KB |
Output is correct |
24 |
Correct |
65 ms |
22204 KB |
Output is correct |
25 |
Correct |
63 ms |
22204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
20156 KB |
Output is correct |
2 |
Correct |
107 ms |
31932 KB |
Output is correct |
3 |
Correct |
94 ms |
31040 KB |
Output is correct |
4 |
Correct |
95 ms |
31164 KB |
Output is correct |
5 |
Correct |
103 ms |
31364 KB |
Output is correct |
6 |
Correct |
99 ms |
31888 KB |
Output is correct |
7 |
Correct |
95 ms |
31940 KB |
Output is correct |
8 |
Correct |
91 ms |
31932 KB |
Output is correct |
9 |
Correct |
87 ms |
28604 KB |
Output is correct |
10 |
Correct |
79 ms |
28604 KB |
Output is correct |
11 |
Correct |
90 ms |
28604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
121 ms |
31932 KB |
Output is correct |
2 |
Correct |
93 ms |
31932 KB |
Output is correct |
3 |
Correct |
88 ms |
30396 KB |
Output is correct |
4 |
Correct |
85 ms |
30396 KB |
Output is correct |
5 |
Correct |
105 ms |
32388 KB |
Output is correct |
6 |
Correct |
75 ms |
28528 KB |
Output is correct |
7 |
Correct |
69 ms |
25276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
30140 KB |
Output is correct |
2 |
Correct |
87 ms |
29984 KB |
Output is correct |
3 |
Correct |
83 ms |
29372 KB |
Output is correct |
4 |
Correct |
83 ms |
29828 KB |
Output is correct |
5 |
Correct |
73 ms |
27068 KB |
Output is correct |
6 |
Correct |
121 ms |
31932 KB |
Output is correct |
7 |
Correct |
93 ms |
31932 KB |
Output is correct |
8 |
Correct |
88 ms |
30396 KB |
Output is correct |
9 |
Correct |
85 ms |
30396 KB |
Output is correct |
10 |
Correct |
105 ms |
32388 KB |
Output is correct |
11 |
Correct |
75 ms |
28528 KB |
Output is correct |
12 |
Correct |
69 ms |
25276 KB |
Output is correct |
13 |
Correct |
109 ms |
31744 KB |
Output is correct |
14 |
Correct |
100 ms |
31796 KB |
Output is correct |
15 |
Correct |
100 ms |
31932 KB |
Output is correct |
16 |
Correct |
91 ms |
30140 KB |
Output is correct |
17 |
Correct |
94 ms |
31424 KB |
Output is correct |
18 |
Correct |
93 ms |
31932 KB |
Output is correct |
19 |
Correct |
76 ms |
27848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8532 KB |
Output is correct |
2 |
Correct |
1 ms |
8532 KB |
Output is correct |
3 |
Correct |
1 ms |
8532 KB |
Output is correct |
4 |
Correct |
2 ms |
8532 KB |
Output is correct |
5 |
Correct |
1 ms |
8532 KB |
Output is correct |
6 |
Correct |
1 ms |
8532 KB |
Output is correct |
7 |
Correct |
1 ms |
8532 KB |
Output is correct |
8 |
Correct |
2 ms |
8532 KB |
Output is correct |
9 |
Correct |
1 ms |
8532 KB |
Output is correct |
10 |
Correct |
1 ms |
8532 KB |
Output is correct |
11 |
Correct |
1 ms |
8532 KB |
Output is correct |
12 |
Correct |
2 ms |
8532 KB |
Output is correct |
13 |
Correct |
2 ms |
8532 KB |
Output is correct |
14 |
Correct |
2 ms |
8532 KB |
Output is correct |
15 |
Correct |
2 ms |
8532 KB |
Output is correct |
16 |
Correct |
2 ms |
8532 KB |
Output is correct |
17 |
Correct |
2 ms |
8532 KB |
Output is correct |
18 |
Correct |
2 ms |
8644 KB |
Output is correct |
19 |
Correct |
87 ms |
30140 KB |
Output is correct |
20 |
Correct |
87 ms |
29984 KB |
Output is correct |
21 |
Correct |
83 ms |
29372 KB |
Output is correct |
22 |
Correct |
83 ms |
29828 KB |
Output is correct |
23 |
Correct |
73 ms |
27068 KB |
Output is correct |
24 |
Correct |
66 ms |
22468 KB |
Output is correct |
25 |
Correct |
66 ms |
22212 KB |
Output is correct |
26 |
Correct |
62 ms |
22220 KB |
Output is correct |
27 |
Correct |
63 ms |
21956 KB |
Output is correct |
28 |
Correct |
65 ms |
22032 KB |
Output is correct |
29 |
Correct |
67 ms |
22128 KB |
Output is correct |
30 |
Correct |
65 ms |
22204 KB |
Output is correct |
31 |
Correct |
63 ms |
22204 KB |
Output is correct |
32 |
Correct |
52 ms |
20156 KB |
Output is correct |
33 |
Correct |
107 ms |
31932 KB |
Output is correct |
34 |
Correct |
94 ms |
31040 KB |
Output is correct |
35 |
Correct |
95 ms |
31164 KB |
Output is correct |
36 |
Correct |
103 ms |
31364 KB |
Output is correct |
37 |
Correct |
99 ms |
31888 KB |
Output is correct |
38 |
Correct |
95 ms |
31940 KB |
Output is correct |
39 |
Correct |
91 ms |
31932 KB |
Output is correct |
40 |
Correct |
87 ms |
28604 KB |
Output is correct |
41 |
Correct |
79 ms |
28604 KB |
Output is correct |
42 |
Correct |
90 ms |
28604 KB |
Output is correct |
43 |
Correct |
121 ms |
31932 KB |
Output is correct |
44 |
Correct |
93 ms |
31932 KB |
Output is correct |
45 |
Correct |
88 ms |
30396 KB |
Output is correct |
46 |
Correct |
85 ms |
30396 KB |
Output is correct |
47 |
Correct |
105 ms |
32388 KB |
Output is correct |
48 |
Correct |
75 ms |
28528 KB |
Output is correct |
49 |
Correct |
69 ms |
25276 KB |
Output is correct |
50 |
Correct |
109 ms |
31744 KB |
Output is correct |
51 |
Correct |
100 ms |
31796 KB |
Output is correct |
52 |
Correct |
100 ms |
31932 KB |
Output is correct |
53 |
Correct |
91 ms |
30140 KB |
Output is correct |
54 |
Correct |
94 ms |
31424 KB |
Output is correct |
55 |
Correct |
93 ms |
31932 KB |
Output is correct |
56 |
Correct |
76 ms |
27848 KB |
Output is correct |
57 |
Correct |
103 ms |
31932 KB |
Output is correct |
58 |
Correct |
95 ms |
31420 KB |
Output is correct |
59 |
Correct |
100 ms |
31676 KB |
Output is correct |
60 |
Correct |
91 ms |
31164 KB |
Output is correct |
61 |
Correct |
95 ms |
31164 KB |
Output is correct |
62 |
Correct |
96 ms |
31424 KB |
Output is correct |
63 |
Correct |
93 ms |
28528 KB |
Output is correct |
64 |
Correct |
78 ms |
24828 KB |
Output is correct |