传送门

对于某个点 $(x,y)$ ,不妨设 $x<y$ 因为如果 $x>y$ 直接按 $y=x$ 对称一下即可

当且仅当正方形左下角 $(a,a)$ 满足 $a<=x$,右上角 $(b,b)$ 满足 $b>=y$ ,才能得到这个点的价值

所以发现其实是个二维偏序的问题,直接把 $(a,b)$ 看成另一个平面上的点,$(x,y)$ 放到那个平面上

这样就问题变成选一个点 $(a,b)$ ,你得到的价值为所有 $x>=a$ 并且 $y<=b$ 的点 $(x,y)$ 的价值和再减去 $a,b$ 之间的差值

考虑把点按第一关键字 $x$ 从大到小,按第二关键字 $y$ 从小到大排序,维护一个线段树表示当前 $a=x$ 的情况下 $y$ 取各个值时能够得到的最大价值

因为当前 $a=x$ 的情况下,所有 $x>a$ 的点的代价都加入了,每次加入一个点以后直接查询线段树上 $b>=y$ 和下一个点 $b<=y'-1$ 之间的那一段的最大价值,当然如果下一个点的 $x$ 和当前点不同,那么查询直接查询当前点到线段树最大位置的值即可

发现这样是有问题的,因为对于不同的 $b=y$ ,直接取点的值最大还不行,因为代价还要考虑 $-(y-x)$,所以线段树上维护的应该是点值和再减 $y$ 以后的最大值,当然要随便维护一下取最大值时 $b$ 的值

然后就没了,代码因为主体是比赛时写的,可能比较丑,但是还能看...吧

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=1e6+;
const ll INF=1e18;
int n,x[N],y[N],c[N],t[N],xx[N],yy[N];
struct dat {
int l,r,val,id;
dat (int _l=,int _r=,int _val=,int _id=) { l=_l,r=_r,val=_val,id=_id; }
inline bool operator < (const dat &tmp) const {
if(l!=tmp.l) return l>tmp.l;
return r!=tmp.r ? r<tmp.r : val>tmp.val;
}
}d[N];
int tot;
int inv[N];
struct SegTree {
ll T[N<<],id[N<<],tag[N<<];
inline void pushup(int o) { T[o]=max(T[o<<],T[o<<|]); id[o]=T[o<<]>=T[o<<|] ? id[o<<] : id[o<<|]; }
inline void pushdown(int o,int l,int r)
{
if(!o||!tag[o]) return;
T[o]+=tag[o]; if(l==r) { tag[o]=; return; }
tag[o<<]+=tag[o]; tag[o<<|]+=tag[o];
tag[o]=;
}
void build(int o,int l,int r)
{
if(l==r) { id[o]=l; T[o]=-inv[l]; return; }
int mid=l+r>>; build(o<<,l,mid); build(o<<|,mid+,r);
pushup(o);
}
inline void change(int o,int l,int r,int ql,int qr,int v)
{
pushdown(o,l,r);
if(l>qr||r<ql) return;
if(l>=ql&&r<=qr) { tag[o]=v; pushdown(o,l,r); return; }
int mid=l+r>>;
change(o<<,l,mid,ql,qr,v); change(o<<|,mid+,r,ql,qr,v);
pushup(o);
}
ll pos,val;
inline void query(int o,int l,int r,int ql,int qr)
{
pushdown(o,l,r);
if(l>qr||r<ql) return;
if(l>=ql&&r<=qr) { if(T[o]>val) val=T[o],pos=id[o]; return; }
int mid=l+r>>; query(o<<,l,mid,ql,qr); query(o<<|,mid+,r,ql,qr);
pushup(o);
}
}ST;
int main()
{
n=read();
for(int i=;i<=n;i++) xx[i]=x[i]=read(),yy[i]=y[i]=read(),c[i]=read();
for(int i=;i<=n;i++) t[++tot]=x[i],t[++tot]=y[i];
sort(t+,t+tot+); tot=unique(t+,t+tot+)-t-;
for(int i=;i<=n;i++) x[i]=lower_bound(t+,t+tot+,x[i])-t;
for(int i=;i<=n;i++) y[i]=lower_bound(t+,t+tot+,y[i])-t;
int ansx=,ansy=;
for(int i=;i<=n;i++)
{
if(x[i]>y[i]) swap(x[i],y[i]),swap(xx[i],yy[i]);
d[i]=dat(x[i],y[i],c[i],i);
ansx=max(ansx,yy[i]+); ansy=max(ansy,yy[i]+);
inv[x[i]]=xx[i]; inv[y[i]]=yy[i];
}
sort(d+,d+n+); ll ans=; ST.build(,,tot);
d[n+].l=-;
for(int i=;i<=n;i++)
{
ST.change(,,tot,d[i].r,tot,d[i].val);
ST.val=-INF; ST.pos=;
if(d[i].l==d[i+].l) ST.query(,,tot,d[i].r,d[i+].r-);
else ST.query(,,tot,d[i].r,tot);
ll res=ST.val+inv[d[i].l];
if(res>ans) ans=res,ansx=inv[d[i].l],ansy=inv[ST.pos];
}
printf("%lld\n",ans);
printf("%d %d %d %d\n",ansx,ansx,ansy,ansy);
return ;
}

