[hdoj6483][莫队+线段树/ST]
A Sequence Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 712 Accepted Submission(s): 114
There is a sequence with N positive integers A1,A2,...,An and M queries. Each query will give you an interval [L,R] and require an answer with YES/NO indicates that whether the numbers in this interval are continuous in its integer range.
Let us assume that the maximal number in an interval is mx and the minimal number is mi. The numbers in this interval are continuous in its integer range means that each number from mi to mx appears at least once in this interval.
The first line contains two positive integers n,m which has been explained above.The second line contains positive integers A1,A2,...,An.
Then there will be m lines followed. Each line contains to positive numbers Li,Ri indicating that the ith query’s interval is [Li,Ri].
Each of following m lines contains a single string “YES”/ “NO” which is the answer you have got.
3 3
3 1 2
2 3
1 3
1 2
5 3
1 2 2 4 5
1 5
1 3
3 3
YES
NO
NO
YES
YES
T=5
1<=n<=100000
1<=Ai<=10^9
1<=m<=100000
The input file is very large, so you are recommend to use scanf() and printf() for IO.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout<<"["<<#x<<"]"<<" "<<x<<endl;
const int maxn=1e5+;
int a[maxn],b[maxn],c[maxn],in[maxn];
struct node{
int maxx;
int minn;
int l;
int r;
}Node[maxn<<];
struct Qa{
int l;
int r;
int id;
int bloc;
}q[maxn];
int ANS[maxn];
void pushup(int rt){
Node[rt].maxx=max(Node[rt<<].maxx,Node[(rt<<)|].maxx);
Node[rt].minn=min(Node[rt<<].minn,Node[(rt<<)|].minn);
}
void build(int L,int R,int rt){
Node[rt].l=L;
Node[rt].r=R;
if(L==R){
Node[rt].maxx=Node[rt].minn=a[L];
return;
}
int mid=(L+R)/;
build(L,mid,rt<<);
build(mid+,R,(rt<<)|);
pushup(rt);
}
bool cmp(struct Qa aa,struct Qa bb){
if(aa.bloc==bb.bloc)return aa.r<bb.r;
return aa.bloc<bb.bloc;
}
void query(int L,int R,int rt,int L1,int R1,int &m1,int &m2){
//debug(L);
if(L1<=L&&R1>=R){
m1=max(m1,Node[rt].maxx);
m2=min(m2,Node[rt].minn);
return;
}
int mid=(L+R)/;
if(mid>=L1)query(L,mid,rt<<,L1,R1,m1,m2);
if(mid<R1)query(mid+,R,(rt<<)|,L1,R1,m1,m2);
}
int main()
{
//cout<<100000ll*sqrt(100000)+400000ll*log(100000)<<endl;
int t;
scanf("%d",&t);
while(t--){
int n,m;
scanf("%d%d",&n,&m);
//unordered_map<int,int>mp;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
b[i]=a[i];
in[i]=;
}
build(,n,);
int len=sqrt(n);
for(int i=;i<=m;i++){
scanf("%d%d",&q[i].l,&q[i].r);
q[i].id=i;
q[i].bloc=q[i].l/len;
ANS[i]=;
}
sort(q+,q++m,cmp);
sort(b+,b++n);
int L=;
int R=;
int tot=;
int kk=unique(b+,b++n)-b-;
for(int i=;i<=n;i++){
int pos=lower_bound(b+,b++kk,a[i])-b;
c[i]=pos;
}
in[c[]]++;
for(int i=;i<=m;i++){
int m1=a[q[i].l];
int m2=a[q[i].r];
query(,n,,q[i].l,q[i].r,m1,m2);
while(L<q[i].l){
in[c[L]]--;
if(in[c[L]]==){
tot--;
}
L++;
}
while(L>q[i].l){
L--;
in[c[L]]++;
if(in[c[L]]==){
tot++;
}
}
while(R>q[i].r){
in[c[R]]--;
if(in[c[R]]==){
tot--;
}
R--;
}
while(R<q[i].r){
R++;
in[c[R]]++;
if(in[c[R]]==){
tot++;
}
}
if(tot==m1-m2+){
ANS[q[i].id]=;
}
}
for(int i=;i<=m;i++){
if(ANS[i]){
printf("YES\n");
}
else{
printf("NO\n");
}
}
}
return ;
}
[hdoj6483][莫队+线段树/ST]的更多相关文章
- Codeforces 666E E - Forensic Examination SA + 莫队 + 线段树
E - Forensic Examination 我也不知道为什么这个复杂度能过, 而且跑得还挺快, 数据比较水? 在sa上二分出上下界, 然后莫队 + 线段树维护区间众数. #include< ...
- 洛谷P3246 序列 [HNOI2016] 莫队/线段树+扫描线
正解:莫队/线段树+扫描线 解题报告: 传送门! 似乎是有两种方法的,,,所以分别港下好了QAQ 第一种,莫队 看到这种询问很多区间之类的就会自然而然地想到莫队趴?然后仔细思考一下,发现复杂度似乎是欧 ...
- 【CF633H】Fibonacci-ish II 莫队+线段树
[CF633H]Fibonacci-ish II 题意:给你一个长度为n的序列$a_i$.m个询问,每个询问形如l,r:将[l,r]中的所有$a_i$排序并去重,设得到的新数列为$b_i$,求$b_1 ...
- Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵
H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...
- [bzoj4358]permu:莫队+线段树/回滚莫队
这道题是几天前水过去的,现在快没印象了,水一发. 首先我们看到它让求解的是最长的值域 连续段长度,很好. 然后就想到了山海经,但但是我还没有做. 然后又想到了很久以前的一次考试的T3旅馆hotel(我 ...
- BZOJ 4129 树上带修莫队+线段树
思路: 可以先做做BZOJ3585 是序列上的mex 考虑莫队的转移 如果当前数字出现过 线段树上把它置成1 对于询问 二分ans 线段树上查 0到ans的和 是不是ans+1 本题就是把它搞到了序列 ...
- bzoj 3289: Mato的文件管理 莫队+线段树
题目链接 给一些询问,每个询问给出区间[L, R] , 求这段区间的逆序数. 先分块排序, 然后对于每次更改, 如果是更改L, 那么应该查询区间内比他小的数的个数, 如果更改R, 查区间内比他大的数的 ...
- BZOJ 4358 坑 莫队+线段树 死T
这是一个坑 竟然卡nsqrt(n)logn T死 等更 //By SiriusRen #include <cmath> #include <cstdio> #include & ...
- CF633H Fibonacci-ish II(莫队+线段树)
温馨提示:本题十分卡常数,我手动开O2才过的.而数据范围不伦不类的n<=30000,常数小的O(n2)居然比O(n√nlogn)跑得快…… 考虑插进去一个元素对答案产生的影响.原本数列为Σa[i ...
随机推荐
- use selenium+chromedriver to taobao automatically
原理 利用chromedriver来驱动chrome进行各种模拟各种行为操作, 然后利用selenium提供的接口来操作chromedriver. 安装ChromeDriver 当然这个的默认前提是你 ...
- mybatis+mysql insert添加数据后返回数据主键id---(转)
1.根据useGeneratedKeys获取返回值,部分数据库不支持 修改mybatis xml 1 2 3 <insert id="insertUser" useGener ...
- 028 Android 旋转动画+病毒查杀效果+自定义样式的ProgressBar
1.目标效果 旋转动画+病毒查杀效果 2.xml布局文件 (1)activity_kill_virus.xml <?xml version="1.0" encoding=&q ...
- CF731E Funny Game
题目描述 一个长度为 N 的序列 ai ,双方轮流操作 每次的操作是选择一个长度大于 1 的前缀,计算它的和 s ,然后 用 s 替换它的前缀,同时当前玩家获得 s 的分数. 当只剩下一个元素,游戏结 ...
- 机器学习支持向量机SVM笔记
SVM简述: SVM是一个线性二类分类器,当然通过选取特定的核函数也可也建立一个非线性支持向量机.SVM也可以做一些回归任务,但是它预测的时效性不是太长,他通过训练只能预测比较近的数据变化,至于再往后 ...
- 为什么无人机测量主流现在都不用RTK技术,而是PPK技术【转】
为什么无人机测量主流现在都不用RTK技术,而是PPK技术_宇辰网_让世界读懂无人机_全球专业无人机资讯|电商|大数据服务平台 大疆Phantom 4 RTK正式发布_宇辰网_让世界读懂无人机_全球专业 ...
- prometheus环境搭建
1. 下载文件 wget https://dl.grafana.com/oss/release/grafana-6.2.4.linux-amd64.tar.gz tar -zxvf grafana-. ...
- 怎么将visual studio项目打包生成dll文件
1.打开电脑再打开visual studio软件,在软件里面新建一个项目,文件---->新建---->项目,打开新建项目窗口. 2.选择C#类工程,并为项目命名. 3.将类库文件class ...
- .net通过网络路径下载文件至本地
获取网络文件,通过流保存文件,由于上一版存在数据丢失情况,稍微调整了以下. //网络路径文件 string pathUrl = "http://localhost:805/春风吹.mp3&q ...
- OpenSSL 1.1.1 国密算法支持
OpenSSL 1.1.1 国密算法支持 https://www.openssl.org/ https://github.com/openssl/openssl OpenSSL 1.1.1 新特性: ...