【题目链接】

点击打开链接

【算法】

线段树扫描线求周长并

【代码】

  1. #include <algorithm>
  2. #include <bitset>
  3. #include <cctype>
  4. #include <cerrno>
  5. #include <clocale>
  6. #include <cmath>
  7. #include <complex>
  8. #include <cstdio>
  9. #include <cstdlib>
  10. #include <cstring>
  11. #include <ctime>
  12. #include <deque>
  13. #include <exception>
  14. #include <fstream>
  15. #include <functional>
  16. #include <limits>
  17. #include <list>
  18. #include <map>
  19. #include <iomanip>
  20. #include <ios>
  21. #include <iosfwd>
  22. #include <iostream>
  23. #include <istream>
  24. #include <ostream>
  25. #include <queue>
  26. #include <set>
  27. #include <sstream>
  28. #include <stdexcept>
  29. #include <streambuf>
  30. #include <string>
  31. #include <utility>
  32. #include <vector>
  33. #include <cwchar>
  34. #include <cwctype>
  35. #include <stack>
  36. #include <limits.h>
  37. using namespace std;
  38. #define MAXN 5010
  39.  
  40. int i,L,R,l1,l2,ans,last,n,xa,xb,ya,yb;
  41. int x[MAXN*];
  42.  
  43. struct info {
  44. int l,r,h,opt;
  45. } y[MAXN*];
  46. struct Node {
  47. int l,r,sum,cnt,c;
  48. bool lc,rc;
  49. } Tree[MAXN*];
  50.  
  51. bool cmp(info a,info b) { return a.h > b.h; }
  52. template <typename T> inline void read(T &x) {
  53. int f = ; x = ;
  54. char c = getchar();
  55. for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
  56. for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
  57. x *= f;
  58. }
  59. template <typename T> inline void write(T x) {
  60. if (x < ) { putchar('-'); x = -x; }
  61. if (x > ) write(x/);
  62. putchar(x%+'');
  63. }
  64. template <typename T> inline void writeln(T x) {
  65. write(x);
  66. puts("");
  67. }
  68. inline void build(int index,int l,int r) {
  69. int mid;
  70. Tree[index].l = l;
  71. Tree[index].r = r;
  72. Tree[index].c = Tree[index].sum = Tree[index].cnt = ;
  73. Tree[index].lc = Tree[index].rc = false;
  74. if (l == r) return;
  75. mid = (l + r) >> ;
  76. build(index<<,l,mid);
  77. build(index<<|,mid+,r);
  78. }
  79. inline void push_up(int index) {
  80. if (Tree[index].c > ) {
  81. Tree[index].sum = x[Tree[index].r+] - x[Tree[index].l];
  82. Tree[index].cnt = ;
  83. Tree[index].lc = Tree[index].rc = true;
  84. } else if (Tree[index].l == Tree[index].r) {
  85. Tree[index].sum = Tree[index].cnt = ;
  86. Tree[index].lc = Tree[index].rc = false;
  87. } else {
  88. Tree[index].lc = Tree[index<<].lc;
  89. Tree[index].rc = Tree[index<<|].rc;
  90. Tree[index].sum = Tree[index<<].sum + Tree[index<<|].sum;
  91. Tree[index].cnt = Tree[index<<].cnt + Tree[index<<|].cnt;
  92. if (Tree[index<<].rc && Tree[index<<|].lc) Tree[index].cnt--;
  93. }
  94. }
  95. inline void update(int index,int l,int r,int val) {
  96. int mid;
  97. if (Tree[index].l == l && Tree[index].r == r) {
  98. Tree[index].c += val;
  99. push_up(index);
  100. return;
  101. }
  102. mid = (Tree[index].l + Tree[index].r) >> ;
  103. if (mid >= r) update(index<<,l,r,val);
  104. else if (mid + <= l) update(index<<|,l,r,val);
  105. else {
  106. update(index<<,l,mid,val);
  107. update(index<<|,mid+,r,val);
  108. }
  109. push_up(index);
  110. }
  111.  
  112. int main() {
  113.  
  114. scanf("%d",&n);
  115. l1 = l2 = ;
  116. for (i = ; i <= n; i++) {
  117. read(xa); read(ya); read(xb); read(yb);
  118. x[++l1] = xa;
  119. x[++l1] = xb;
  120. y[++l2] = (info){xa,xb,ya,-};
  121. y[++l2] = (info){xa,xb,yb,};
  122. }
  123. l1 = unique(x+,x+l1+) - x;
  124. sort(x+,x+l1+);
  125. build(,,l1-);
  126. sort(y+,y+l2+,cmp);
  127. ans = last = ;
  128. for (i = ; i < l2; i++) {
  129. L = lower_bound(x+,x+l1+,y[i].l) - x;
  130. R = lower_bound(x+,x+l1+,y[i].r) - x - ;
  131. update(,L,R,y[i].opt);
  132. ans += Tree[].cnt * * (y[i].h - y[i+].h);
  133. ans += abs(Tree[].sum - last);
  134. last = Tree[].sum;
  135. }
  136. L = lower_bound(x+,x+l1+,y[l2].l) - x;
  137. R = lower_bound(x+,x+l1+,y[l2].r) - x - ;
  138. update(,L,R,y[l2].opt);
  139. ans += abs(Tree[].sum - last);
  140. writeln(ans);
  141.  
  142. return ;
  143.  
  144. }

