[hdu5200]离线+标记
思路:按顺序处理,新建一堆然后向左右合并,不过巧妙地用了标记数组来记录和统计答案。
#pragma comment(linker, "/STACK:10240000,10240000") #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <ctime>
#include <cctype>
#include <set> using namespace std; #define mem0(a) memset(a, 0, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define define_m int m = (l + r) >> 1
#define rep(a, b) for(int a = 0; a < b; a++)
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x) & (-(x)))
#define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
#define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
#define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
#define pc(a) putchar(a)
#define ps(a) puts(a) typedef double db;
typedef long long LL;
typedef pair<int, int> pii;
typedef multiset<int> msi;
typedef multiset<int>::iterator msii;
typedef set<int> si;
typedef set<int>::iterator sii;
typedef vector<int> vi; const int dx[] = {, , -, , , , -, -};
const int dy[] = {, -, , , -, , , -};
const int maxn = 1e6 + ;
const int maxm = 1e5 + ;
const int maxv = 1e7 + ;
const int max_val = 1e6 + ;
const int MD = 1e9 +;
const int INF = 1e9 + ;
const double PI = acos(-1.0);
const double eps = 1e-; inline int ReadInt() {
char c = getchar();
while(!isdigit(c)) c = getchar(); int x = ;
while(isdigit(c)) {
x = x * + c - '';
c = getchar();
}
return x;
} inline void WriteInt(int i) {
int p = ;
static int buf[];
if(i == ) buf[p++] = ;
else while(i) {
buf[p++] = i % ;
i /= ;
}
for(int j = p - ; j >= ; j--) putchar('' + buf[j]);
} bool cmp(const pii &a, const pii &b) {
return a.first > b.first;
} int main() {
//freopen("in.txt", "r", stdin);
int n, q;
while (cin >> n >> q) {
vector<pii> a(n), b(q);
vector<int> out(q);
rep(i, n) {
a[i].first = ReadInt();
a[i].second = i;
}
rep(i, q) {
b[i].first = ReadInt();
b[i].second = i;
}
sort(all(a), cmp);
sort(all(b), cmp);
vector<bool> vis(n);
int now = , ans = ;
rep(i, q) {
while (now < n && a[now].first > b[i].first) {
int pos = a[now].second;
vis[pos] = true;
ans++;
if (pos && vis[pos - ]) ans--;
if (pos < n - && vis[pos + ]) ans--;
now++;
}
out[b[i].second] = ans;
}
rep(i, q) {
WriteInt(out[i]);
pc('\n');
}
}
return ;
}
[hdu5200]离线+标记的更多相关文章
- Android 开发命令行完全攻略
作为命令行的爱好者,我想写这个主题已经有好一段时间了.除了显得很酷之外,命令行的使用能够提高我们的开发效率,因为相比通过鼠标点击一系列的菜单选项,使用键盘输入几个字符并点击 TAB 健显然会快很多. ...
- [BZOJ3473][BZOJ3277]字符串
[BZOJ3473][BZOJ3277]字符串 试题描述 给定 \(n\) 个字符串,询问每个字符串有多少子串(不包括空串)是所有 \(n\) 个字符串中至少 \(k\) 个字符串的子串? 输入 第一 ...
- [UOJ#219][BZOJ4650][Noi2016]优秀的拆分
[UOJ#219][BZOJ4650][Noi2016]优秀的拆分 试题描述 如果一个字符串可以被拆分为 AABBAABB 的形式,其中 A 和 B 是任意非空字符串,则我们称该字符串的这种拆分是优秀 ...
- BestCoder Round #36 (hdu5200)Strange Class(离线)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Trees Time Limit: 2000/1000 MS (Java/Othe ...
- 数值标记问题 离线+树状数组 HDU 3938 + HDU 3333
HDU 3938 题目大意:给你一个长度为n的数组a,定义区间[l,r]的val为区间内所有不同的数值之和.现在有m个询问,每次询问一个区间,问区间的val是多少. 思路:将所有的询问按照右端点排序. ...
- HDU5200 数据离线处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5200 ,数据离线处理. 这是BestCoder Round #36的C题,比赛时自己用线段树做,姿势不 ...
- BZOJ 3626: [LNOI2014]LCA [树链剖分 离线|主席树]
3626: [LNOI2014]LCA Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2050 Solved: 817[Submit][Status ...
- [分享黑科技]纯js突破localstorage存储上线,远程抓取图片,并转码base64保存本地,最终实现整个网站所有静态资源离线到用户手机效果却不依赖浏览器的缓存机制,单页应用最新黑科技
好久没有写博客了,想到2年前答应要放出源代码的也没放出来,最近终于有空先把纯js实现无限空间大小的本地存储的功能开源了,项目地址https://github.com/xueduany/localsto ...
- ACM/ICPC 之 BFS(离线)+康拓展开 (HDU1430-魔板)
魔板问题,一道经典的康拓展开+BFS问题,为了实现方便,我用string类来表示字符串,此前很少用string类(因为不够高效,而且相对来说我对char数组的相关函数比较熟),所以在这里也发现了很多容 ...
随机推荐
- 小小小小小flag
2020:300道题 小小小小小flag 150红题 100道橙题 50道黄题 努力变强!加油 我的主页: 主页https://www.luogu.com.cn/user/306734 谢谢大家,目前 ...
- Python 【面试强化宝典】
四大数据类型的常用方法 列表常用方法 #1. append 用于在列表末尾追加新的对象 a = [1,2,3] a.append(4) #the result : [1, 2, 3, 4] #2. c ...
- tensorflow1.0 队列FIFOQueue管理实现异步读取训练
import tensorflow as tf #模拟异步子线程 存入样本, 主线程 读取样本 # 1. 定义一个队列,1000 Q = tf.FIFOQueue(1000,tf.float32) # ...
- 在手机和电脑间双向加密传输文件 —— Windows 安装 Kde Connect
2020-04-27 作为 Kde 项目的一部分,Windows 用户可能很少知道它,但它确实存在,而且超棒. Kde Connect 简直了,现在我的手机和 Linux 主机以及 Win 本完全是一 ...
- Caused by: java.lang.ClassCastException: class java.lang.Double cannot be cast to class org.apache.hadoop.io.WritableComparable
错误: Caused by: java.lang.ClassCastException: class java.lang.Double cannot be cast to class org.apac ...
- Python初学者常见错误问题汇总
1.在客户端和服务端如何传递数组? 答:在客户端和服务端可以使用json进行数据传输.在客户端把数据转换成json字符串,然后使用POST方法发送给服务端. 服务端收集到数据之后,使用json.loa ...
- 进制之间转换——day_01
一.计算机文件大小单位 b = bit 位(比特) B = Byte 字节 1B = 8b #一个字节等于8位 简写 1Byte = 8 bit 1KB = 1024B 1MB = 1024KB 1G ...
- 关于暴力破解的一些学习笔记(pikachu)
这几天的笔记都懒得发博客都写在本地了,随缘搬上来 什么是暴力破解 就是在攻击者不知道目标账号密码情况下的,对目标系统的常识性登陆 一般会采用一些工具+特定的字典 来实现高效的连续的尝试性登陆 一个有效 ...
- webform 最后的黄昏之力
前言 现在有人谈起webform 一般都会说这种技术已经过时了,毫无用处. 因为我们在日常开发中已经不会去开发哪种几个简单的网页的程序,我们的业务更加复杂,这种拖动式的过于死板. 但是是否毫无用处呢? ...
- .net 使用TCP模拟UDP广播通信加强广播通信的稳定性
应用场景:当每一台终端开启程序后发出消息,其他终端必须收到消息然后处理 思路1:使用UDP广播. 缺点:UDP广播信号不稳定,无法确定每一台机器能接收到信号 思路2:将一台主机作为服务器,使用 ...