题意:n个左下角为原点右上角在第一象限的矩形不断覆盖,求最后形成的图形的周长

x和y是独立的,分别维护两棵线段树,一棵表示x坐标下最大的y值,另一棵表示y坐标下最大的x值

从覆盖的角度来考虑,如果逆序处理,当前处理的段的贡献为大于等于当前位置的最大值的差

比如一条横的线段i,坐标为[x1=0,x2],y

那它对答案的贡献为max(0,x2 - max_x of [y,maxy]),此时的区间存在的线段为逆序第n条到第i+1条

处理完后再插入到对应的线段树中即可(其实贡献为0的不插也行,因为都是不断取一个后缀最大的值)

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define println(a) printf("%lld\n",(ll)(a))
#define printbk(a) printf("%lld ",(ll)(a))
typedef long long ll;
using namespace std;
const int MAXN = 2e5+11;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const ll ooo= 0x3f3f3f3f;
const int MOD = 1e9+7;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
struct ST{
#define lc o<<1
#define rc o<<1|1
ll mx[MAXN<<2];
void pu(int o){
mx[o]=max(mx[lc],mx[rc]);
}
void update(int o,int l,int r,int k,ll v){
if(l==r){
mx[o]=max(mx[o],v);
return;
}
int mid=l+r>>1;
if(k<=mid) update(lc,l,mid,k,v);
else update(rc,mid+1,r,k,v);
pu(o);
}
ll query(int o,int l,int r,int L,int R){
if(L<=l&&r<=R) return mx[o];
int mid=l+r>>1;
ll ans=0;
if(L<=mid) ans=max(ans,query(lc,l,mid,L,R));
if(R>mid) ans=max(ans,query(rc,mid+1,r,L,R));
return ans;
}
}st[2]; struct QAQ{
int x, y;
int _x,_y;
QAQ(int Q=0,int A=0){
x=Q;
y=A;
}
}a[MAXN];
int xx[MAXN],yy[MAXN],n;
int main(){
while(cin>>n){
int cnt=0;
rep(i,1,n){
int x=read();
int y=read();
a[i]=QAQ(x,y);
xx[++cnt]=x;
yy[cnt]=y;
}
sort(xx+1,xx+1+cnt);
sort(yy+1,yy+1+cnt);
rep(i,1,n){
a[i]._x=lower_bound(xx+1,xx+1+cnt,a[i].x)-xx;
a[i]._y=lower_bound(yy+1,yy+1+cnt,a[i].y)-yy;
}
rep(i,0,1) memset(st[i].mx,0,sizeof st[i].mx);
//st[0]: x坐标下最大的y
//st[1]: y坐标下最大的x
ll ans=0;
rrep(i,n,1){
int x=a[i].x;
int y=a[i].y;
int xid=a[i]._x;
int yid=a[i]._y;
ll t1=st[1].query(1,1,cnt,yid,cnt);
if(t1<x) ans+=x-t1;
st[1].update(1,1,cnt,yid,x);
ll t2=st[0].query(1,1,cnt,xid,cnt);
if(t2<y) ans+=y-t2;
st[0].update(1,1,cnt,xid,y);
}
println(ans);
}
return 0;
}

2018徐州网络赛 - Trace的更多相关文章

  1. ACM-ICPC 2018徐州网络赛-H题 Ryuji doesn't want to study

    死于update的一个long long写成int了 真的不想写过程了 ******** 树状数组,一个平的一个斜着的,怎么斜都行 题库链接:https://nanti.jisuanke.com/t/ ...

  2. 2018徐州网络赛H. Ryuji doesn't want to study

    题目链接: https://nanti.jisuanke.com/t/31458 题解: 建立两个树状数组,第一个是,a[1]*n+a[2]*(n-1)....+a[n]*1;第二个是正常的a[1], ...

  3. 2018 ICPC 徐州网络赛

    2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...

  4. 2018 CCPC网络赛

    2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物 ...

  5. 计蒜客 41391.query-二维偏序+树状数组(预处理出来满足情况的gcd) (The Preliminary Contest for ICPC Asia Xuzhou 2019 I.) 2019年徐州网络赛)

    query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be rep ...

  6. ICPC 2019 徐州网络赛

    ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才 ...

  7. [徐州网络赛]Longest subsequence

    [徐州网络赛]Longest subsequence 可以分成两个部分,前面相同,然后下一个字符比对应位置上的大. 枚举这个位置 用序列自动机进行s字符串的下标转移 注意最后一个字符 #include ...

  8. 徐州网络赛F-Feature Trace【暴力】

    Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat moveme ...

  9. 徐州网络赛G-Trace【线段树】

    There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy  ...

随机推荐

  1. Java Thread系列(十)Future 模式

    Java Thread系列(十)Future 模式 Future 模式适合在处理很耗时的业务逻辑时进行使用,可以有效的减少系统的响应时间,提高系统的吞吐量. 一.Future 模式核心思想 如下的请求 ...

  2. Java设计模式(7)——装饰者模式

    转载:http://blog.csdn.net/yanbober/article/details/45395747 一.装饰者模式的定义 装饰者( Decorator )模式又叫做包装模式.通过一种对 ...

  3. mysql5.7文件无法导入数据库的解决方案

    一般是因为my.ini的“secure-file-priv”的设置导致loaddata失败,网上查了许多资料,大部分都是要求注释掉my.ini的: secure-file-priv="C:/ ...

  4. 用word2016 写CSDN 博客

    目前大部分的博客作者在用Word写博客这件事情上都会遇到以下3个痛点: 1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.使用Word写 ...

  5. word 2007 写CSDN博客

    目前大部分的博客作者在用Word写博客这件事情上都会遇到以下3个痛点: 1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.使用Word写 ...

  6. 二道Const,readonly 和 override, new的面试题

    1. Const 和 readonly ; ; ; ; static void Main(string[] args) { Console.WriteLine("aa:{0},bb:{1}, ...

  7. osx上使用'cd'命令跳转到别名(alias)目录

    在mac上使用windows的共享目录时,在terminal中时法使用cd的,会提示"xxx 不是目录",经过一番的查找,发现了Mac Terminal 'cd' to folde ...

  8. FTPClient用法

      某些数据交换,我们需要通过ftp来完成. sun.net.ftp.FtpClient 可以帮助我们进行一些简单的ftp客户端功能:下载.上传文件. 但如遇到创建目录之类的就无能为力了,我们只好利用 ...

  9. 记那些年在asp.net mvc上挖过的坑

    表现: IDE是vs2017.是在 A 控制器方法断点后,却怎么也运行不到那个位置,但是又正常返回页面.该方法位于web项目引用的控制器类库上的一个控制器,试过它隔壁的控制器,一切正常. 但每次访问该 ...

  10. UVA 11426 GCD - Extreme (II)(欧拉函数打表 + 规律)

    Given the value of N, you will have to find the value of G. The definition of G is given below:Here ...