题目链接: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&#39;s Web 树状数组+模拟的更多相关文章

  1. Codeforces 946G Almost Increasing Array (树状数组优化DP)

    题目链接   Educational Codeforces Round 39 Problem G 题意  给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ...

  2. Educational Codeforces Round 10 D. Nested Segments (树状数组)

    题目链接:http://codeforces.com/problemset/problem/652/D 给你n个不同的区间,L或者R不会出现相同的数字,问你每一个区间包含多少个区间. 我是先把每个区间 ...

  3. Codeforces Gym 100114 H. Milestones 离线树状数组

    H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ...

  4. Codeforces - 828E DNA Evolution —— 很多棵树状数组

    题目链接:http://codeforces.com/contest/828/problem/E E. DNA Evolution time limit per test 2 seconds memo ...

  5. Codeforces Gym 100269F Flight Boarding Optimization 树状数组维护dp

    Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is ...

  6. Codeforces 570D TREE REQUESTS dfs序+树状数组 异或

    http://codeforces.com/problemset/problem/570/D Tree Requests time limit per test 2 seconds memory li ...

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

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

  8. CodeForces - 369E Valera and Queries(树状数组)

    CodeForces - 369E Valera and Queries 题目大意:给出n个线段(线段的左端点和右端点坐标)和m个查询,每个查询有cnt个点,要求给出有多少条线段包含至少其中一个点. ...

  9. codeforces 1042D - Petya and Array【树状数组+离散化】

    题目:戳这里 题意:有n个数,问有多少个区间满足[L,R]内的和小于t. 解题思路: [L,R]内的和小于t等价于sum[R]-sum[L-1]<t,将sum[L-1]左移,可以看出R与L的关系 ...

随机推荐

  1. 用npm来部署快速一个httpweb服务器

    https://blog.csdn.net/u012182627/article/details/55060594 http-server的安装######注意事项 安装http-server的时候 ...

  2. LINUX:解压问题tar: Child returned status

    解压某个文件时 #tar -zxvf xxxxx.tar.gz 出现下面的错误提示: gzip: stdin: not in gzip formattar: Child returned status ...

  3. 【计算机网络】3.2 无连接运输:UDP

    第三章第二节 无连接运输:UDP UDP(用户数据报协议,User Datagram Protocol),它只是做了运输层协议能够做的最少工作,除了多路复用和多路分解及一些差错检测外,它几乎没有做任何 ...

  4. 基于jQuery的用户界面插件集合---EasyUI

    easyui是一种基于jQuery的用户界面插件集合.为创建现代化,互动,JavaScript应用程序,提供必要的功能.使用easyui你不需要写很多代码,你只需要通过编写一些简单HTML标记,就可以 ...

  5. PHP 下基于 php-amqp 扩展的 RabbitMQ 简单用例 (四) -- Push API 和 Pull API

    RabbitMQ 中针对消息的分发提供了 Push API (订阅模式) 和 Pull API (主动获取) 两种模式. 在 PHP 中, 这两种模式分别通过 AMQPQueue 类中的 consum ...

  6. joda-time时间操作组件

    今天看到了学习到了一个不错的操作时间的jar包,很方便的,以后操作时间运算就可以直接使用jar包中的方法了,再也不用自己写操作时间的方法了.懒的不行不行的 <!-- 时间操作组件 --> ...

  7. find_in_set()和in()比较

    转载于:https://www.cnblogs.com/zqifa/p/mysql-4.html 作者:zqifa 因为自己太懒了,就从大佬那转载来,作为一次笔记! mysql 中find_in_se ...

  8. MRC转ARC

    转载请注明出处:http://blog.csdn.net/cywn_d/article/details/18222671 1.删除所有retain,release和autorelease. 2.把原来 ...

  9. libuv httpparser写的简单http server

    libuv文档地址:http://docs.libuv.org/en/v1.x/代码地址:https://github.com/libuv/libuvhttp-parser https://githu ...

  10. [Python3网络爬虫开发实战] 1.5.4-RedisDump的安装

    RedisDump是一个用于Redis数据导入/导出的工具,是基于Ruby实现的,所以要安装RedisDump,需要先安装Ruby. 1. 相关链接 GitHub:https://github.com ...