QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#216140#7582. Snowy SmileSolitaryDream#RE 1ms3676kbC++171.8kb2023-10-15 16:10:022023-10-15 16:10:02

Judging History

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

  • [2023-10-15 16:10:02]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3676kb
  • [2023-10-15 16:10:02]
  • 提交

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;
        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].sum);
            }
        }
        cout<<ans<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3676kb

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

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:


result: