QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#771573#7582. Snowy Smiletarjen#WA 1191ms4272kbC++202.2kb2024-11-22 14:19:132024-11-22 14:19:13

Judging History

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

  • [2024-11-22 14:19:13]
  • 评测
  • 测评结果:WA
  • 用时:1191ms
  • 内存:4272kb
  • [2024-11-22 14:19:13]
  • 提交

answer

//线段树区间加区间求和 线段树二分左右>=给定sum的第一个位置
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2010;
struct info{
    ll ans=0,lmx=0,rmx=0,sum=0;
};
info operator+(info a,info b){
    a.ans=max({a.ans,b.ans,a.rmx+b.lmx});
    a.lmx=max(a.lmx,a.sum+b.lmx);
    a.rmx=max(a.rmx,a.rmx+b.sum);
    a.sum+=b.sum;
    return a;
}
struct Node{
    int l,r;
    info res;  
};
struct SegmentTree{
    Node a[maxn*4];
    void pushup(int i){
        if(a[i].l==a[i].r)return;
        a[i].res=a[i*2].res+a[i*2+1].res;
    }
    void build(int i,int l,int r){
        a[i].l=l,a[i].r=r;a[i].res=info{0,0,0,0};
        if(l>=r)return;
        int mid=(l+r)/2;
        build(i*2,l,mid);
        build(i*2+1,mid+1,r);
    }
    void update(int i,int x,int w){
        if(a[i].r<x||a[i].l>x)return;
        if(a[i].l>=x&&a[i].r<=x){
            a[i].res.sum+=w;
            a[i].res.ans=a[i].res.lmx=a[i].res.rmx=max(a[i].res.sum,0ll);
            return;
        }
        update(i*2,x,w);
        update(i*2+1,x,w);
        pushup(i);
    }
    info query(int i,int l,int r){
        if(a[i].r<l||a[i].l>r||l>r)return info{0,0,0,0};
        if(a[i].l>=l&&a[i].r<=r){
            return a[i].res;
        }
        return query(i*2,l,r)+query(i*2+1,l,r);
    }
}tri;
struct kkk{
    int x,y,w;
};
ll solve()
{
    int n;cin>>n;
    vector<kkk>a(n);
    map<int,int> X,Y;
    for(int i=0;i<n;i++){
        cin>>a[i].x>>a[i].y>>a[i].w;
        X[a[i].x]=1;
        Y[a[i].y]=1;
    }
    int cntx=0,cnty=0;
    for(auto &it:X)it.second=++cntx;
    for(auto &it:Y)it.second=++cnty;
    vector<vector<kkk>> ve(cntx+1);
    for(int i=0;i<n;i++)a[i].x=X[a[i].x],a[i].y=Y[a[i].y],ve[a[i].x].push_back(a[i]);
    ll ans=0;
    for(int i=1;i<=cntx;i++){
        tri.build(1,1,cnty);
        for(int j=i;j<=cntx;j++){
            for(auto &it:ve[j])tri.update(1,it.y,it.w);
            ans=max(ans,tri.query(1,1,cnty).ans);
        }
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;cin>>T;while(T--)cout<<solve()<<"\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Wrong Answer
time: 1191ms
memory: 4272kb

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
2521516047
1309403622
2546207262
2446335573
2173157697
2112317422
1541661140
2423431804
2209082718
1571719735
1330200071
2039708041
2262594131
1327470290
996805867
1826546180
2157986113
1706604892
2879605727
2226683395
2943744963
2090539403
666502909
14660...

result:

wrong answer 5th numbers differ - expected: '2591083202', found: '2521516047'