离线,树状数组。

数据范围好像有点小,直接暴力可以过的。

我直接上了$n,Q≤100000$的做法:只需要判断区间上比$x$小的数字有几个即可,可以对询问进行离线操作,从左到右一个一个数字插入到树状数组中。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
using namespace std; int n,m;
struct X
{
int id;
int op;
int pos;
int val;
int y;
}s[20010];
int sz;
int ans[10010][2];
int c[10100],a[10100]; int lowbit(int x)
{
return x&(-x);
} void update(int x)
{
while(x<=10000)
{
c[x]++;
x = x+lowbit(x);
}
} int get(int x)
{
int res = 0; while(x>0)
{
res = res + c[x];
x = x-lowbit(x);
}
return res;
} bool cmp(X a,X b)
{
return a.pos<b.pos;
} bool cmp2(X a,X b)
{
if(a.id == b.id) return a.op < b.op;
return a.id < b.id;
} int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
{
int L,R,v; scanf("%d%d%d",&L,&R,&v);
s[sz].id = i;
s[sz].op = 0;
s[sz].pos = L-1;
s[sz].val = a[v];
s[sz].y = v;
sz++;
s[sz].id = i;
s[sz].op = 1;
s[sz].pos = R;
s[sz].val = a[v];
s[sz].y = v;
sz++;
} sort(s,s+sz,cmp); int p = 0;
for(int i=0;i<=n;i++)
{
if(i>0) update(a[i]); while(1)
{
if(p<sz && s[p].pos==i)
{
ans[s[p].id][s[p].op] = get(s[p].val-1);
p++;
}
else break;
}
} sort(s,s+sz,cmp2); int id = 0;
for(int i=0;i<sz;i=i+2)
{
id++;
int num1 = ans[id][1] - ans[id][0];
int num2 = s[i].y - s[i].pos - 1;
if(num1 == num2) printf("Yes\n");
else printf("No\n");
} return 0;
}

CodeForces 811B Vladik and Complicated Book的更多相关文章

  1. Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book

    B. Vladik and Complicated Book time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  2. Codeforces 811 B. Vladik and Complicated Book

    B. Vladik and Complicated Book   time limit per test 2 seconds memory limit per test 256 megabytes i ...

  3. codeforces 811E Vladik and Entertaining Flags(线段树+并查集)

    codeforces 811E Vladik and Entertaining Flags 题面 \(n*m(1<=n<=10, 1<=m<=1e5)\)的棋盘,每个格子有一个 ...

  4. Vladik and Complicated Book CodeForces - 811B (思维实现)

    Vladik had started reading a complicated book about algorithms containing n pages. To improve unders ...

  5. Codeforces 743C - Vladik and fractions (构造)

    Codeforces Round #384 (Div. 2) 题目链接:Vladik and fractions Vladik and Chloe decided to determine who o ...

  6. 【dp】codeforces C. Vladik and Memorable Trip

    http://codeforces.com/contest/811/problem/C [题意] 给定一个自然数序列,在这个序列中找出几个不相交段,使得每个段的异或值之和相加最大. 段的异或值这样定义 ...

  7. CodeForces - 811C Vladik and Memorable Trip(dp)

    C. Vladik and Memorable Trip time limit per test 2 seconds memory limit per test 256 megabytes input ...

  8. CodeForce-811B Vladik and Complicated Book(水题)

    http://codeforces.com/problemset/problem/811/B 题意: 给定一个长度为 N 不重复的数字序列,然后对其进行 M 次询问. 每次询问含L,R,X三个值,问如 ...

  9. CodeForces 743C Vladik and fractions (数论)

    题意:给定n,求三个不同的数满足,2/n = 1/x + 1/y + 1/z. 析:首先1是没有解的,然后其他解都可以这样来表示 1/n, 1/(n+1), 1/(n*(n+1)),这三个解. 代码如 ...

随机推荐

  1. 小程序 mcrypt加密拓展在php7.1 废弃 使用openssl替代方案

    原加密方法 使用mcrypt //获得16位随机字符串,填充到明文之前 $random = $this->getRandomStr(); $text = $random . pack(" ...

  2. 洛谷 Transformations 方块转换

    Description 一块N x N(1<=N<=10)正方形的黑白瓦片的图案要被转换成新的正方形图案.写一个程序来找出将原始图案按照以下列转换方法转换成新图案的最小方式: 1:转90度 ...

  3. Metasploit 进阶

    本文是"T00LS Metasploit(第二季)"的文档版,是个人在观看视频动手操作的一个记录,仅供学习.文中会介绍Metasploit的一些基本使用:主要包括远程代码执行.MI ...

  4. scrapy爬虫框架介绍

    一 介绍 Scrapy一个开源和协作的框架,其最初是为了页面抓取 (更确切来说, 网络抓取 )所设计的,使用它可以以快速.简单.可扩展的方式从网站中提取所需的数据.但目前Scrapy的用途十分广泛,可 ...

  5. 项目开发 -- ZFS容量分配

    存储池 allocated 池中已实际分配的存储空间量.该属性也可通过其简短列名alloc来引用. capacity 已用的池空间百分比.此属性也可通过其简短列名cap来引用. dedupratio ...

  6. long类型的数据转化为时间

    long time = 111111111111111111111:SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm: ...

  7. TinyOS 代码分析

    1.Basestation案例   位于/opt/tinyos-main-master/apps/Basetation 1.1本例的顶层结构图: 1.2软件实现流程 1) uartIn,uartOut ...

  8. Lucene7.2.1系列(二)luke使用及索引文档的基本操作

    系列文章: Lucene系列(一)快速入门 Lucene系列(二)luke使用及索引文档的基本操作 Lucene系列(三)查询及高亮 luke入门 简介: github地址:https://githu ...

  9. 记一个logrotate的配置文件权限问题

    问题描述 从git仓库更新了别人配置好的logrotate,发现不能正常运行.手工执行报错 error: Ignoring syslog because of bad file mode - must ...

  10. 去除\ufeff的解决方法,python语言

    语言:python 编程工具:pycharm 硬件环境:win10 64位 读取文件过程中发现一个问题:已有记事本文件(非空),转码 UTF-8,复制到pycharm中,在开始位置打印结果会出现  \ ...