QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#216157#7582. Snowy SmileSolitaryDream#AC ✓620ms3784kbC++171.9kb2023-10-15 16:19:382023-10-15 16:19:39

Judging History

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

  • [2023-10-15 16:19:39]
  • 评测
  • 测评结果:AC
  • 用时:620ms
  • 内存:3784kb
  • [2023-10-15 16:19:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long

using pii=pair<int,int>;

const int N=2e3+1e2+7;

int T,n,x[N],y[N],w[N];

vector<pii> a[N];

vector<int> X,Y;

int m;

struct Data{
    int lmx,rmx,smx,sum;
}t[N*10];

Data operator +(const Data &a,const Data &b) 
{
    return {max(a.lmx,a.sum+b.lmx),max(b.rmx,b.sum+a.rmx),max({a.smx,b.smx,a.rmx+b.lmx}),a.sum+b.sum};
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>T;
    while(T--)
    {
        cin>>n;
        X.clear(),Y.clear();
        for(int i=1;i<=n;i++)
            cin>>x[i]>>y[i]>>w[i],X.push_back(x[i]),Y.push_back(y[i]);
        sort(X.begin(),X.end());
        X.erase(unique(X.begin(),X.end()),X.end());
        sort(Y.begin(),Y.end());
        Y.erase(unique(Y.begin(),Y.end()),Y.end());
        for(int i=1;i<=n;i++)
            a[i].clear();
        for(int i=1;i<=n;i++)
        {
            x[i]=lower_bound(X.begin(),X.end(),x[i])-X.begin()+1,y[i]=lower_bound(Y.begin(),Y.end(),y[i])-Y.begin()+1;
            a[x[i]].push_back({y[i],w[i]});
        }
        m=1;
        while(m<Y.size())
            m<<=1;
        m--;
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            for(int k=1;k<=m*2+1;k++)
                t[k]={0,0,0,0};
            for(int j=i;j<=n;j++)
            {
                for(auto [y,w]:a[j])
                {
                    y+=m;
                    t[y].sum+=w;
                    t[y].smx=max(0ll,t[y].sum);
                    t[y].lmx=max(0ll,t[y].sum);
                    t[y].rmx=max(0ll,t[y].sum);
                    y>>=1;
                    while(y)
                        t[y]=t[y*2]+t[y*2+1],y>>=1;
                }
                ans=max(ans,t[1].smx);
            }
        }
        cout<<ans<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3512kb

input:

2
4
1 1 50
2 1 50
1 2 50
2 2 -500
2
-1 1 5
-1 1 1

output:

100
6

result:

ok 2 number(s): "100 6"

Test #2:

score: 0
Accepted
time: 620ms
memory: 3784kb

input:

52
10
30 -1 -40065867
-15 -74 -695603735
-14 3 -847010045
33 -92 -458180374
-88 -86 -488393753
50 -91 -949931576
39 -99 -168684248
-29 64 783067879
14 -5 -104144786
-67 90 492127865
10
-29 -70 151800541
54 41 -677722362
-85 -72 766300892
-47 -90 -74384884
-12 -56 679506148
0 -41 -30038154
-4 -6 -254...

output:

1275195744
2084179225
1734353870
1018976777
2591083202
1309403622
2358891488
2143566532
1602649268
2112317422
1470851645
2423431804
2209082718
1571719735
1313345276
2039708041
1526772930
1368470878
866267413
1826546180
1878414495
1706604892
1822460963
1942258759
2943744963
2090539403
666502909
14660...

result:

ok 52 numbers