QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#385922#6846. Wiring EngineeringTx_LcyRE 18ms78516kbC++143.2kb2024-04-11 10:06:272024-04-11 10:06:27

Judging History

你现在查看的是最新测评结果

  • [2024-04-11 10:06:27]
  • 评测
  • 测评结果:RE
  • 用时:18ms
  • 内存:78516kb
  • [2024-04-11 10:06:27]
  • 提交

answer

//A tree without skin will surely die.
//A man without face will be alive.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define chkmax(x,y) (x=max(x,y))
#define rep(i,j,k) for (int i=j;i<=k;++i)
#define per(i,j,k) for (int i=j;i>=k;--i)
int const N=105;
int const M=1e6+10;
int n,q,u[N],v[N],w[N][N],a[M],b[M],c[M],d[M],ans[M];
int lf[N][N],rg[N][N],dp1[N][N][N][2][2],dp2[N][N][N][2][2];
vector<int>g1[N],g2[N];
inline void work(int l,int r,int x,int y,vector<int>id){
    if (l>r || x>y || !id.size()) return;
    // if (r-l+1>=y-x+1){
        int md=(l+r)>>1;
        vector<int>L,R,M;
        for (auto i:id)
            if (b[i]<md) L.push_back(i);
            else if (a[i]>md) R.push_back(i);
            else M.push_back(i);
        work(l,md-1,x,y,L),work(md+1,r,x,y,R);
        rep(tp,0,1){
            if (!tp) memset(lf,0,sizeof(lf)),memset(rg,0,sizeof(rg));
            else memset(lf,-0x3f,sizeof(lf)),memset(rg,-0x3f,sizeof(rg));
            rep(i,1,n) g1[i].clear(),g2[i].clear();
            for (auto i:M) g1[b[i]].push_back(i),g2[a[i]].push_back(i);
            memset(dp1,-0x3f,sizeof(dp1));
            rep(L,x,y) dp1[md-1][L][L-1][0][0]=0;
            rep(i,md,r){
                rep(L,x,y) rep(R,L-1,y) rep(s,0,1) rep(t,0,1){
                    chkmax(dp1[i][L][R][0][t],dp1[i-1][L][R][s][t]);
                    if (L<=R) chkmax(dp1[i][L][R][1][1],dp1[i-1][L][R][s][t]-u[i]-(!t)*v[R]+w[i][R]);
                    if (L<=R && !(L==R && tp)) chkmax(dp1[i][L][R][s][0],dp1[i][L][R-1][s][t]);
                    if (L<=R) chkmax(dp1[i][L][R][1][1],dp1[i][L][R-1][s][t]-(!s)*u[i]-v[R]+w[i][R]);
                }
                for (auto id:g1[i]) rep(k,c[id],d[id]) rep(s,0,1) rep(t,0,1)
                    chkmax(lf[id][k],dp1[i][k][d[id]][s][t]);
            }
            memset(dp2,-0x3f,sizeof(dp2));
            rep(L,x-1,y+1) dp2[md][L][L-1][0][0]=0;
            per(i,md-1,l){
                per(L,y+1,x) rep(R,L-1,y) rep(s,0,1) rep(t,0,1){
                    chkmax(dp2[i][L][R][0][t],dp2[i+1][L][R][s][t]);
                    if (L<=R) chkmax(dp2[i][L][R][1][1],dp2[i+1][L][R][s][t]-u[i]-(!t)*v[L]+w[i][L]);
                    if (L<=R && !(L==R && tp)) chkmax(dp2[i][L][R][s][0],dp2[i][L+1][R][s][t]);
                    if (L<=R) chkmax(dp2[i][L][R][1][1],dp2[i][L+1][R][s][t]-(!s)*u[i]-v[L]+w[i][L]);
                }
                for (auto id:g2[i]) rep(k,c[id],d[id]) rep(s,0,1) rep(t,0,1)
                    chkmax(rg[id][k],dp2[i][c[id]][k][s][t]);
            }
            for (auto i:M)
                rep(k,c[i],d[i]) ans[i]=max(ans[i],lf[i][k]+rg[i][k]+tp*v[k]);
        }
    // }
}
inline void solve(){
    cin>>n>>q;
    rep(i,1,n) cin>>u[i];
    rep(i,1,n) cin>>v[i];
    rep(i,1,n) rep(j,1,n) cin>>w[i][j];
    vector<int>id;
    rep(i,1,q) cin>>a[i]>>b[i]>>c[i]>>d[i],id.push_back(i);
    work(1,n,1,n,id);
    rep(i,1,q) cout<<ans[i]<<'\n';
}
signed main(){
    // freopen("test.in","r",stdin);
    // freopen("test.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t=1;
    // cin>>t;
    while (t--) solve();
    cerr<<"Time: "<<(double)clock()/CLOCKS_PER_SEC<<" s\n";
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 18ms
memory: 78516kb

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
Runtime Error

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:


result: