QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#219814 | #7582. Snowy Smile | PhantomThreshold# | AC ✓ | 858ms | 4304kb | C++20 | 1.7kb | 2023-10-19 18:38:31 | 2023-10-19 18:38:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=23333;
int lson[maxn],rson[maxn];
long long maxx[maxn],lmax[maxn],rmax[maxn],sum[maxn];
int root,top;
int build(int l,int r)
{
int ret=++top;
ret[lson]=ret[rson]=ret[maxx]=ret[lmax]=ret[rmax]=ret[sum]=0;
if(l!=r)
{
int mid=(l+r)/2;
ret[lson]=build(l,mid);
ret[rson]=build(mid+1,r);
}
return ret;
}
void upd(int x)
{
x[sum]=x[lson][sum]+x[rson][sum];
x[lmax]=max(x[lson][lmax],x[lson][sum]+x[rson][lmax]);
x[rmax]=max(x[rson][rmax],x[rson][sum]+x[lson][rmax]);
x[maxx]=max({x[lson][maxx],x[rson][maxx],x[lson][rmax]+x[rson][lmax]});
}
void change(int cur,int l,int r,int pos,int del)
{
if(l==r)
{
cur[sum]+=del;
cur[lmax]=cur[rmax]=cur[maxx]=max(cur[sum],0ll);
return;
}
int mid=(l+r)/2;
if(pos<=mid)change(cur[lson],l,mid,pos,del);
else change(cur[rson],mid+1,r,pos,del);
upd(cur);
}
long long query(){return root[maxx];}
int main()
{
ios_base::sync_with_stdio(false);
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
map<int,int> mpx,mpy;
vector<tuple<int,int,int>> a(n+5);
for(int i=1;i<=n;i++)
{
int x,y,w;
cin>>x>>y>>w;
mpx[x]=0;
mpy[y]=0;
a[i]={x,y,w};
}
int idx=0;
for(auto &[x,tx]:mpx)tx=++idx;
idx=0;
for(auto &[y,ty]:mpy)ty=++idx;
vector<vector<int>> event(idx+5);
for(int i=1;i<=n;i++)
{
auto &[x,y,w]=a[i];
x=mpx[x];y=mpy[y];
event[y].push_back(i);
}
long long ans=0;
for(int l=1;l<=idx;l++)
{
top=0;
root=build(1,n);
for(int r=l;r<=idx;r++)
{
for(auto id:event[r])
{
auto [x,y,w]=a[id];
change(root,1,n,x,w);
}
ans=max(ans,query());
}
}
cout<<ans<<endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
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: 858ms
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