题意:

给你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. Ant Design 表单中getFieldDecorator、getFieldValue、setFieldValue用法

    Ant Design 表单中getFieldDecorator.getFieldValue.setFieldValue用法 一.getFieldDecorator getFieldDecorator是 ...

  2. 二分查找LintcodeNo14

    14First Position of Target 二分查找的基础题 STL lower_bound实现 class Solution { public: /** * @param nums: Th ...

  3. nor flash之写保护

    背景 没有电池的嵌入式设备,很容易发生随机掉电.因此要让产品可靠稳定,就必须保证各种场景下的掉电安全. 例如系统更新过程随机掉电,不能导致系统无法启动.例如正常读写flash过程中掉电,最多正在传输的 ...

  4. 更加清晰的TFRecord格式数据生成及读取

    TFRecords 格式数据文件处理流程 TFRecords 文件包含了 tf.train.Example 协议缓冲区(protocol buffer),协议缓冲区包含了特征 Features.Ten ...

  5. 悄摸直播(二)—— 播流器实现(拉取rtmp服务器中的数据流,播放直播画面)

    悄摸直播 -- JavaCV实现本机摄像头画面远程直播 播流器 一.功能说明 从rtmp服务器中获取视频流数据 + 展示直播画面 二.代码实现 /** * 播流器 * @param inputPath ...

  6. 虚拟机安装(Vmware14)

    下载Vmvare,然后安装. 安装成功后,对两个版本的了解:简单来说Pro的版本更复杂. 创建新的虚拟机时遇到提示BIOS固件问题,提示说Intel的Uirtualizatuion未被激活,解决方案关 ...

  7. struct结构体 重载运算符

    struct node{ int x,y,z; }; bool operator<(node a,node b) { if(a.x!=b.x) return a.x<b.x; if(a.y ...

  8. 使用ajax向后台发送请求跳转页面无效的原因

    Ajax只是利用脚本访问对应url获取数据而已,不能做除了获取返回数据以外的其它动作了.所以浏览器端是不会发起重定向的. 1)正常的http url请求,只有浏览器和服务器两个参与者.浏览器端发起一个 ...

  9. Redis系列(二):Redis的5种数据结构及其常用命令

    上一篇博客,我们讲解了什么是Redis以及在Windows和Linux环境下安装Redis的方法, 没看过的同学可以点击以下链接查看: Redis系列(一):Redis简介及环境安装. 本篇博客我们来 ...

  10. 创建过滤扩展方法 Creating Filtering Extension Methods 精通ASP-NET-MVC-5-弗瑞曼 Listing 4-17