思路:按顺序处理,新建一堆然后向左右合并,不过巧妙地用了标记数组来记录和统计答案。

 #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 ;
}

最新文章

  1. while跟do...while的用法
  2. centos从日志文件查找关键字的日志并生成文件
  3. ECMAScript 6 简介
  4. jquery hasClass、removeClass、addClass方法
  5. LinkedHashMap和HashMap区别
  6. SSAS数据集Cube不存在或者尚未处理
  7. BZOJ 1089 严格n元树 (递推+高精度)
  8. Spring集合配置
  9. CSS动画效果的回调
  10. 【Mysql基本知识整理】
  11. Scrapy 隐含 bug: 强制关闭爬虫后从 requests.queue 读取的已保存 request 数量可能有误
  12. Qt Designer问题(挖坑)
  13. VMWAR-workstatuon
  14. GIT 版本管理-github&amp;码云
  15. Get filename from URL using Javascript
  16. wpf 导出Excel
  17. 不要问我有多懒,写个脚本跑django
  18. 3ds Max 中的导航控件ViewCube入门介绍
  19. 分析 HTML 代码并提取数据
  20. java 批量文件后缀重命名

热门文章

  1. 详解 volatile关键字 与 CAS算法
  2. 2020新Asp.NET敏捷快速开发框架7.0.5旗舰版源码asp.net mvc框架,工具类CRM,工作流
  3. github使用--配置sshkey
  4. 解决利用hibernate连接mysql时无法插入汉字的问题
  5. 二分查找(通过相对位置判断区间位置)--17--二分--LeetCode33搜索旋转排序数组
  6. debian7安装了mysql后,局域网去连接时出现10061错误
  7. thinkPHP--关于域名指向的问题
  8. 共享文件夹下其他文件可以访问但php文件访问不了的原因
  9. NGINX反向代理,后端服务器获取真实IP
  10. IDEA 之 常用快捷键