题意:

给你n条平行于坐标轴的线,问你能组成多少个矩形,坐标绝对值均小于5000

保证线之间不会重合或者退化

思路:

从下到上扫描每一条纵坐标为y的水平的线,然后扫描所有竖直的线并标记与它相交的线,保证上端至少多出1

并用树状数组维护它们

然后从y+1网上扫描纵坐标为yy的水平的线,查询y到yy中同时与他们相交的竖直的线的条数算贡献即可

每查询完一个yy后,要在树状数组内删除上端点为yy的竖直的线,因为以后的yy与它不会再相交了

代码:

几乎是照着官方题解来的。。

#include<iostream>
#include<cstdio>
#include<algorithm>
//#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1 using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 1e4+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
//const db pi = acos(-1.0); int n;
struct node{
int l,r;
int x;
node(){}
node(int a,int b,int c):l(a),r(b),x(c){}
};
vector<node>vt[maxn],hr[maxn];
vector<int>tmp[maxn];
int tree[maxn*];
int lowbit(int x){
return x&-x;
}
void add(int x,int C){
for(int i=x;i<maxn-;i+=lowbit(i)){
tree[i]+=C;
}
}
int sum(int x){
int ans=;
for(int i=x;i;i-=lowbit(i)){
ans+=tree[i];
}
return ans;
} int main(){
scanf("%d", &n);
for(int i = ; i <= n; i++){
int x1,y1,x2,y2;
scanf("%d %d %d %d" ,&x1, &y1, &x2, &y2);
x1+=;x2+=;
y1+=;y2+=;
if(x1==x2){
vt[x1].pb(node(min(y1,y2),max(y1,y2),x1));
}
else{
hr[y1].pb(node(min(x1,x2),max(x1,x2),y1));
//printf("===%d\n",y1-5000);
}
}
ll ans = ;
for(int y = ; y < maxn-; y++){
for(int i = ; i < hr[y].size(); i++){
//for(int j = 0; j < maxn-10; j++)tmp[j].clear();
//mem(tree,0);
node lne = hr[y][i];
int l = lne.l, r = lne.r;
for(int x = l; x <= r; x++){
for(int j = ; j < (int)vt[x].size(); j++){
if(vt[x][j].l<=y&&vt[x][j].r>=y+){
add(x,);
tmp[vt[x][j].r].pb(x);
} }
}
for(int yy = y+; yy < maxn-; yy++){
for(int j = ; j < (int)hr[yy].size(); j++){
ll res = sum(hr[yy][j].r)-sum(hr[yy][j].l-);
ans+=res*(res-)/;
}
for(int j = ; j < (int)tmp[yy].size(); j++){
add(tmp[yy][j],-);
}
tmp[yy].clear();
} }
}
printf("%lld",ans);
return ;
}
/* */

Codeforces 1197E Count The Rectangles(树状数组+扫描线)的更多相关文章

  1. Codeforces 786C Till I Collapse(树状数组+扫描线+倍增)

    [题目链接] http://codeforces.com/contest/786/problem/C [题目大意] 给出一个数列,问对于不同的k,将区间划分为几个, 每个区间出现不同元素个数不超过k时 ...

  2. BZOJ 1452: [JSOI2009]Count 二维树状数组

    1452: [JSOI2009]Count Description Input Output Sample Input Sample Output 1 2 HINT Source 题解:设定C[101 ...

  3. Codeforces 703D Mishka and Interesting sum(树状数组+扫描线)

    [题目链接] http://codeforces.com/contest/703/problem/D [题目大意] 给出一个数列以及m个询问,每个询问要求求出[L,R]区间内出现次数为偶数的数的异或和 ...

  4. CodeForces 828E DNA Evolution(树状数组)题解

    题意:给你一个串k,进行两个操作: “1 a b”:把a位置的字母换成b “2 l r s”:求l到r有多少个字母和s匹配,匹配的条件是这样:从l开始无限循环s形成一个串ss,然后匹配ss和指定区间的 ...

  5. Codeforces 909C Python Indentation:树状数组优化dp

    题目链接:http://codeforces.com/contest/909/problem/C 题意: Python是没有大括号来标明语句块的,而是用严格的缩进来体现. 现在有一种简化版的Pytho ...

  6. Count(二维树状数组)

    [bzoj1452][JSOI2009]Count Description Input Output Sample Input Sample Output 12   HINT 题解:对于每一个颜色建一 ...

  7. CodeForces - 597C Subsequences 【DP + 树状数组】

    题目链接 http://codeforces.com/problemset/problem/597/C 题意 给出一个n 一个 k 求 n 个数中 长度为k的上升子序列 有多少个 思路 刚开始就是想用 ...

  8. Codeforces 635D Factory Repairs【树状数组】

    又是看了很久的题目... 题目链接: http://codeforces.com/contest/635/problem/D 题意: 一家工厂生产维修之前每天生产b个,维修了k天之后每天生产a个,维修 ...

  9. codeforces 570 D. Tree Requests 树状数组+dfs搜索序

    链接:http://codeforces.com/problemset/problem/570/D D. Tree Requests time limit per test 2 seconds mem ...

随机推荐

  1. 用ES5实现ES6的数组方法map

    先举个常见的栗子: var arr = [1,2,3,4,6,7,8,9,12,3,25,63,100] var arr2 = arr.map(item => item += 1) consol ...

  2. Scala实践3

    一.函数式对象 1.1  rational类的规格和创建 Rational类来源于有理数(rational number),来表示n(分子)/d(分母)的数字,同时对有理数的运算(加减乘除)建模,还具 ...

  3. 数据量不足,MedicalNet 如何助力医疗影像 AI 突破瓶颈?

    ​导读 |近日,云+社区技术沙龙“腾讯开源技术”圆满落幕.本次沙龙邀请了多位腾讯技术专家,深度揭秘了腾讯开源项目TencentOS tiny.TubeMQ.Kona JDK.TARS以及Medical ...

  4. Spring Boot2 系列教程 (十四) | 统一异常处理

    如题,今天介绍 SpringBoot 是如何统一处理全局异常的.SpringBoot 中的全局异常处理主要起作用的两个注解是 @ControllerAdvice 和 @ExceptionHandler ...

  5. 【LC_Lesson2】---整数反转练习

    题目描述: 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: -123 输出: -321 示例 3: 输入: 1 ...

  6. 2018 CCPC 网络赛

    The Power Cube is used as a stash of Exotic Power. There are n cities numbered 1,2,…,n where allowed ...

  7. 树上对抗搜索 - 树形dp

    Alice and Bob are going on a trip. Alice is a lazy girl who wants to minimize the total travelling d ...

  8. Linux下利用Ant调用Jmeter脚本生成HTML测试报告

    今天我们学习如何利用Ant调用Jmeter脚本,并将生成的 jtl 文件转换为 HTML 格式的测试报告. 准备工作 需要在Linux上提前安装好 JDK. Jmeter 和 Ant. 1,JDK(可 ...

  9. synchronized底层实现

    1.锁升级的过程 当多个线程同时竞争一个对象监视器时:当前对象结构中的mark word中是否是当前线程id,如果是则当前线程获得偏向锁. 如果不是,则通过CAS将当前线程id置换到mark word ...

  10. 创建dynamics CRM client-side (十四) - Web API

    Xrm.WebApi 是我们做前端开发不可不缺少的内容. Xrm.WebApi 分为online和offline online: 可以实现和服务器的CRUD交互 offline: 多用于mobile ...