简单分析一下,对于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的更多相关文章

  1. Educational Codeforces Round 41 (Rated for Div. 2)

    这场没打又亏疯了!!! A - Tetris : 类似俄罗斯方块,模拟一下就好啦. #include<bits/stdc++.h> #define fi first #define se ...

  2. Educational Codeforces Round 41 (Rated for Div. 2) ABCDEF

    最近打的比较少...就只有这么点题解了. A. Tetris time limit per test 1 second memory limit per test 256 megabytes inpu ...

  3. EC Round 33 F. Subtree Minimum Query 主席树/线段树合并

    这题非常好!!! 主席树版本 很简单的题目,给一个按照指定节点的树,树上有点权,你需要回答给定节点的子树中,和其距离不超过k的节点中,权值最小的. 肯定首先一想,按照dfs序列建树,然后按照深度为下标 ...

  4. Educational Codeforces Round 41 (Rated for Div. 2)F. k-substrings

    题意比较麻烦略 题解:枚举前缀的中点,二分最远能扩展的地方,lcp来check,然后线段树维护每个点最远被覆盖的地方,然后查询线段树即可 //#pragma GCC optimize(2) //#pr ...

  5. Educational Codeforces Round 41 (Rated for Div. 2)(A~D)

    由于之前打过了这场比赛的E题,而后面两道题太难,所以就手速半个多小时A了前4题. 就当练手速吧,不过今天除了C题数组开小了以外都是1A A Tetris 题意的抽象解释可以在Luogu里看一下(话说现 ...

  6. D. Pair Of Lines( Educational Codeforces Round 41 (Rated for Div. 2))

    #include <vector> #include <iostream> #include <algorithm> using namespace std; ty ...

  7. C. Chessboard( Educational Codeforces Round 41 (Rated for Div. 2))

    //暴力 #include <iostream> #include <algorithm> #include <string> using namespace st ...

  8. B. Lecture Sleep( Educational Codeforces Round 41 (Rated for Div. 2))

    前缀后缀和搞一搞,然后枚举一下区间,找出最大值 #include <iostream> #include <algorithm> using namespace std; ; ...

  9. 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,2最后会在一条直线上,则把这条直线上的点都删掉. 看看剩余的点是否在同 ...

随机推荐

  1. hdoj 1325 Is It A Tree? 【并查集】

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/shengweisong/article/details/34099151 做了一上午,最终ac了 w ...

  2. python基础--线程、进程

    并发编程: 操作系统:(基于单核研究) 多道技术: 1.空间上的复用 多个程序共用一个计算机 2.时间上的复用 切换+保存状态 例如:洗衣 烧水 做饭 切换: 1.程序遇到IO操作系统会立刻剥夺着CP ...

  3. Django项目:CRM(客户关系管理系统)--16--08PerfectCRM实现King_admin显示注册表的字段表头

    # king_urls.py # ————————02PerfectCRM创建ADMIN页面———————— from django.conf.urls import url from king_ad ...

  4. Django 自定义auth_user

    1 导入AbstractUser from django.contrib.auth.models import AbstractUser 1 2 创建类UserProfile并继承AbstractUs ...

  5. iOS 自定义 URL Scheme 完全指南

    http://www.cocoachina.com/industry/20140522/8514.html “”   阅读器 自定义URL Scheme 本文转自Migrant的博客,原文:<T ...

  6. LeetCode141 Linked List Cycle. LeetCode142 Linked List Cycle II

    链表相关题 141. Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up:Can y ...

  7. LeafLet 简单使用

    Leaflet 使用 最近在Angular项目中,用到了地图,由于种种原因放弃了百度地图api使用,最后选择了leaflet,简单介绍一下. 介绍: Leaflet 是一个为移动设备设计的交互式地图的 ...

  8. 2019.11.12htmlhomework1

    ex: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...

  9. utf8mb4 使用注意

    数据库的表的定义如果是utf8mb4的富文本时,关联的字段必须指定为非utf8,否则 跟其他的表关联的时候,会非常慢,以至于索引都不能使用. 也就是必须的字段才可以使用这个 utf8mb4 ,否则检索 ...

  10. 微信公众号系统在Linux下的部署操作

    ps -ef | grep tomcat 查看tomcat进程