【题目链接】

点击打开链接

【算法】

线段树扫描线求周长并

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 5010 int i,L,R,l1,l2,ans,last,n,xa,xb,ya,yb;
int x[MAXN*]; struct info {
int l,r,h,opt;
} y[MAXN*];
struct Node {
int l,r,sum,cnt,c;
bool lc,rc;
} Tree[MAXN*]; bool cmp(info a,info b) { return a.h > b.h; }
template <typename T> inline void read(T &x) {
int f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
}
template <typename T> inline void writeln(T x) {
write(x);
puts("");
}
inline void build(int index,int l,int r) {
int mid;
Tree[index].l = l;
Tree[index].r = r;
Tree[index].c = Tree[index].sum = Tree[index].cnt = ;
Tree[index].lc = Tree[index].rc = false;
if (l == r) return;
mid = (l + r) >> ;
build(index<<,l,mid);
build(index<<|,mid+,r);
}
inline void push_up(int index) {
if (Tree[index].c > ) {
Tree[index].sum = x[Tree[index].r+] - x[Tree[index].l];
Tree[index].cnt = ;
Tree[index].lc = Tree[index].rc = true;
} else if (Tree[index].l == Tree[index].r) {
Tree[index].sum = Tree[index].cnt = ;
Tree[index].lc = Tree[index].rc = false;
} else {
Tree[index].lc = Tree[index<<].lc;
Tree[index].rc = Tree[index<<|].rc;
Tree[index].sum = Tree[index<<].sum + Tree[index<<|].sum;
Tree[index].cnt = Tree[index<<].cnt + Tree[index<<|].cnt;
if (Tree[index<<].rc && Tree[index<<|].lc) Tree[index].cnt--;
}
}
inline void update(int index,int l,int r,int val) {
int mid;
if (Tree[index].l == l && Tree[index].r == r) {
Tree[index].c += val;
push_up(index);
return;
}
mid = (Tree[index].l + Tree[index].r) >> ;
if (mid >= r) update(index<<,l,r,val);
else if (mid + <= l) update(index<<|,l,r,val);
else {
update(index<<,l,mid,val);
update(index<<|,mid+,r,val);
}
push_up(index);
} int main() { scanf("%d",&n);
l1 = l2 = ;
for (i = ; i <= n; i++) {
read(xa); read(ya); read(xb); read(yb);
x[++l1] = xa;
x[++l1] = xb;
y[++l2] = (info){xa,xb,ya,-};
y[++l2] = (info){xa,xb,yb,};
}
l1 = unique(x+,x+l1+) - x;
sort(x+,x+l1+);
build(,,l1-);
sort(y+,y+l2+,cmp);
ans = last = ;
for (i = ; i < l2; i++) {
L = lower_bound(x+,x+l1+,y[i].l) - x;
R = lower_bound(x+,x+l1+,y[i].r) - x - ;
update(,L,R,y[i].opt);
ans += Tree[].cnt * * (y[i].h - y[i+].h);
ans += abs(Tree[].sum - last);
last = Tree[].sum;
}
L = lower_bound(x+,x+l1+,y[l2].l) - x;
R = lower_bound(x+,x+l1+,y[l2].r) - x - ;
update(,L,R,y[l2].opt);
ans += abs(Tree[].sum - last);
writeln(ans); return ; }

