QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#393863#6846. Wiring Engineering2745518585WA 29ms17388kbC++203.9kb2024-04-19 15:28:522024-04-19 15:28:52

Judging History

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

  • [2024-04-19 15:28:52]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:17388kb
  • [2024-04-19 15:28:52]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int N=1001,M=1000001;
int n,m,a[N][N],a1[N],a2[N];
ll f[N*N*3],g[N*N*3],d[M];
vector<pair<int,ll>> b1[N*N*3],b2[N*N*3];
struct str
{
    int l1,r1,l2,r2,t;
};
inline int sum(int x,int y,int t)
{
    return (x-1)*(n+1)*3+(y-1)*3+t+1;
}
pair<int,int> num(int x)
{
    return make_pair((x-1)/((n+1)*3)+1,(x-1)/3%(n+1)+1);
}
void road(int x,int y,ll w)
{
    auto [x1,x2]=num(x);
    auto [y1,y2]=num(y);
    // printf("%d %d %d -> %d %d %d: %lld\n",x1,x2,(x-1)%3,y1,y2,(y-1)%3,w);
    b1[x].push_back(make_pair(y,w));
    b2[y].push_back(make_pair(x,w));
}
void check(int x,int l1,int r1,int l2,int r2)
{
    for(int i=l1;i<=r1;++i)
    {
        for(int j=l2;j<=r2;++j)
        {
            f[sum(i,j,0)]=f[sum(i,j,1)]=f[sum(i,j,2)]=-1e18;
            g[sum(i,j,0)]=g[sum(i,j,1)]=g[sum(i,j,2)]=-1e18;
        }
    }
    f[x]=g[x]=0;
    auto [x1,x2]=num(x);
    for(int i=x1;i>=l1;--i)
    {
        for(int j=x2;j>=l2;--j)
        {
            for(int k=2;k>=0;--k)
            {
                int x=sum(i,j,k);
                for(auto l:b2[x]) f[l.first]=max(f[l.first],f[x]+l.second);
            }
        }
    }
    for(int i=x1;i<=r1;++i)
    {
        for(int j=x2;j<=r2;++j)
        {
            for(int k=0;k<=2;++k)
            {
                int x=sum(i,j,k);
                for(auto l:b1[x]) g[l.first]=max(g[l.first],g[x]+l.second);
            }
        }
    }
}
void solve(int l1,int r1,int l2,int r2,const vector<str> &x)
{
    if(l1>r1&&l2>r2) return;
    if(r1-l1>=r2-l2)
    {
        int z=l1+r1>>1;
        vector<str> p,p1,p2;
        for(auto i:x)
        {
            if(i.r1<z) p1.push_back(i);
            else if(i.l1>z) p2.push_back(i);
            else p.push_back(i);
        }
        for(int i=l2;i<=r2;++i)
        {
            check(sum(z,i,2),l1,r1,l2,r2);
            for(auto j:p)
            {
                d[j.t]=max(d[j.t],f[sum(j.l1,j.l2,0)]+g[sum(j.r1,j.r2,0)]);
            }
        }
        solve(l1,z-1,l2,r2,p1);
        solve(z+1,r1,l2,r2,p2);
    }
    else
    {
        int z=l2+r2>>1;
        vector<str> p,p1,p2;
        for(auto i:x)
        {
            if(i.r2<z) p1.push_back(i);
            else if(i.l2>z) p2.push_back(i);
            else p.push_back(i);
        }
        for(int i=l1;i<=r1;++i)
        {
            check(sum(i,z,1),l1,r1,l2,r2);
            for(auto j:p)
            {
                d[j.t]=max(d[j.t],f[sum(j.l1,j.l2,0)]+f[sum(j.r1,j.r2,0)]);
            }
        }
        solve(l1,r1,l2,z-1,p1);
        solve(l1,r1,z+1,r2,p2);
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&a1[i]);
    }
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&a2[i]);
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=n;++j)
        {
            scanf("%d",&a[i][j]);
        }
    }
    for(int i=1;i<=n+1;++i)
    {
        for(int j=1;j<=n+1;++j)
        {
            int x=sum(i,j,0);
            if(i>1) road(sum(i-1,j,0),x,0),road(sum(i-1,j,1),x,0);
            if(j>1) road(sum(i,j-1,0),x,0),road(sum(i,j-1,2),x,0);
            x=sum(i,j,1);
            road(sum(i,j,0),x,-a1[i]);
            if(j>1) road(sum(i,j-1,1),x,max(a[i][j-1]-a2[j-1],0)),road(sum(i,j-1,2),x,a[i][j-1]-a1[i]);
            x=sum(i,j,2);
            road(sum(i,j,0),x,-a2[j]);
            if(i>1) road(sum(i-1,j,2),x,max(a[i-1][j]-a1[i-1],0)),road(sum(i-1,j,1),x,a[i-1][j]-a2[j]);
        }
    }
    vector<str> p;
    for(int i=1;i<=m;++i)
    {
        str x;
        scanf("%d%d%d%d",&x.l1,&x.r1,&x.l2,&x.r2);
        ++x.r1,++x.r2;
        x.t=i;
        p.push_back(x);
    }
    solve(1,n+1,1,n+1,p);
    for(int i=1;i<=m;++i)
    {
        printf("%lld\n",d[i]);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 9936kb

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: 29ms
memory: 17388kb

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
8784
0
0
0
0
0
0
58251
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8784
0
0
0
0
0
0
58251
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3651
0
0
0
0
0
0
53118
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
45661
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
45661
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
37085
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

wrong answer 5th lines differ - expected: '0', found: '8784'