CodeForces 811B Vladik and Complicated Book
离线,树状数组。
数据范围好像有点小,直接暴力可以过的。
我直接上了$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的更多相关文章
- 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 ...
- 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 ...
- codeforces 811E Vladik and Entertaining Flags(线段树+并查集)
codeforces 811E Vladik and Entertaining Flags 题面 \(n*m(1<=n<=10, 1<=m<=1e5)\)的棋盘,每个格子有一个 ...
- Vladik and Complicated Book CodeForces - 811B (思维实现)
Vladik had started reading a complicated book about algorithms containing n pages. To improve unders ...
- Codeforces 743C - Vladik and fractions (构造)
Codeforces Round #384 (Div. 2) 题目链接:Vladik and fractions Vladik and Chloe decided to determine who o ...
- 【dp】codeforces C. Vladik and Memorable Trip
http://codeforces.com/contest/811/problem/C [题意] 给定一个自然数序列,在这个序列中找出几个不相交段,使得每个段的异或值之和相加最大. 段的异或值这样定义 ...
- 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 ...
- CodeForce-811B Vladik and Complicated Book(水题)
http://codeforces.com/problemset/problem/811/B 题意: 给定一个长度为 N 不重复的数字序列,然后对其进行 M 次询问. 每次询问含L,R,X三个值,问如 ...
- CodeForces 743C Vladik and fractions (数论)
题意:给定n,求三个不同的数满足,2/n = 1/x + 1/y + 1/z. 析:首先1是没有解的,然后其他解都可以这样来表示 1/n, 1/(n+1), 1/(n*(n+1)),这三个解. 代码如 ...
随机推荐
- Jquery中find与each方法使用详解
本文实例讲述了jQuery中find与each方法用法.分享给大家供大家参考.具体如下: 一.find()方法 jquery选择器非常强大,利用css的命名规约,可以更快更方便的找出想要的元素. 图解 ...
- C11线程管理:异步操作
1.异步操作 C++11提供了异步操作相关的类,std::future.std::promise和std::package_task.std::future作为异步结果的传输通道,方便的获取线程函数的 ...
- 【BZOJ】3238: [Ahoi2013]差异
[题意]给定长度为n的小写字母字符串,令Ti表示以i开头的后缀,求Σ[Ti+Tj-2*lcp(Ti,Tj)],1<=i<j<=n. [算法]后缀自动机 [题解]Σ(Ti+Tj)只与n ...
- 【POJ】2774 Long Long Message
[题意]给定两个字符串S和T,求最长公共子串.len<=10^5. [算法]后缀自动机 [题解]对字符串S建SAM,然后令串T在S上跑匹配. 这是自动机最原本的功能——匹配,就是串T在SAM(S ...
- js小记:对象、原型及原型链、面向对象编程
一.js对象 1.js对象 js对象是一种复合数据类型,它可以把多个(不同类型的)数据集中在一个变量中,并且给每个数据起名字. 2.对象与数组 对象的每个数据有对应的名字(属性名),我们通过叫名字访问 ...
- MQTT协议及推送服务(二)
MQTT简介 MQTT全称叫做Message Queuing Telemetry Transport,意为消息队列遥测传输,是IBM开发的一个即时通讯协议.由于其维护一个长连接以轻量级低消耗著称,所以 ...
- [POJ3370]&[HDU1808]Halloween treats 题解(鸽巢原理)
[POJ3370]&[HDU1808]Halloween treats Description -Every year there is the same problem at Hallowe ...
- 读书笔记 ~ Nmap渗透测试指南
记录Nmap选项及脚本使用,仅供参考... 除了端口扫描,好像其它脚本都比较鸡肋,用途感觉应该没有专用的小工具好用,不过还是可以看看,选项和脚本还是相当的丰富的. Nmap 使用帮助 starnigh ...
- python 天气爬虫
python3 爬取全国天气信息 制作一个天气查询软件,能够查询全国范围内的天气数据. github:https://github.com/1052687889/weatherApp 基于PyQt5编 ...
- Maven如何发布项目到一个Tomcat中
首先,在本地tomcat的conf/tomcat-users.xml 中配置一个user,准备让maven接入时使用: <role rolename="admin-gui"/ ...