主席树——Codeforces811B Vladik and Complicated Book
来源:互联网 发布:传奇数据库编辑工具 编辑:程序博客网 时间:2024/06/05 17:02
题面:cf811b
简要题意:给定一个1~n的排列, 询问区间l,r经过排序后数列第k个数是否还处在原位(l<=k<=r)
和求区间k小很像,转化一下题目就是询问区间l,r中数列第k个数是否为区间第(k-l+1)小
所以权值主席树直接上不虚。。。
据说暴力能过。。。QAQ(毕竟是B题,数据范围这么小+毛子机子跑得快肯定能过)
#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<cstdlib>#include<iostream>#include<queue>#include<string>#include<ctime>#include<climits>using namespace std;inline int read(){ int k=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();} return k*f;}int n,m,cnt=0,a[100001];int root[100001],t[2500001],lt[2500001],rt[2500001];inline void build(int l,int r,int& nod){ nod=++cnt;t[nod]=0; if(l==r)return; int mid=(l+r)>>1; build(l,mid,lt[nod]); build(mid+1,r,rt[nod]);}inline void xg(int l,int r,int& nod,int la,int p){ nod=++cnt;t[nod]=t[la]+1;lt[nod]=lt[la];rt[nod]=rt[la]; if(l==r)return; int mid=(l+r)>>1; if(p<=mid)xg(l,mid,lt[nod],lt[la],p); else xg(mid+1,r,rt[nod],rt[la],p);}inline int s(int l,int r,int x,int y,int k){ if(l==r)return l; int mid=(l+r)>>1,cmp=t[lt[y]]-t[lt[x]]; if(k<=cmp)return s(l,mid,lt[x],lt[y],k); else return s(mid+1,r,rt[x],rt[y],k-cmp);}int main(){ n=read();m=read();int sum=n; for(int i=1;i<=n;i++)a[i]=read(); build(1,sum,root[0]); for(int i=1;i<=n;i++)xg(1,sum,root[i],root[i-1],a[i]); for(int i=1;i<=m;i++){ int x=read(),y=read(),z=read(); int k=s(1,sum,root[x-1],root[y],z-x+1); if(k==a[z])puts("Yes"); else puts("No"); } return 0;}
阅读全文
1 0
- 主席树——Codeforces811B Vladik and Complicated Book
- Codeforces 811B Vladik and Complicated Book[主席树]
- Vladik and Complicated Book
- B. Vladik and Complicated Book
- B. Vladik and Complicated Book
- codeforce Vladik and Complicated Book
- codeforces——811B——Vladik and Complicated Book
- CodeForces 811B——Vladik and Complicated Book ——思维,模拟
- CodeForce 811 B Vladik and Complicated Book
- Codeforces 811B Vladik and Complicated Book
- codeforces#416 div2- Vladik and Complicated Book
- Codeforces 811 B Vladik and Complicated Book
- Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
- #416 Div.2 B. Vladik and Complicated Book
- Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
- Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
- codeforce811b Vladik and Complicated Book(都是不好好想题惹的祸)
- codeforces——811A——Vladik and Courtesy
- hive row_number()
- 运行jar包提示找不到.properties文件的问题
- 项目——预处理3
- js、java的base64相互加密、解密
- mybatis学习:九
- 主席树——Codeforces811B Vladik and Complicated Book
- ABAP 输出方式
- Java 异常处理
- .NET Expression 从零开始一(基本认知):hello world!
- mysql 配置支持SSL连接
- 172. Factorial Trailing Zeroes
- C# 编码转换
- 第十周作业: Add Digits
- 关于XML文档的xmlns、xmlns:xsi和xsi:schemaLocation