QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771584 | #7582. Snowy Smile | tarjen# | AC ✓ | 1230ms | 4304kb | C++20 | 2.3kb | 2024-11-22 14:23:10 | 2024-11-22 14:23:17 |
Judging History
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(b.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);
// cout<<"i="<<i<<" j="<<j<<" ans="<<tri.query(1,1,cnty).ans<<endl;
// for(int k=1;k<=cnty;k++)cout<<tri.query(1,k,k).sum<<" \n"[k==cnty];
}
}
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: 3852kb
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: 1230ms
memory: 4304kb
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