【Best Coder】#36 C tree
来源:互联网 发布:java防止xss攻击代码 编辑:程序博客网 时间:2024/05/17 01:42
好吧,我承认是抄别人的代码的。
但感觉这道题目确实得好好学习学习。
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define MAX 50005struct node{int v;int id;}h[MAX],q[MAX];int co[MAX];int res[MAX];bool cmp(node a, node b){return a.v > b.v;}int main(){int n, qq;while (~scanf("%d%d", &n, &qq)){memset(co, 0, sizeof(co));for (int i = 0; i < n; i++){scanf("%d", &h[i].v);h[i].id = i;}for (int i = 0; i < qq; i++){scanf("%d", &q[i].v);q[i].id = i;}sort(h, h + n, cmp);sort(q, q + qq, cmp);int pos = 0;int ans = 0;for (int i = 0; i < qq; i++){while (pos<n&&h[pos].v>q[i].v){if (co[h[pos].id - 1])ans--;if (co[h[pos].id + 1])ans--;ans++;co[h[pos].id] = 1;pos++;}res[q[i].id] = ans;}for (int i = 0; i < qq; i++)printf("%d\n", res[i]);}}
0 0
- 【Best Coder】#36 C tree
- best coder 第六场
- best coder 资格赛D
- best coder #17 1002 Select
- 【Best Coder】Go to movies
- Best Coder Matrix(数学)
- Best Coder Lotus and Characters
- Best Coder MG loves gold
- hdu 4883 (Best Coder) TIANKENG’s restaurant
- Best Coder Round 12【so easy】
- Best coder 2014-3-14题解
- 【Best Coder】#34 B Building Blocks
- hdu-4883- (Best Coder) TIANKENG’s restaurant
- Best coder 52div21001Victor and Machine
- Best Coder 1003 string(dp)
- 裂变位法加密 best coder
- Best Coder #92 1001 Skip The Class
- coder-strike 2014 C Kicker
- Android Studio在创建项目是一直处于building “project name”gradle project info的解决办法
- Memcache学习总结3-Memcache的配置项详解
- 《JAVA编程思想》笔记-对象导论&一切都是对象
- URL,URLConnection,HttpURLConnection
- 习题6-12 筛子难题 UVa810
- 【Best Coder】#36 C tree
- SDKD TeamContest A-E - 1005
- 删除星号字符
- HDU P5200 Trees
- dubbo learning - day 2
- javascript-this对象指代
- hibernate的ManyToOne的单向关联
- 算法学习之路-交换排序
- 第五章 语句