离线,树状数组。

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

我直接上了$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. [DeeplearningAI笔记]序列模型3.3集束搜索

    5.3序列模型与注意力机制 觉得有用的话,欢迎一起讨论相互学习~Follow Me 3.3 集束搜索Beam Search 对于机器翻译来说,给定输入的句子,会返回一个随机的英语翻译结果,但是你想要一 ...

  2. [DeeplearningAI笔记]卷积神经网络4.11一维和三维卷积

    4.4特殊应用:人脸识别和神经网络风格转换 觉得有用的话,欢迎一起讨论相互学习~Follow Me 4.11一维和三维卷积 二维和一维卷积 对于2D卷积来说,假设原始图像为\(14*14*3\)的三通 ...

  3. debian自动挂载ntfs硬盘

    首先下载安装ntfs-3g apt-get install ntfs-3g 然后查看分区信息 fdisk -l Device Boot Start End Blocks Id System /dev/ ...

  4. 算法专题-STL篇

    这篇文章着重记录c++中STL的用法.主要粗略的介绍其用法,以知识点的形式呈现其功能,不会深入源码分析其工作原理. 排序和检索. sort(a,a+n),对a[0]往后的n个元素(包括a[0])进行排 ...

  5. Flying to the Mars

    D - Flying to the Mars Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I ...

  6. [译]Quartz 框架 教程(中文版)2.2.x 之第二课 Quartz API,Jobs和Triggers简介

    第二课:QuartzAPI,Jobs和Triggers简介 Quartz API Quartz API 关键的几个接口: Scheduler:跟任务调度相关的最主要的API接口. Job:你期望任务调 ...

  7. Spark 基本架构及原理

    转载自: http://blog.csdn.net/swing2008/article/details/60869183 转自:http://www.cnblogs.com/tgzhu/p/58183 ...

  8. 【BZOJ】2154: Crash的数字表格 莫比乌斯反演

    [题意]给定n,m,求Σlcm(i,j),1<=i<=n,1<=j<=m,n,m<=10^7. [算法]数论(莫比乌斯反演) [题解] $$ans=\sum_{i\leq ...

  9. HDU 2050 折线分割平面 (数学)

    题目链接 Problem Description我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目.比如,一条折线可以将平面分成两部分,两条折线最多可 ...

  10. python3爬虫.3.下载网页图片

    目标,豆瓣读书, 下载页面书籍图片. import urllib.request import re #使用正则表达式 def getJpg(date): jpgList = re.findall(r ...