【IOI 1998】 Picture的更多相关文章

  1. 【HDU 1828】 Picture (矩阵周长并,线段树,扫描法)

    [题目] Picture Problem Description A number of rectangular posters, photographs and other pictures of ...

  2. 【IOI 1996】 Network of Schools

    [题目链接] 点击打开链接 [算法] 对于第一问,将这个图缩点,输出出度为零的点的个数 对于第二问,同样将这个图缩点,输出入度为零.出度为零的点的个数的最大值 [代码] #include <al ...

  3. 【IOI 1994】 The Buses

    [题目链接] http://poj.org/problem?id=1167 [算法] 深度优先搜索 + 迭代加深 [代码] #include <algorithm> #include &l ...

  4. 【IOI 2011】Race

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2599 [算法] 点分治 [代码] #include<bits/stdc++.h ...

  5. 【49.23%】【hdu 1828】Picture

    Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

  6. 【BZOJ 1998】 1998: [Hnoi2010]Fsk物品调度(双向链表+并查集+置换)

    1998: [Hnoi2010]Fsk物品调度 Description 现在找工作不容易,Lostmonkey费了好大劲才得到fsk公司基层流水线操作员的职位.流水线上有n个位置,从0到n-1依次编号 ...

  7. 【IOI 2018】Werewolf 狼人

    虽然作为IOI的Day1T3,但其实不是一道很难的题,或者说这道题其实比较套路吧. 接下来讲解一下这个题的做法: 如果你做过NOI 2018的Day1T1,并且看懂了题面,那你很快就会联想到这道题,因 ...

  8. 【IOI 2018】Combo 组合动作(模拟,小技巧)

    题目链接 IOI的签到题感觉比NOI的签到题要简单啊,至少NOI同步赛我没有签到成功…… 其实这个题还是挺妙妙的,如果能够从题目出发,利用好限制,应该是可以想到的做法的. 接下来开始讲解具体的做法: ...

  9. 【Vijos 1998】【SDOI 2016】平凡的骰子

    https://vijos.org/p/1998 三维计算几何. 需要混合积求四面体体积: 四面体剖分后合并带权重心求总重心: 四面体重心的横纵坐标是四个顶点的横纵坐标的平均数: 三维差积求平面的法向 ...

随机推荐

  1. PTA 03-树3 Tree Traversals Again (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/667 5-5 Tree Traversals Again   (25分) An inor ...

  2. 禁止ScrollView在子控件的布局改变时自动滚动的的方法

    重写scrollview中的如下方法,并将其返回值设为0即可. @Override  protected int computeScrollDeltaToGetChildRectOnScreen(Re ...

  3. mapStruct笔记

    背景 mapStruct 是一个方便对象转换的工具,类似的工具还有 Dozer, BeanUtils. 实现 mapStruct的核心是在编译期生成基于转换规则的 Impl 文件,运行时直接调用 Im ...

  4. [NOIP2000] 提高组 洛谷P1017 进制转换

    题目描述 我们可以用这样的方式来表示一个十进制数: 将每个阿拉伯数字乘以一个以该数字所处位置的(值减1)为指数,以10为底数的幂之和的形式.例如:123可表示为 1*10^2+2*10^1+3*10^ ...

  5. ES6__数据结构 Set

    /* 数据结构 Set */ /* *集合的基本概念:集合是由一组无序且唯一(即不能重复)的项组成的.这个数据结构使用了与有限集合相同的数学概念,应用在计算机的数据结构中. *特点:key 和 val ...

  6. linux下reboot和shutdown关机命令详解

    我 们在操作Linux v/服务器的时候肯定会有需要重启系统,或者关闭系统等操作.有些用户是直接到VPS主机商家面板上操作的,这样一来比较麻烦,二来有些面板还不易于使用 容易导致面板卡死.所以最好的方 ...

  7. iOS - 系统方法中弃用的关键字的了解 NS_AVAILABLE和NS_DEPRECATED

    NS_AVAILABLE_IOS(5_0)  这个方法可以在iOS5.0及以后的版本中使用,如果在比5.0更老的版本中调用这个方法,就会引起崩溃.  NS_AVAILABLE(_mac, _ios) ...

  8. List排列组合

    /** * 步骤::每次递归时,把原始数据和满足条件的工作空间复制一份,所有的操作均在复制文件中进行,目的就是保证不破坏原始数据, * 从而可以让一轮递归结束后可以正常进行下一轮. * 其次,把数据的 ...

  9. tomcat的安装和使用

    1.下载最新的tomcat:https://tomcat.apache.org/download-90.cgi 最新版本9.0.2属于beta版本,就没有必要尝鲜踩坑了 使用8.5.24的稳定版本的二 ...

  10. zedboard硬件连接过程

    1.      ZedBoard – Connect a 2nd micro-USBcable between the host machine and connector J17 (JTAG) 2. ...