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的更多相关文章

  1. Java 堆内存与栈内存异同(Java Heap Memory vs Stack Memory Difference)

    --reference Java Heap Memory vs Stack Memory Difference 在数据结构中,堆和栈可以说是两种最基础的数据结构,而Java中的栈内存空间和堆内存空间有 ...

  2. 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 ...

  3. [转载]Difference between <context:annotation-config> vs <context:component-scan>

    在国外看到详细的说明一篇,非常浅显透彻.转给国内的筒子们:-) 原文标题: Spring中的<context:annotation-config>与<context:componen ...

  4. 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 ...

  5. Luogu 魔法学院杯-第二弹(萌新的第一法blog)

    虽然有点久远  还是放一下吧. 传送门:https://www.luogu.org/contest/show?tid=754 第一题  沉迷游戏,伤感情 #include <queue> ...

  6. difference between forward and sendredirect

    Difference between SendRedirect and forward is one of classical interview questions asked during jav ...

  7. 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 ...

  8. luogu p1268 树的重量——构造,真正考验编程能力

    题目链接:http://www.luogu.org/problem/show?pid=1268#sub -------- 这道题费了我不少心思= =其实思路和标称毫无差别,但是由于不习惯ACM风格的题 ...

  9. MySQL: @variable vs. variable. Whats the difference?

    MySQL: @variable vs. variable. Whats the difference?   up vote351down votefavorite 121 In another qu ...

随机推荐

  1. Beta敏捷冲刺每日报告——Day2

    1.情况简述 Beta阶段Scrum Meeting 敏捷开发起止时间 2017.11.2 00:00 -- 2017.11.3 00:00 讨论时间地点 2017.11.2 晚9:30,电话会议会议 ...

  2. 2018上C语言程序设计(高级)作业- 第2次作业

    作业要求一 提交截图: 6-7: 6-8: 6-9: 7-1: 作业要求二 题目6-7删除字符中数字字符 1.设计思路: (1)第一步:本题要求是删除字符中的数字字符,我的主要思路是通过数组遍历若遇到 ...

  3. socket_sever实现多客户端并发

    #!/usr/bin/env python # -*- coding:utf-8 -*- import socketserver class mysever(socketserver.BaseRequ ...

  4. Flask学习 二 模板

    jinja2模版 from flask import Flask,render_template app = Flask (__name__) @app.route ('/<name>') ...

  5. 【iOS】字号问题

    一,ps和pt转换 px:相对长度单位.像素(Pixel).(PS字体) pt:绝对长度单位.点(Point).(iOS字体) 公式如下: pt=(px/96)*72. 二,字体间转换 1in = 2 ...

  6. [SDOI2014]旅行

    洛谷 P3313 [SDOI2014]旅行 https://www.luogu.org/problem/show?pid=3313 题目描述 S国有N个城市,编号从1到N.城市间用N-1条双向道路连接 ...

  7. xxe漏洞检测及代码执行过程

    这两天看了xxe漏洞,写一下自己的理解,xxe漏洞主要针对webservice危险的引用的外部实体并且未对外部实体进行敏感字符的过滤,从而可以造成命令执行,目録遍历等.首先存在漏洞的web服务一定是存 ...

  8. nodeJs多进程Cluster

    在前端页面中,如果我们想进行多进程,我们会用到WebWorker,而在NodeJs中,我们如果想充分利用服务器核心资源,我们会用到Node中Cluster模块 直接上代码吧: const cluste ...

  9. LeetCode & Q167-Two Sum II - Input array is sorted-Easy

    Array Two Pointers Binary Search Description: Given an array of integers that is already sorted in a ...

  10. Spring Security入门(3-6)Spring Security 的鉴权 - 自定义权限前缀