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;
}
转载于:https://www.cnblogs.com/zufezzt/p/6930423.html
CodeForces 811B Vladik and Complicated Book相关推荐
- Codeforces 题目合集+分类+代码 【Updating...】【361 in total】
961A - Tetris 模拟 ...
- codeforces round 416 div2补题
第一题,水题 A. Vladik and Courtes #include<bits/stdc++.h> using namespace std; int main() {long lon ...
- Codeforces Round #416 (Div. 2)
地址:点我 A. Vladik and Courtesy 模拟 #include<iostream> using namespace std; int main(){int n,m;sca ...
- c语言符号运算优先级6,c语言运算符号的优先级
c语言运算符号的优先级 本文来自百度搜索只为查看方便 优先级等级口诀: 圆方括号.箭头一句号, 自增自减非反负.针强地址长度, 乘除,加减,再移位, 小等大等.等等不等, 八位与,七位异,六位或,五与 ...
- Codeforces Round # 555 (Div. 3) C2. Increasing subsequence (complicated version) (贪心)
题目链接:http://codeforces.com/contest/1157/problem/C2 当左右两边数字相同时,需要判断一下取哪边能得到更长的递增序列 #include <iostr ...
- Codeforces Round #253 (Div. 1) A. Borya and Hanabi 暴力
A. Borya and Hanabi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/442/p ...
- 【Codeforces】 Round #374 (Div. 2)
Position:http://codeforces.com/contest/721 我的情况 开始还是rank1,秒出C.(11:00机房都走光了,我ma到11:05才走,只打了一个小时) 结果.. ...
- Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题
A. One-dimensional Japanese Crossword 题目连接: http://codeforces.com/contest/721/problem/A Description ...
- Codeforces 915 E Physical Education Lessons
题目描述 This year Alex has finished school, and now he is a first-year student of Berland State Univers ...
最新文章
- 苹果发布会体现出的未来趋势
- Kafka工作原理简要概述
- 关于SET和UNORDER_SET
- Debian 8开启sftp服务
- 操作系统上机题目(多线程2)
- mysql中新建不了查询语句_将excel和mysql建立链接后,如何通过在excel里面执行mysql查询语句,然后建立查询...
- Python 中的协程 (4) asyncio模块
- java 的 provider_Java里的Provider是什么?
- coco数据集大小分类_COCO数据集的简单介绍
- 学习ubuntu 网址
- 20170908算法工程师在线笔试之jd编程思路
- STM32 vcap引脚
- red5流媒体服务器安装
- 图像增强——Roberts算子、Sobel算子、Prewitt算子、Laplace算子
- LabVIEW开发结构监控系统
- python函数(一)——def语句,作用域和参数
- 4.PEB断链隐藏模块
- 一个好玩的编程小游戏—— 母牛生小牛
- 用监控摄像机搭建视频直播系统的方式
- tyvector在matlab中代表,MATLAB曲线绘制
热门文章
- Vue访问百度音乐API实现播放时no-referrer-when-downgrade
- 关于能否命令Scrum团队的对话
- 在Flutter中更快地加载您的图像资源
- JSP中response,session,cookie,application的作用及区别
- js 字符串加减法_JavaScript (+) 加法运算符
- hashmap储存有向图_如何在Rust中构建向量的HashMap?
- Linux系统入门之如何安装Linux系统
- 误入前端三年,一个文科生的独白(上)
- 快速打开IIS的方法
- 1165: 零起点学算法72——首字母变大写