QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#228059 | #7582. Snowy Smile | Giga_Cronos# | AC ✓ | 744ms | 4336kb | C++14 | 2.3kb | 2023-10-28 11:16:26 | 2023-10-28 11:16:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mid ((L+R)/2)
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
const int MAXN=2000;
struct nod{
int L,R,Sum,Best;
};
nod St[8000];
nod merge(const nod & A,const nod &B){
nod C;
C.Best=max(A.Best,B.Best);
C.Best=max(A.R+B.L,C.Best);
C.Sum=A.Sum+B.Sum;
C.L=max(A.L,B.L+A.Sum);
C.R=max(A.R+B.Sum,B.R);
return C;
}
int Arr[MAXN];
void update(int node,int L,int R,int pos){
if(L==R){
St[node]={max(0ll,Arr[L]),max(0ll,Arr[L]),Arr[L],max(0ll,Arr[L])};
return;
}
if(pos<=mid){
update(2*node,L,mid,pos);
}else{
update(2*node+1,mid+1,R,pos);
}
St[node]=merge(St[2*node],St[2*node+1]);
}
int n,k,m;
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int tc=1;
cin>>tc;
while(tc--){
cin>>n;
map<pii,int> M;
vi CoordX;
vi CoordY;
map<int,int> MX;
map<int,int> MY;
for(int i=0;i<n;i++){
int x,y,w;
cin>>x>>y>>w;
M[{x,y}]+=w;
CoordX.pb(x);
CoordY.pb(y);
}
sort(all(CoordX));
CoordX.resize(unique(all(CoordX))-CoordX.begin());
sort(all(CoordY));
CoordY.resize(unique(all(CoordY))-CoordY.begin());
for(int i=0;i<sz(CoordX);i++){
MX[CoordX[i]]=i;
}
for(int i=0;i<sz(CoordY);i++){
MY[CoordY[i]]=i;
}
vvpii X(sz(CoordX));
for(auto &p:M){
X[MX[p.fs.fs]].pb({MY[p.fs.sc],p.sc});
}
int ans=0;
for(int i=0;i<sz(X);i++){
memset(St,0,sizeof(St));
memset(Arr,0,sizeof(Arr));
for(int j=i;j>=0;j--){
for(const pii &p:X[j]){
Arr[p.fs]+=p.sc;
update(1,0,sz(CoordY)-1,p.fs);
}
ans=max(ans,St[1].Best);
}
}
cout<<ans<<"\n";
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3812kb
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: 744ms
memory: 4336kb
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