QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425697 | #6846. Wiring Engineering | LinkWish | WA | 23ms | 9424kb | C++14 | 3.8kb | 2024-05-30 15:54:23 | 2024-05-30 15:54:24 |
Judging History
answer
//Linkwish's code
//Ciallo~(∠・ω< )⌒★
#include<bits/stdc++.h>
#define endl '\n'
#define si static inline
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;typedef long double ld;typedef __int128 li;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;typedef const int ci;
typedef const ll cl;const int iinf=1e9;const ll linf=LLONG_MAX;
template<typename T>si bool gmax(T &x,const T y){if(x<y)return x=y,1;return 0;}
template<typename T>si bool gmin(T &x,const T y){if(y<x)return x=y,1;return 0;}
namespace LinkWish{
ci N=505,M=300005;
int n,m;
int a[N][N],v1[N],v2[N];
struct Que{
int l,r,L,R,id;
inline Que(int v,int w,int x,int y,int z){l=v,r=w,L=x,R=y,id=z;}
};
vector<Que> q[N<<2];
int ans[M];
si int ls(int x){return x<<1;}
si int rs(int x){return x<<1|1;}
void add(int x,int l,int r,Que k){
if(l==r){
ans[k.id]=-v1[l];
for(int i=k.L;i<=k.R;i++)if(a[l][i]>v2[i])ans[k.id]+=a[l][i]-v2[i];
gmax(ans[k.id],0);
return ;
}
int mid=(l+r)>>1;
if(k.l<=mid&&k.r>mid)return q[x].push_back(k),void();
if(k.l<=mid)add(ls(x),l,mid,k);
else add(rs(x),mid+1,r,k);
}
int f[N][N][2],g[N][N][2];
void solve(int x,int l,int r){
if(l==r)return ;
int mid=(l+r)>>1;
for(int st=1;st<=n;st++){
for(int i=l;i<=mid+1;i++)for(int j=1;j<=n;j++)f[i][j][0]=f[i][j][1]=-iinf;
for(int i=mid;i<=r;i++)for(int j=1;j<=n;j++)g[i][j][0]=g[i][j][1]=-iinf;
for(int i=mid;i>=l;i--){
f[i][st][1]=max(f[i+1][st][1],a[i][st]-v1[i]-v2[st]),f[i][st][0]=0;
int mx[2][2]={{0,-iinf},{f[i+1][st][1],a[i][st]-v1[i]-v2[st]}};
for(int j=st-1,v=0;j;j--){
f[i][j][0]=f[i+1][j][0]+max(0,a[i][j]-v1[i]);
int c1=mx[0][0]+a[i][j]-v1[i]-v2[j],c2=mx[0][1]+a[i][j]-v2[j];
gmax(f[i][j][0],max(c1,c2));
f[i][j][1]=f[i+1][j][1]+max(0,a[i][j]-v1[i]);
int d1=mx[1][0]+a[i][j]-v1[i]-v2[j],d2=mx[1][1]+a[i][j]-v2[j];
gmax(f[i][j][1],max(d1,d2));
gmax(f[i][j][1],v-v1[i]+a[i][j]-v2[j]);
gmax(mx[0][0],f[i+1][j][0]);
gmax(mx[0][1],max(c1,c2));
gmax(mx[1][0],f[i+1][j][1]);
gmax(mx[1][1],max(d1,d2));
if(a[i][j]-v2[j]>0)v+=a[i][j]-v2[j];
}
}
for(int i=mid+1;i<=r;i++){
g[i][st][1]=max(g[i-1][st][1],a[i][st]-v1[i]-v2[st]),g[i][st][0]=0;
int mx[2][2]={{0,-iinf},{g[i-1][st][1],a[i][st]-v1[i]-v2[st]}};
for(int j=st+1,v=0;j<=n;j++){
g[i][j][0]=g[i-1][j][0]+max(0,a[i][j]-v1[i]-v2[j]);
int c1=mx[0][0]+a[i][j]-v1[i]-v2[j],c2=mx[0][1]+a[i][j]-v2[j];
gmax(g[i][j][0],max(c1,c2));
g[i][j][1]=g[i-1][j][1]+max(0,a[i][j]-v1[i]-v2[j]);
int d1=mx[1][0]+a[i][j]-v1[i]-v2[j],d2=mx[1][1]+a[i][j]-v2[j];
gmax(g[i][j][1],max(d1,d2));
gmax(g[i][j][1],v-v1[i]+a[i][j]-v2[j]);
gmax(mx[0][0],g[i-1][j][0]);
gmax(mx[0][1],max(c1,c2));
gmax(mx[1][0],g[i-1][j][1]);
gmax(mx[1][1],max(d1,d2));
if(a[i][j]-v2[j]>0)v+=a[i][j]-v2[j];
}
}
// cout<<"ST "<<st<<endl;
for(Que &i:q[x]){
if(i.L<=st&&i.R>=st){
for(int j=0;j<2;j++){
for(int k=0;k<2;k++){
gmax(ans[i.id],f[i.l][i.L][j]+g[i.r][i.R][k]+(j&&k)*v2[st]);
// cout<<"GM "<<i.id<<' '<<j<<' '<<k<<' '<<f[i.l][i.L][j]<<' '<<g[i.r][i.R][k]<<endl;
}
}
}
}
}
solve(ls(x),l,mid),solve(rs(x),mid+1,r);
}
si void mian(){
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>v1[i];
for(int i=1;i<=n;i++)cin>>v2[i];
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>a[i][j];
for(int i=1,l,r,L,R;i<=m;i++){
cin>>l>>r>>L>>R;
add(1,1,n,Que(l,r,L,R,i));
}
solve(1,1,n);
for(int i=1;i<=m;i++)cout<<ans[i]<<endl;
}
}
signed main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
LinkWish::mian();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7808kb
input:
3 4 1 2 1 2 1 2 1 2 3 4 5 6 3 2 1 1 3 1 3 2 3 1 2 1 1 2 3 1 2 2 3
output:
8 5 1 7
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 23ms
memory: 9424kb
input:
24 90000 8793 8115 9643 2814 6394 7070 3822 4788 6737 6506 2901 4772 5347 5050 3493 2803 584 2544 3834 678 9891 2958 5475 522 9057 3674 3163 6433 5937 8480 4815 1201 5509 1303 4151 8190 6229 9339 9765 3011 2256 3682 8442 3641 2268 5609 4948 9632 5872 4006 7690 2611 5381 6184 9483 8527 8248 960 8124 ...
output:
0 0 0 0 0 0 734 8060 10799 10799 14772 14772 14772 14772 14772 20708 24243 25895 27159 33403 33403 33403 33469 33469 0 0 0 0 0 734 8060 10799 10799 14772 14772 14772 14772 14772 20708 24243 25895 27159 33403 33403 33403 33469 33469 0 0 0 0 402 7728 10467 10467 14440 14440 14440 14440 14440 20376 239...
result:
wrong answer 309th lines differ - expected: '14904', found: '12810'