社区讨论
只WA1是什么神奇的错误???
P14966Staring at Stars参与者 1已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mkmf75k8
- 此快照首次捕获于
- 2026/01/20 17:57 4 周前
- 此快照最后确认于
- 2026/01/20 20:40 4 周前
求hack
CPP#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
typedef long long ll;
struct node{
ll x,y,d;
bool operator == (const node& z){
return x == z.x && y == z.y;
}
}a[N];
int t,n,k;
ll sum[N];
bool cmp(node p,node q){
if(p.x != q.x) return p.x < q.x;
if(p.y != q.y) return p.y < q.y;
}
int main(){
cin>>t;
while(t--){
ll ans = 0;
int pos = 1;//去重后的下标
memset(sum,0,sizeof(sum));
cin>>n>>k;
for(int i = 1; i <= n; i++)
cin>>a[i].x>>a[i].y>>a[i].d;
sort(a+1,a+1+n,cmp);
auto last = unique(a+1,a+1+n);//排序去重
for(auto i = a+1; i != last; i++,pos++){
sum[pos] = sum[pos-1]+a[pos].d;
}
a[pos].d = 1e18; a[pos].x = 1e18; a[pos].y = 1e18;//不可能达到的值
for(int t = 1; t*t <= k; t++){
int h = k/t;
for(int l = 1, r = 1; l < pos && r <= pos; ){//多看一个
if(l == r) {r++; continue;}
//不在同一x
if(a[l].x != a[r].x){
ans = max(ans,(sum[r-1] - sum[l-1])*h);
//cout<<l<" "<<r<<" "<<ans<<endl;
l = r; continue;
}
if(a[r].y - a[l].y > t){
ans = max(ans,(sum[r-1] - sum[l-1])*h);
//cout<<l<" "<<r<<" "<<ans<<endl;
l = r; continue;
}
if(a[r].y - a[l].y <= t) r++;
}
}
cout<<ans<<'\n';
}
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...