[Luogu 3901]Difference
Description

Input

Output

Sample Input
4 2
1 2 3 2
1 3
2 4
Sample Output
Yes
No
HINT

题解
莫队。加个标记数组维护该数在区间中出现了几次,再加个变量统计有几个数是重复的。
#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define RE register
#define IL inline
using namespace std;
const int N=1e5; int n,q,lim;
int cnt[N+],a[N+];
struct tt
{
int l,r,id;
}query[N+];
bool keep[N+]; IL bool comp(const tt &a,const tt &b) {return a.l/lim==b.l/lim ? a.r<b.r : a.l<b.l;} int main()
{
scanf("%d%d",&n,&q);
lim=sqrt(n);
for (RE int i=;i<=n;i++) scanf("%d",&a[i]);
for (RE int i=;i<=q;i++) scanf("%d%d",&query[i].l,&query[i].r),query[i].id=i;
sort(query+,query++q,comp);
int curl=,curr=,ans=,l,r;
for (RE int i=;i<=q;i++)
{
l=query[i].l,r=query[i].r;
while (curl<l) cnt[a[curl]]--,ans-=(cnt[a[curl++]]==);
while (curl>l) cnt[a[--curl]]++,ans+=(cnt[a[curl]]==);
while (curr<r) cnt[a[++curr]]++,ans+=(cnt[a[curr]]==);
while (curr>r) cnt[a[curr]]--,ans-=(cnt[a[curr--]]==);
if (!ans) keep[query[i].id]=;
}
for (RE int i=;i<=q;i++) printf(keep[i] ? "Yes\n":"No\n");
return ;
}
[Luogu 3901]Difference的更多相关文章
- Java 堆内存与栈内存异同(Java Heap Memory vs Stack Memory Difference)
		--reference Java Heap Memory vs Stack Memory Difference 在数据结构中,堆和栈可以说是两种最基础的数据结构,而Java中的栈内存空间和堆内存空间有 ... 
- What's the difference between a stub and mock?
		I believe the biggest distinction is that a stub you have already written with predetermined behavio ... 
- [转载]Difference between <context:annotation-config> vs <context:component-scan>
		在国外看到详细的说明一篇,非常浅显透彻.转给国内的筒子们:-) 原文标题: Spring中的<context:annotation-config>与<context:componen ... 
- What's the difference between <b> and <strong>, <i> and <em> in HTML/XHTML? When should you use each?
		ref:http://stackoverflow.com/questions/271743/whats-the-difference-between-b-and-strong-i-and-em The ... 
- Luogu 魔法学院杯-第二弹(萌新的第一法blog)
		虽然有点久远 还是放一下吧. 传送门:https://www.luogu.org/contest/show?tid=754 第一题 沉迷游戏,伤感情 #include <queue> ... 
- difference between forward and sendredirect
		Difference between SendRedirect and forward is one of classical interview questions asked during jav ... 
- Add Digits, Maximum Depth of BinaryTree, Search for a Range, Single Number,Find the Difference
		最近做的题记录下. 258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the ... 
- luogu p1268 树的重量——构造,真正考验编程能力
		题目链接:http://www.luogu.org/problem/show?pid=1268#sub -------- 这道题费了我不少心思= =其实思路和标称毫无差别,但是由于不习惯ACM风格的题 ... 
- MySQL: @variable vs. variable. Whats the difference?
		MySQL: @variable vs. variable. Whats the difference? up vote351down votefavorite 121 In another qu ... 
随机推荐
- 【Spring源码深度解析学习系列】默认标签解析(三)
			Spring的标签包括默认标签和自定义标签两种 默认标签的解析方法: ###DefaultBeanDefinitionDocumentReader.java### private void parse ... 
- 网络1711c语言第0次作业总结
			作业地址:https://edu.cnblogs.com/campus/jmu/JMUC--NE17111712/homework/861 总结 1.评分标准 以下要求中除了未交和抄袭0分,其他项最多 ... 
- C语言博客作业—结构体
			一.PTA实验作业 题目1:结构体数组按总分排序 1. 本题PTA提交列表 2. 设计思路 void calc //函数calc求出p指针所指的结构体数组中 n 名学生各自的总分 { 定义循环变量i: ... 
- 从0开始的LeetCode生活—461-Hamming Distance(汉明距离)
			题目: The Hamming distance between two integers is the number of positions at which the corresponding ... 
- 团队作业4——第一次项目冲刺(Alpha版本)2017.11.16
			第一次会议:2017-11-16 大家的任务完成的不错^_^,继续努力了. 上图: 忘记照了,额....... 会议主要内容: 1.登录功能的讨论 2. 代码统一 具体分工: 成员 计划任务 遇见难题 ... 
- poj2029 Get Many Persimmon Trees
			http://poj.org/problem?id=2029 单点修改 矩阵查询 二维线段树 #include<cstdio> #include<cstring> #inclu ... 
- OO第一次阶段性总结
			经过三次作业的历练之后终于来到了写博客这一周.回顾开学来的这一个月,令我印象最深刻也是最累的一门课就是OO了.虽然上学期学过一部分Java,但这学期开学就来的OO作业还是让我在第二周就开始熬夜了.不过 ... 
- ll的命令后面的字段详解
			linux学习 命令ll后字段的解释 分类:linux | 标签: 命令ll后字段的解释 2010-10-25 15:47阅读(4513)评论(0) ls -l 列表信息详解 我们平时用ls -l ... 
- Java KeyTool command
			Create a new key: keytool -genkey -alias keyAlias -keyalg RSA -validity 1000 -keystore d:\keyPath\k ... 
- ### Cause: org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [arg1, arg0, param1, param2]
			org.apache.ibatis.exceptions.PersistenceException: ### Error updating database. Cause: org.apache.ib ... 
