Codeforces 216D Spider's Web 树状数组+模拟
题目链接:http://codeforces.com/problemset/problem/216/D
题意:
对于一个梯形区域,假设梯形左边的点数!=梯形右边的点数,那么这个梯形为红色。否则为绿色,
问:
给定的蜘蛛网中有多少个红色。
2个树状数组维护2个线段。然后暴力模拟一下,由于点数非常多但须要用到的线段树仅仅有3条,所以类似滚动数组的思想优化内存。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
#define N 10010
#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define ll int
int maxn;
struct hehe{
int c[100505];
void init(){memset(c, 0, sizeof c);}
inline int Lowbit(int x){return x&(-x);}
void change(int i, int x)//i点增量为x
{
while(i <= maxn)
{
c[i] += x;
i += Lowbit(i);
}
}
int sum(int x){//区间求和 [1,x]
int ans = 0;
for(int i = x; i >= 1; i -= Lowbit(i))
ans += c[i];
return ans;
}
}tree[2];
int ans;
vector<int>l,r,o;
void work(){
if(o.size()<=1)return;
tree[0].init(); tree[1].init();
for(int i = 0; i < l.size(); i++)
tree[0].change(l[i],1);
for(int i = 0; i < r.size(); i++)
tree[1].change(r[i],1); int L = o[0];
for(int i = 1; i < o.size(); i++){
int R = o[i];
if(L+1<=R-1){
int Z = tree[0].sum(R-1)-tree[0].sum(L);
int Y = tree[1].sum(R-1)-tree[1].sum(L);
ans += (Z!=Y);
}
L = R;
}
}
vector<int>a,tmp1, red, tmp2, tmpend;
void Red(){
red.clear();
int HHH,EEE; scanf("%d",&HHH);
while(HHH--){scanf("%d",&EEE);red.push_back(EEE);}
sort(red.begin(),red.end());
}
int n;
int main(){
int i,j,num;
maxn = 100010;
while(~scanf("%d",&n)){
ans = 0;
l.clear(); r.clear(); tmp1.clear(); a.clear();
tmp2.clear(); tmpend.clear();
Red();
l = tmp1 = red;
Red();
tmp2 = o = red;
for(i = 3; i <= n; i++){
Red();
r = red;
if(i==n)tmpend = red;
work();
l = o;
o = r;
}
r = tmp1;
work(); l = tmpend;
o = tmp1;
r = tmp2;
work();
cout<<ans<<endl;
}
return 0;
}
/*
3
2 1 3
3 1 3 2
3 1 3 2 ans:
0
2 */
/*
ll n,m,k;
ll a[N];
ll gcd(ll x,ll y){
if(x>y)swap(x,y);
while(x){
y%=x;
swap(x,y);
}
return y;
}
int main(){
ll i, j, u, v, que;
while(cin>>n>>m>>k){
for(i = 1; i <= n; i++)cin>>a[i];
ll _gcd = a[1];
for(i = 2; i <= n; i++)_gcd = gcd(_gcd,a[i]);
for(i = 1; i <= n; i++)a[i]/=_gcd; }
return 0;
}
/* */
Codeforces 216D Spider's Web 树状数组+模拟的更多相关文章
- Codeforces 946G  Almost Increasing Array (树状数组优化DP)
		题目链接 Educational Codeforces Round 39 Problem G 题意 给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ... 
- Educational Codeforces Round 10   D. Nested Segments (树状数组)
		题目链接:http://codeforces.com/problemset/problem/652/D 给你n个不同的区间,L或者R不会出现相同的数字,问你每一个区间包含多少个区间. 我是先把每个区间 ... 
- Codeforces Gym 100114 H. Milestones 离线树状数组
		H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ... 
- Codeforces - 828E DNA Evolution —— 很多棵树状数组
		题目链接:http://codeforces.com/contest/828/problem/E E. DNA Evolution time limit per test 2 seconds memo ... 
- Codeforces Gym 100269F Flight Boarding Optimization 树状数组维护dp
		Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is ... 
- Codeforces 570D TREE REQUESTS dfs序+树状数组  异或
		http://codeforces.com/problemset/problem/570/D Tree Requests time limit per test 2 seconds memory li ... 
- Codeforces 786C Till I Collapse(树状数组+扫描线+倍增)
		[题目链接] http://codeforces.com/contest/786/problem/C [题目大意] 给出一个数列,问对于不同的k,将区间划分为几个, 每个区间出现不同元素个数不超过k时 ... 
- CodeForces - 369E Valera and Queries(树状数组)
		CodeForces - 369E Valera and Queries 题目大意:给出n个线段(线段的左端点和右端点坐标)和m个查询,每个查询有cnt个点,要求给出有多少条线段包含至少其中一个点. ... 
- codeforces 1042D - Petya and Array【树状数组+离散化】
		题目:戳这里 题意:有n个数,问有多少个区间满足[L,R]内的和小于t. 解题思路: [L,R]内的和小于t等价于sum[R]-sum[L-1]<t,将sum[L-1]左移,可以看出R与L的关系 ... 
随机推荐
- Zend Studio 离线汉化包下载方法
			进入eclipse官网 语言包位置 http://www.eclipse.org/babel/downloads.php 
- c语言 c++ 实现查看本地ip,外网ip, 本地主机名,查看http网址对应的ip
			/******************************************************************************* 作者 :邓中强 Email :1246 ... 
- 实现UAC对话框效果
			设置桌面全屏: int cxScreen,cyScreen; cxScreen=GetSystemMetrics(SM_CXSCREEN); cyScreen=GetSystemMetrics(SM_ ... 
- Oracle排名函数(Rank)实例详解
			这篇文章主要介绍了Oracle排名函数(Rank)实例详解,需要的朋友可以参考下 --已知:两种排名方式(分区和不分区):使用和不使用partition --两种计算方式(连续,不连续),对应 ... 
- JS、CSS、Image预加载
			Image预加载 <div class="hidden"> <script type="text/javascript"> var im ... 
- 08私有化、MRO顺序
			一. 私有化 1)xx: 公有变量 2)_x: 单前置下划线,私有化属性或方法,from somemodule import *禁止导入,类对象和子类可以访问 3)__xx:双前置下划线,避免与子类中 ... 
- nginx虚拟主机配置实践
			1.配置基于域名的虚拟主机 [root@web01 html]# egrep -v "#|^$" /application/nginx/conf/nginx.conf.defaul ... 
- HDU 6446 Tree and Permutation(赛后补题)
			>>传送门<< 分析:这个题是结束之后和老师他们讨论出来的,很神奇:刚写的时候一直没有注意到这个是一个树这个条件:和老师讨论出来的思路是,任意两个结点出现的次数是(n-1)!, ... 
- 【HDU 2196】 Computer(树的直径)
			[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ... 
- mysql-5.7.17-winx64免安装配置
			一,下载mysql-5.7.17-winx64.zip 地址:https://dev.mysql.com/downloads/file/?id=467269 二,解压到自己的某个磁盘:data文件夹和 ... 
