Codeforces 216D Spider#39;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 2ans:
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;
}
/**/
转载于:https://www.cnblogs.com/yutingliuyl/p/6845743.html
Codeforces 216D Spider#39;s Web 树状数组+模拟相关推荐
- codeforces 261D Maxim and Increasing Subsequence(树状数组优化最长上升子列)
题目链接:http://codeforces.com/problemset/problem/261/D 题意:最长上升子列. 思路:树状数组优化求最长上升子列. #include <iostre ...
- CodeForces - 538F--A Heap of Heaps(树状数组+离线)
题目链接https://codeforces.com/problemset/problem/538/F Time limit 3000 ms Memory limit 524288 kB Andrew ...
- Codeforces Gym 100114 H. Milestones 离线树状数组
H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ...
- 【CodeForces - 460C】Present(二分+树状数组)
题干: 给定N朵花的原先的高度,从左到右排列,最多浇水m天,每天只能浇一次,每次使得连续的w朵花的高度增长1,问最后最矮的花的高度最高是多少. Examples Input 6 2 3 2 2 2 2 ...
- JZOJ 3.10 1542——跑步(树状数组+模拟+排序/归并排序)
题目描述 FJ觉得赛马很无聊,于是决定调查将赛牛作为一种运动的可能性.他安排了N(1 <= N <= 100,000)头奶牛来进行一个L圈的赛牛比赛,比赛在一个环形的长度为C的跑道上进行. ...
- CodeForces 828E DNA Evolution(树状数组)题解
题意:给你一个串k,进行两个操作: "1 a b":把a位置的字母换成b "2 l r s":求l到r有多少个字母和s匹配,匹配的条件是这样:从l开始无限循环s ...
- Codeforces Round #365 (Div. 2) D. Mishka and Interesting sum (离线树状数组+前缀xor)
题目链接:http://codeforces.com/contest/703/problem/D 给你n个数,m次查询,每次查询问你l到r之间出现偶数次的数字xor和是多少. 我们可以先预处理前缀和X ...
- CodeForces 314C 树状数组 + dp
//CodeForces 314C //分析:相当于求给定序列的不降子序列的个数,从一个空序列开始将得到的不降子序列不断的延长是典型的做法,则dp[i]表示以第 i 个元素结尾的序列 //思路:O(n ...
- CodeForces 390E Inna and Large Sweet Matrix(树状数组改段求段)
CodeForces 390E Inna and Large Sweet Matrix(树状数组改段求段) 树状数组仅仅能实现线段树区间改动和区间查询的功能,能够取代不须要lazy tag的线段树.且 ...
最新文章
- oracle 日期检查,在检查约束中使用日期,Oracle
- 如何在Eclipse中使用tomcat9 运行servlet开发简单的动态网页?
- OpenYurt 深度解读:如何构建 Kubernetes 原生云边高效协同网络?
- 如何通过递归找父节点或子节点详解
- const对象,NULL和nullptr,C++中创建对象数组
- linux oracle bad elf,oracle11g安装到red hat6.2 64位系统报错:/lib/ld-linux.so.2: bad ELF interpreter...
- 素描的几大基础知识点_2020年让您感到惊奇的5大素描资源
- 大数据量表的优化查询
- H3C路由器映射端口到外网
- lstm中look_back的大小选择_[Pytorch和Tensorflow对比(二)]:LSTM
- Atitit.嵌入式web 服务器 java android最佳实践
- 六款练手的javaweb项目源码!
- DTC Sprint总结——管理经验篇
- RTSP、RTMP、HTTP流媒体播放器比较
- [BZOJ3993] [SDOI2015]星际战争(最大流+二分)
- Android内核层驱动程序UAF漏洞提权实例
- 如果腾讯突然宣布必须充值一块钱才能继续使用微信,会发生什么
- 从网易云音乐网页版无登陆下载MP3的办法
- Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid
- python租房_如何用Python爬租房网站信息
热门文章
- LeetCode--174.地下城游戏(动态规划)
- 电机的入门之路系列2--电机驱动芯片2003的用法
- redis java api 单例_Java API 操作Redis
- 4027-计数排序(C++,附解析)
- c语言实现路由功能,前端路由的两种实现方式,内附详细代码
- 高新园区到大连计算机学校,教育局 | 高新园区2018指标分配表及大连各区指标到校表(附:现行大连指标名额分配方案)...
- 中标麒麟共享win7打印机_Win7系统添加网络共享打印机
- luogu P1578 奶牛浴场
- 【小记】输入框前后左右去空格的正则方法
- redis10--主从模式