Codeforces 1221F. Choose a Square的更多相关文章

  1. Codeforces Round #448 C. Square Subsets

    题目链接 Codeforces Round #448 C. Square Subsets 题解 质因数 *质因数 = 平方数,问题转化成求异或方程组解的个数 求出答案就是\(2^{自由元-1}\) , ...

  2. Codeforces 1221 F Choose a Square

    题面 不知道大佬们怎么想的,反正我看到这种区间包含性质的并且score只和包含的区间与询问区间挂钩的题,马上就想到了扫描线23333 虽然革命方向无比正确,但却因为SB错误交了5次才 A. WA第一发 ...

  3. Codeforces 710C. Magic Odd Square n阶幻方

    C. Magic Odd Square time limit per test:1 second memory limit per test:256 megabytes input:standard ...

  4. Codeforces 716C. Plus and Square Root-推公式的数学题

    http://codeforces.com/problemset/problem/716/C codeforces716C. Plus and Square Root 这个题就是推,会推出来规律,发现 ...

  5. Codeforces 1187 F - Expected Square Beauty

    F - Expected Square Beauty 思路:https://codeforces.com/blog/entry/68111 代码: #pragma GCC optimize(2) #p ...

  6. Codeforces 715A. Plus and Square Root[数学构造]

    A. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  7. 【模拟】Codeforces 710C Magic Odd Square

    题目链接: http://codeforces.com/problemset/problem/710/C 题目大意: 构造一个N*N的幻方.任意可行解. 幻方就是每一行,每一列,两条对角线的和都相等. ...

  8. Codeforces 679C Bear and Square Grid

    Bear and Square Grid 枚举k * k 的位置, 然后接上它周围白色连通块的数量, 再统计完全在k * k范围里的连通块, 这个只要某个连通块全部的方格 在k * k里面就好, 并且 ...

  9. CodeForces - 710C Magic Odd Square(奇数和幻方构造)

    Magic Odd Square Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, c ...

随机推荐

  1. Netty入门官方例子

    参考链接:https://blog.csdn.net/wocjy/article/details/78661464 maven依赖: <!-- Netty开始 --> <!-- ht ...

  2. Linux常用指令grep(搜索过滤)

    Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expression Print,表示全局正则表达 ...

  3. Python 之 try...except...错误捕捉

    Python常见异常类型大概分为以下类: 1.AssertionError:当assert断言条件为假的时候抛出的异常 2.AttributeError:当访问的对象属性不存在的时候抛出的异常 3.I ...

  4. PHP 分页+查询

    首先是主页面,与上篇分页页面相同 <table width="100%" border="1" cellpadding="0" cel ...

  5. windos批处理启动redis与哨兵

    为各个启动单独建立脚本后用总的bat调用 创建脚本,redis6379.bat脚本内容:@echo offtitle redis-serverset ENV_HOME6379="G:\Red ...

  6. iOS即时通讯之CocoaAsyncSocket源码解析三

    原文 前言 本文实例Github地址:即时通讯的数据粘包.断包处理实例. 本文旨以实例的方式,使用CocoaAsyncSocket这个框架进行数据封包和拆包.来解决频繁的数据发送下,导致的数据粘包.以 ...

  7. linux vim的全目录搜索 和 hostname的设置?

    vim下的搜索命令是: vimgrep, 简写就是vim. 关于这个全局搜索的用法根grep的差不多, 但是, 如果你直接使用 grep的话 就会在vim的外部执行, 根vim内部就没有什么关系了, ...

  8. 一些有意思的git

    fs: https://github.com/psankar/simplefs https://github.com/gzc/isystem/blob/master/basic/Crash_Consi ...

  9. Node某个JS导出方法变量以及在其他地方引用的例子

    //modelJs.js var name="miyue"; function doSomething() { console.log("做一些事情"); } ...

  10. Hibernate查询总的记录数

    1. 原生sql String hql="select count(*) from product" ;//此处的product是数据库中的表名 Query query=sessi ...