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)),这三个解. 代码如 ...
随机推荐
- swift4.0中http连接(据于xcode9.3 URLSession)
NSURLSession是NSURLConnection的替代者,在2013年苹果全球开发者大会上(WWDC2013)随iOS7一起发布的,是对NSURLConnection进行了重构优化后的新的网络 ...
- (转)ios error:unrecognized selector sent to class
转自:http://blog.itpub.net/12231606/viewspace-1081952/ 今天将app统计的.a静态库包含到一个app应用中,调试时报下面的错误: *** Termin ...
- HDU 4778 状压DP
一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...
- Spring Cacheable 注解不缓存null值
用Cacheable注解时,发现空值,也会被缓存下来.如果我们期望空值不被缓存,可以做如下设置: @Cacheable(key = "#id", unless="#res ...
- c#开发_Dev的关于XtraGrid的使用(GridControl小结)
1,增加新行用InitNewRow事件,给新行某字段赋值.后结束编辑. private void grdView_InitNewRow(object sender, DevExpress.XtraGr ...
- 【BZOJ】3039: 玉蟾宫 悬线法
[题意]给定01矩阵,求最大全1子矩阵.n,m<=1000. [算法]动态规划(悬线法) [题解]★对于01矩阵中的任意一个全1极大子矩阵,都可以在其上边界遇到的障碍点处悬线到下边界的点x,则点 ...
- THINKPHP简单商品查询项目
代码:http://files.cnblogs.com/files/wordblog/test.zip
- Linux 脚本内容指定用户执行
#!/bin/bash set -x ## 因为这些变量在下面要用,所以要写在最上面, ## 如果直接写在下面,则变量获取不到,并且下面的 $ 标识的都要用 引号引起来,否则这些参数接收不到 tarf ...
- htmlunit爬虫工具使用--模拟浏览器发送请求,获取JS动态生成的页面内容
Htmlunit是一款模拟浏览抓取页面内容的java框架,具有js解析引擎(rhino),可以解析页面的js脚本,得到完整的页面内容,特殊适合于这种非完整页面的站点抓取. 下载地址: https:// ...
- linux initcall 介绍 (转自http://blog.csdn.net/fenzhikeji/article/details/6860143)
现在以module_init为例分析initcall在内核中的调用顺序 在头文件init.h中,有如下定义: #define module_init(x) __initcall(x); 很明显 ...