1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define pb push_back
  5. #define lb lower_bound
  6. #define ull unsigned ll
  7. #define gcd(a,b) __gcd(a,b)
  8. #define pii pair<int,int>
  9. #define all(x) x.begin(),x.end()
  10. #define ll long long
  11. #define mp make_pair
  12. //#define pi acos(-1)
  13.  
  14. #define mod 1000000007
  15. #define inf (1LL<<31)-1
  16.  
  17. map<int,vector<pii> > X,Y;
  18. vector<pair<int,pii> > V;
  19.  
  20. const int mx = 200005;
  21. int tree[mx], pos[mx],N;
  22.  
  23. int getPos(int n)
  24. {
  25. return (int) (lb(pos,pos+N,n)-pos) + 1;
  26. }
  27.  
  28. int update(int idx,int val)
  29. {
  30. while(idx<=N)
  31. {
  32. tree[idx] += val;
  33. idx += (idx&-idx);
  34. }
  35. return 0;
  36. }
  37.  
  38. int sum(int idx)
  39. {
  40. int res = 0;
  41. while(idx>0)
  42. {
  43. res += tree[idx];
  44. idx -= (idx&-idx);
  45. }
  46. return res;
  47. }
  48.  
  49. int main()
  50. {
  51. int i,j,k,n;
  52. scanf("%d",&n);
  53. int x1,y1,x2,y2;
  54. for(i=0;i<n;i++)
  55. {
  56. scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
  57. if(x1>x2) swap(x1,x2);
  58. if(y1>y2) swap(y1,y2);
  59. if(x1==x2) Y[x1].pb(mp(y1,y2));
  60. else X[y1].pb(mp(x1,x2));
  61. pos[N++] = y1;
  62. pos[N++] = y2;
  63. }
  64. sort(pos,pos+N);
  65. N = (int) (unique(pos,pos+N)-pos);
  66.  
  67. map<int,vector<pii> > :: iterator it;
  68.  
  69. ll ans = 0;
  70. for(it=X.begin();it!=X.end();it++)
  71. {
  72. vector<pii>& vt = it -> second;
  73. sort(all(vt));
  74. int y = (it -> first);
  75. int x1 = vt[0].first;
  76. int x2 = vt[0].second;
  77. int sz = vt.size();
  78. for(i=1;i<sz;i++)
  79. {
  80. if(x2<vt[i].first)
  81. {
  82. ans += (x2-x1+1);
  83. V.pb(mp(x1,mp(-1,y)));
  84. V.pb(mp(x2+1,mp(1,y)));
  85. x1 = vt[i].first;
  86. x2 = vt[i].second;
  87. }
  88. else x2 = max(x2,vt[i].second);
  89. }
  90. ans += (x2-x1+1);
  91. V.pb(mp(x1,mp(-1,y)));
  92. V.pb(mp(x2+1,mp(1,y)));
  93. }
  94.  
  95. int m = V.size(), p = 0;
  96. sort(all(V));
  97. for(it=Y.begin();it!=Y.end();it++)
  98. {
  99. vector<pii>& vt = it -> second;
  100. sort(all(vt));
  101. int x = (it -> first);
  102.  
  103. while(p<m&&x>=V[p].first)
  104. {
  105. int t1 = V[p].second.first;
  106. int t2 = V[p].second.second;
  107. t2 = getPos(t2);
  108. update(t2,-t1);
  109. p++;
  110. }
  111.  
  112. int y1 = vt[0].first;
  113. int y2 = vt[0].second;
  114. int sz = vt.size();
  115. for(i=1;i<sz;i++)
  116. {
  117. if(y2<vt[i].first)
  118. {
  119. ans += (y2-y1+1);
  120. y2 = getPos(y2);
  121. y1 = getPos(y1);
  122. ans -= sum(y2) - sum(y1-1);
  123. y2 = vt[i].second;
  124. y1 = vt[i].first;
  125. }
  126. else y2 = max(y2,vt[i].second);
  127. }
  128. ans += (y2-y1+1);
  129. y2 = getPos(y2);
  130. y1 = getPos(y1);
  131. ans -= sum(y2) - sum(y1-1);
  132. }
  133. cout << ans << endl;
  134. }

  

