[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 ...
随机推荐
- winform 适配high dpi
在 mainifest文件中添加:(新建mainifest文件的时候以下内容是有的,只要取消注释就可以了) <compatibility xmlns="urn:schemas-micr ...
- 从Firefox升级说学习方法
今天早上,打开PortableAPPs时,它提示我升级FireFox,跟往常一样我没考虑就升级了. 打开Firefox 57神速,很是惊喜,打开后发现悲剧了,自己(通过下载插件)定制的功能都不能使用了 ...
- 项目Alpha冲刺Day9
一.会议照片 二.项目进展 1.今日安排 侧栏及相关刷新完成,项目结构小变动.个人信息和修改密码后台完成. 2.问题困难 前后台联调出现问题,配置修改了半天还没改好.好像是会话丢失,初步判断应该是后台 ...
- Flask 学习 四 数据库
class Role(db.Model): __tablename__='roles' id = db.Column(db.Integer,primary_key=True) name = db.Co ...
- js 点击 返回顶部 动画
附上效果图 触发前 触发后 HTML代码: CSS代码 JS代码 由于复制文本太丑了 所以直接放的图片 但是我在评论区把js代码又复制了一边 以便你们使用
- 18-TypeScript模板方法模式
在有些情况下,一个功能在基础功能上是不会变的,算法的基本骨架也是确定的,但是在某些场景下算法的具体实现有些差异.应对这种问题,可以采用模板方法模式: abstract class Salary{ ab ...
- C# reportview 按时间改变行颜色
//) AND ((Day(Now()) - Day() AND (Day(Now()) - Day()),) AND (Day(Now()) - Day()) OR (Month(Now()) - ...
- python多目录字符串查找匹配
1. 需求来自于实际工作: 需要处理一批服务器上运行的redis实例,每个redis实例可能有密码,也可能没有,有密码的,密码配置格式一定是: requirepass XXXXX # XXXX是密码 ...
- Win10下, TortoiseGit安装及配合Gitee使用完整版
Windows10下, TortoiseGit的安装及使用, 并配合Gitee码云使用! 1) 安装TortoiseGit 官网, 32位, 64位, 自选 https://tortoisegit.o ...
- 译《Time, Clocks, and the Ordering of Events in a Distributed System》
Motivation <Time, Clocks, and the Ordering of Events in a Distributed System>大概是在分布式领域被引用的最多的一 ...