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的关系 ...
随机推荐
- JavaSE-09 继承
学习要点 继承的优点和实现 子类重写父类方法 继承下构造方法的执行过程 抽象类和抽象方法的使用 final修饰属性.方法和类 继承的优点和实现 宠物管理系统优化设计 宠物管理系统中的类有什么问题? 使 ...
- Python的前世今生
放弃 拾起 放弃 拾起 最终决定好好的编写一次Python的学习笔记 人生苦短,我用Python --------------Life is short, you need Python 再不抓紧,就 ...
- django 标签
django标签 {% if/for/ifequal/ifnotequal condition %} ...{{ name|first|lower}}{# interpretation:lower t ...
- MRC转ARC(2)
春节前抽空花了一天的时间将手头的工程从MRC转成了ARC,然后陆陆续续地修复一部分因为转ARC引起的内存泄漏和崩溃,到目前为止工程也算是比较稳定了,抽空记上一笔.(虽说这种事情这辈子估计都只会做这么一 ...
- vue 清除keep-Alive页面缓存
- 【project】十次方-01
前言 项目介绍 系统分为3大部分:微服务.网站前台.网站管理后台:功能模块分为:问答.招聘.交友中心等 该项目融合了Docker容器化部署.第三方登陆.SpringBoot.SpringCloud.S ...
- Spring接收web请求参数的几种方式
1 查询参数 请求格式:url?参数1=值1&参数2=值2...同时适用于GET和POST方式spring处理查询参数的方法又有几种写法: 方法一:方法参数名即为请求参数名 // 查询参数1 ...
- LeetCode(61) Rotate List
题目 Given a list, rotate the list to the right by k places, where k is non-negative. For example: Giv ...
- LeetCode(47)Permutations II
题目 Given a collection of numbers that might contain duplicates, return all possible unique permutati ...
- STM32——通用定时器基本定时功能
STM32——————通用定时器基本定时功能 1. ...