codeforce div 377的更多相关文章

  1. CodeForce Div 2 C. Masha and two friends

    题目链接: http://codeforces.com/contest/1080/problem/C 思路:双向延长两个矩形方块的4边,会形成一个被分割为9块的更大立方体. 计算所有的9个方框.方框中 ...

  2. Codeforces Round #377 (Div. 2) D. Exams

    Codeforces Round #377 (Div. 2) D. Exams    题意:给你n个考试科目编号1~n以及他们所需要的复习时间ai;(复习时间不一定要连续的,可以分开,只要复习够ai天 ...

  3. Codeforces Round #377 (Div. 2)

    #include <iostream> #include <stdio.h> #include <string.h> using namespace std; in ...

  4. codeforce AIM tech Round 4 div 2 B rectangles

    2017-08-25 15:32:14 writer:pprp 题目: B. Rectangles time limit per test 1 second memory limit per test ...

  5. Codeforces Round #377 (Div. 2) B. Cormen — The Best Friend Of a Man(贪心)

     传送门 Description Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has ...

  6. Codeforces Round #377 (Div. 2) D. Exams(二分答案)

    D. Exams Problem Description: Vasiliy has an exam period which will continue for n days. He has to p ...

  7. Codeforces Round #377 (Div. 2)D(二分)

    题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...

  8. Codeforce#331 (Div. 2) A. Wilbur and Swimming Pool(谨以此题来纪念我的愚蠢)

    C time limit per test 1 second memory limit per test 256 megabytes input standard input output stand ...

  9. Codeforces Round #377 (Div. 2) C. Sanatorium 水题

    C. Sanatorium time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. JQUERY添加、删除元素、eq()方法;

    一.jQuery - 添加元素 1.append() - 在被选元素内部的结尾插入指定内容 2.prepend() - 在被选元素内部的开头插入指定内容 3.after() - 在被选元素之后插入内容 ...

  2. 关于nginx配置的不完全总结

    请参考官方: http://wiki.nginx.org/HttpRewriteModule#Synopsis 关于缓存大小权限 error log 有如下日志:an upstream respons ...

  3. chrome 49 版本 跨越 --args --disable-web-security --user-data-dir

    转载: 做前端的,用Ajax获取数据,是常有的事情,同域下自然没问题了,如果是不同域获取数据,浏览器就有个同源策略的限制. 如图: Origin * is not allowed by Access- ...

  4. LEETCODE —— Best Time to Buy and Sell Stock II [贪心算法]

    Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a ...

  5. Highcharts中文参考手册

    Highcharts 是一个用纯JavaScript编写的一个图表库, 能够很简单便捷的在web网站或是web应用程序添加有交互性的图表,并且免费提供给个人学习.个人网站和非商业用途使用.HighCh ...

  6. win7下IIS错误:"无法访问请求的页面,因为该页的相关配置数据无效"的解决方法(转)

    今天新装win7,然后在IIS下布署了一个网站,布署完成后运行,提示如下错误:HTTP 错误 500.19 - Internal Server Error无法访问请求的页面,因为该页的相关配置数据无效 ...

  7. 4、java中有专门的的函数对数组进行排序

    在java.util包中的Arrays提供了众多的排序算法可以应用.

  8. 【Java数据格式化】使用DecimalFormat 对Float和double进行格式化

    格式化包括如下内容: 基本用法 金钱格式: 科学计数法: 百分比计数法: 嵌入文本: package com.sssppp.NumberFormat; import java.text.Decimal ...

  9. My WelcomeApplet

    import java.applet.*; import java.awt.*; import java.awt.event.*; public class WelcomeApplet extends ...

  10. 黄聪: PHP WkHtmlToPdf/WkHtmlToImage 将网页直接转换成pdf和图片

    function convert($type='pdf') { $filename=time(); $url=$this->input->get("url"); if( ...