【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. P1027 car的旅行路线

    car的旅行路线 洛谷链接 这个题关键就是 如何把每个点表示出来,其实求出四个点的坐标后,只需要把这些点连接起来,用一遍folyed求出最短路径就好了. 代码: #include<cmath&g ...

  2. git push ‘No refs in common and none specified’doing nothing问题解决

    git push ‘No refs in common and none specified’doing nothing问题解决 输入git push origin master即可解决问题

  3. UltraEdit-14.10.0.1024版本语法着色配置

    用了UltraEdit有段时间了,一直没做语法着色,当做普通文本编辑器使用,这也太委屈这个“神器”了. 今天就让它物尽其用吧.体验一把UltraEdit的语法高亮功能. 参考:http://www.1 ...

  4. 45个android实例源码分享

    分享45个android实例源码,很好很强大 http://www.apkbus.com/android-20978-1-1.html andriod闹钟源代码 http://www.apkbus.c ...

  5. 洛谷P3094 [USACO13DEC]假期计划Vacation Planning

    题目描述 有N(1 <= N <= 200)个农场,用1..N编号.航空公司计划在农场间建立航线.对于任意一条航线,选择农场1..K中的农场作为枢纽(1 <= K <= 100 ...

  6. type和metaclass元类

    元类type 1. 创建类的两种方式 (都是由type元类创建) 方式一: class Foo(object): # 默认metaclass = type, 当前类, 由type类创建 a = 'aa ...

  7. hdu - 5128 The E-pang Palace(枚举+计算几何)

    http://acm.hdu.edu.cn/showproblem.php?pid=5128 给出n个点,求n个点组成两个矩形的最大面积. 矩形必须平行x轴,并且不能相交,但是小矩形在大矩形内部是可以 ...

  8. 关于Chrome谷歌浏览器开发者工具网络Network中返回无数据的问题

    1.如图所示,对于有些js文件,响应中无返回数据,Failed to load response data,当然本来是应该有数据,你用火狐浏览器看,就是有的,或者直接在浏览器地址栏里输入url,也可以 ...

  9. 海量数据处理面试题学习zz

    来吧骚年,看看海量数据处理方面的面试题吧. 原文:(Link, 其实引自这里 Link, 而这个又是 Link 的总结) 另外还有一个系列,挺好的:http://blog.csdn.net/v_jul ...

  10. centos Crontab

    minute   hour   day   month   week   command     顺序:分 时 日 月 周 命令 第1列分钟1-59第2列小时1-23(0表示子夜)第3列日1-31第4 ...