EC Round 41 (Rated for Div. 2)主席树 E. Tufurama
简单分析一下,对于x<y,求a[x]>=y 同时a[y]>=x
再简化一下,求1-a[y]区间内大于>=y的个数。。。主席树牛逼
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#define LL long long
using namespace std;
const int maxx = 2e5+;
struct node{
int l,r;
int cnt;
}tree[maxx*];
int a[maxx];
int b[maxx];
int root[maxx];
int cnt;
vector<int>v;
int getval(int x){
return lower_bound(v.begin(),v.end(),x)-v.begin()+;
}
void inserts(int l,int r,int pre,int &now,int pos){
now=++cnt;
tree[now]=tree[pre];
tree[now].cnt++;
if(l==r){
return ;
}
int mid=(l+r)>>;
if (pos<=mid){
inserts(l,mid,tree[pre].l,tree[now].l,pos);
}else {
inserts(mid+,r,tree[pre].r,tree[now].r,pos);
}
}
int query(int L,int R,int l,int r,int w){
if(l==r){
return tree[R].cnt-tree[L].cnt;
}
int mid=(l+r)>>;
if(w<=mid){
return tree[tree[R].r].cnt-tree[tree[L].r].cnt+query(tree[L].l,tree[R].l,l,mid,w);
}else {
return query(tree[L].r,tree[R].r,mid+,r,w);
}
}
int main(){
int n;
while(~scanf("%d",&n)){
for (int i=;i<=n;i++){
scanf("%d",&a[i]);
v.push_back(a[i]);
}
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
for(int i=;i<=n;i++){
b[i]=getval(a[i]);
}
for (int i=;i<=n;i++){
inserts(,n,root[i-],root[i],b[i]);
}
LL ans=;
for (int i=;i<=n;i++){
ans+=query(root[],root[min(a[i],i-)],,n,getval(i));
}
printf("%lld\n",ans);
}
return ;
}
EC Round 41 (Rated for Div. 2)主席树 E. Tufurama的更多相关文章
- Educational Codeforces Round 41 (Rated for Div. 2)
这场没打又亏疯了!!! A - Tetris : 类似俄罗斯方块,模拟一下就好啦. #include<bits/stdc++.h> #define fi first #define se ...
- Educational Codeforces Round 41 (Rated for Div. 2) ABCDEF
最近打的比较少...就只有这么点题解了. A. Tetris time limit per test 1 second memory limit per test 256 megabytes inpu ...
- EC Round 33 F. Subtree Minimum Query 主席树/线段树合并
这题非常好!!! 主席树版本 很简单的题目,给一个按照指定节点的树,树上有点权,你需要回答给定节点的子树中,和其距离不超过k的节点中,权值最小的. 肯定首先一想,按照dfs序列建树,然后按照深度为下标 ...
- Educational Codeforces Round 41 (Rated for Div. 2)F. k-substrings
题意比较麻烦略 题解:枚举前缀的中点,二分最远能扩展的地方,lcp来check,然后线段树维护每个点最远被覆盖的地方,然后查询线段树即可 //#pragma GCC optimize(2) //#pr ...
- Educational Codeforces Round 41 (Rated for Div. 2)(A~D)
由于之前打过了这场比赛的E题,而后面两道题太难,所以就手速半个多小时A了前4题. 就当练手速吧,不过今天除了C题数组开小了以外都是1A A Tetris 题意的抽象解释可以在Luogu里看一下(话说现 ...
- D. Pair Of Lines( Educational Codeforces Round 41 (Rated for Div. 2))
#include <vector> #include <iostream> #include <algorithm> using namespace std; ty ...
- C. Chessboard( Educational Codeforces Round 41 (Rated for Div. 2))
//暴力 #include <iostream> #include <algorithm> #include <string> using namespace st ...
- B. Lecture Sleep( Educational Codeforces Round 41 (Rated for Div. 2))
前缀后缀和搞一搞,然后枚举一下区间,找出最大值 #include <iostream> #include <algorithm> using namespace std; ; ...
- 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,2最后会在一条直线上,则把这条直线上的点都删掉. 看看剩余的点是否在同 ...
随机推荐
- Could not parse mapping document from resource com/hs/model/StudentModel.hbm.xml
网上出现这个问题的 lei.hbm.xml配置写错的,文件头应该改为如下,并不是这个问题 <?xml version="1.0"?> <!DOCTYPE hibe ...
- CSS min-height 属性
实例 设置段落的最小高度: p { min-height:100px; } 浏览器支持 IE Firefox Chrome Safari Opera 所有主流浏览器都支持 min-height 属性. ...
- @at-root和#{&}结合
Sass有脚本模式#{},他和&不同之处是,&只用作选择器,它只能出现在一个复合的开始选择器,类似于一个类型选择器,如a或者h1.但#{}他表示的是一个插值,它可以用在任何地方.同样的 ...
- python基础--GIL全局解释器锁、Event事件、信号量、死锁、递归锁
ps:python解释器有很多种,最常见的就是C python解释器 GIL全局解释器锁: GIL本质上是一把互斥锁:将并发变成串行,牺牲效率保证了数据的安全 用来阻止同一个进程下的多个线程的同时执行 ...
- day38 10-Spring的Bean的属性的注入
后处理bean,如果是返回bean,那么什么都不做直接把这个类原封不动地给你返回回去. 在它执行一些逻辑方法的时候对它进行逻辑增强,比如说进行时间监控,权限管理,日志的记录等等. 要做肯定是对正常的类 ...
- BZOJ4719[NOIP2016提高组Day1T2] 天天爱跑步
#261. [NOIP2016]天天爱跑步 描述 提交 自定义测试 小C同学认为跑步非常有趣,于是决定制作一款叫做<天天爱跑步>的游戏.<天天爱跑步>是一个养成类游戏,需要玩家 ...
- MySQL Daemon failed to start错误解决办法是什么呢?
首先我尝试用命令:service mysql start 来启动服务,但是提示: MySQL Daemon failed to start 一开始出现这个问题我很方,然后开始查,说什么的都有,然后看到 ...
- Vue--moment时间格式插件安装和使用
使用链接:http://momentjs.cn/ 1.安装monent 2.导入 3.过滤器 4.template模板使用:
- ajax成功请求到后台,但是前端报404错误
记录下今天遇见的一个问题,一个删除的ajax请求,传递一个主键到后台,后台成功接受并执行删除,但是前端报POST404错误. 查找原因是由于Controller忘记写返回状态码 @Responsebo ...
- iOS 自定义Tabbar实现push动画隐藏效果
http://wonderffee.github.io/blog/2013/08/07/hide-custom-tab-bar-with-animation-when-push/ 在之前的一篇文章(链 ...