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的关系 ...
随机推荐
- date - 打印或设置系统日期和时间
总览 date [选项]... [+格式] date [选项] [MMDDhhmm[[CC]YY][.ss]] 描述 根据指定格式显示当前时间或设置系统时间. -d, --date=STRING 显示 ...
- apropos - 在 whatis 数据库中查找字符串
总览 (SYNOPSIS) apropos keyword ... 描述 (DESCRIPTION) apropos 命令在一些特定的包含系统命令的简短描述的数据库文件里查找关键字, 然后把结果送到标 ...
- vue工程化之公有CSS、JS文件
1.关于公共的css 在src下面新建public.css,然后在main.js中引入进来 import '@/public.css',这样所有页面中都会使用这个样式了,如果只是部分页面需要,那还是不 ...
- Codeforces Beta Round #1 补题题解
A Theatre Square(数学) 算出每行能装多少乘以每列能装多少就行 公式 ans=ceil(n/a)+ceil(m/a) 代码 #include <bits/stdc++.h> ...
- php 日常问题
1.isset.empty.is_null的区别 isset 判断变量是否定义或者是否为空 变量存在返回ture,否则返回false 变量定义不赋值返回false unset一个变量,返回false ...
- leetcode-169求众数
求众数 思路: 记录每个元素出现的次数,然后查找到众数 代码: class Solution: def majorityElement(self, nums: List[int]) -> int ...
- Python之模块和包的创建与使用
一.模块的概念 在计算机的开发过程中,随着程序代码越写越多,在一个文件里代码就越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,放在不同的文件里面,这样,每个文件包含的代码就相对 ...
- jar项目 BeanDefinitionParsingException: Configuration problem:Unable to locate Spring NamespaceHandler for XML schema namespace
最近由于项目需要,需要jar项目来处理. 我在项目中整合了Spring,在编辑器中启动没有问题,但是使用ant打包为一个完整jar文件,部署后启动报错如下 org.springframework.be ...
- 【02】emmet系列之HTML语法
[01]emmet系列之基础介绍 [02]emmet系列之HTML语法 [03]emmet系列之CSS语法 [04]emmet系列之编辑器 [05]emmet系列之各种缩写 初始化 :快速编写HTML ...
- 将Java程序打包成可执行EXE文件的步骤
需要的工具myeclipse .jar2exe(附上下载地址,直接解压就可以用链接: https://pan.baidu.com/s/1qYPRgXu 密码: wbva) 1.将Java项目导出成.j ...