A.预处理出来,0(1)输出。

Task schedule

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 387    Accepted Submission(s): 193

Problem Description
有一台机器,而且给你这台机器的工作表。工作表上有n个任务,机器在ti时间运行第i个任务,1秒就可以完毕1个任务。

有m个询问,每一个询问有一个数字q。表示假设在q时间有一个工作表之外的任务请求,请计算何时这个任务才干被运行。

机器总是依照工作表运行。当机器空暇时马上运行工作表之外的任务请求。

 
Input
输入的第一行包括一个整数T。 表示一共同拥有T组測试数据。

对于每组測试数据:

第一行是两个数字n, m,表示工作表里面有n个任务, 有m个询问;

第二行是n个不同的数字t1, t2, t3....tn,表示机器在ti时间运行第i个任务。

接下来m行,每一行有一个数字q,表示在q时间有一个工作表之外的任务请求。



特别提醒:m个询问之间是无关的。



[Technical Specification]

1. T <= 50

2. 1 <= n, m <= 10^5

3. 1 <= ti <= 2*10^5, 1 <= i <= n

4. 1 <= q <= 2*10^5

 
Output
对于每个询问,请计算并输出该任务何时才干被运行,每个询问输出一行。
 
Sample Input
1
5 5
1 2 3 5 6
1
2
3
4
5
 
Sample Output
4
4
4
4
7
 
Source
 
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
///#define LL __int64
#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x) const int maxn = 201000; using namespace std; int vis[maxn];
int num[maxn]; int main()
{
int T;
cin >>T;
while(T--)
{
int n, m;
cin >>n>>m;
memset(vis, 0, sizeof(vis));
int x;
for(int i = 1; i <= n; i++)
{
scanf("%d",&x);
vis[x] = 1;
}
int now;
for(int i = maxn-1; i >= 1; i--)
{
if(!vis[i])
{
now = i;
num[i] = now;
continue;
}
num[i] = now;
}
while(m--)
{
scanf("%d",&x);
printf("%d\n",num[x]);
}
}
return 0;
}

B.统计左右比m大的个数,然后求和。

BestCoder Sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 258    Accepted Submission(s): 108

Problem Description
Mr Potato is a coder.

Mr Potato is the BestCoder.



One night, an amazing sequence appeared in his dream. Length of this sequence is odd, the median number is M, and he named this sequence as Bestcoder Sequence.



As the best coder, Mr potato has strong curiosity, he wonder the number of consecutive sub-sequences which are bestcoder sequences in a given permutation of 1 ~ N.
 
Input
Input contains multiple test cases. 

For each test case, there is a pair of integers N and M in the first line, and an permutation of 1 ~ N in the second line.



[Technical Specification]

1. 1 <= N <= 40000

2. 1 <= M <= N
 
Output
For each case, you should output the number of consecutive sub-sequences which are the Bestcoder Sequences
 
Sample Input
1 1
1
5 3
4 5 3 2 1
 
Sample Output
1
3
Hint
For the second case, {3},{5,3,2},{4,5,3,2,1} are Bestcoder Sequence.
 
Source
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
#define LL __int64
///#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x) const int maxn = 101000; using namespace std; int num[maxn];
LL sum1[maxn];
LL sum2[maxn];
int main()
{
int n, m;
while(cin >>n>>m)
{
memset(sum1, 0, sizeof(sum1));
memset(sum2, 0, sizeof(sum2));
int s;
for(int i = 1; i <= n; i++)
{
scanf("%d",&num[i]);
if(num[i] == m) s = i;
}
int cnt = 0;
int pp = 40000;
sum1[pp] = 1;
for(int i = s-1; i >= 1; i--)
{
if(num[i] > m) cnt++;
else if(num[i] < m) cnt--;
sum1[cnt+pp]++;
}
cnt = 0;
LL ans = 0;
ans += sum1[pp];
for(int i = s+1; i <= n; i++)
{
if(num[i] > m) cnt++;
else if(num[i] < m)cnt--;
sum2[cnt+pp]++;
ans += sum1[pp-cnt];
}
cout<<ans<<endl;
}
return 0;
}

BestCoder Round #3 A,B的更多相关文章

  1. BestCoder Round #89 02单调队列优化dp

    1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01  HDU 5944   水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...

  2. BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元

    BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这 ...

  3. bestcoder Round #7 前三题题解

    BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : ...

  4. Bestcoder round #65 && hdu 5593 ZYB's Tree 树形dp

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  5. Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  6. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  7. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...

  8. BestCoder Round #88

    传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: #include <cstdio> #include ...

  9. BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  10. BestCoder Round #68 (div.2) tree(hdu 5606)

    tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

随机推荐

  1. HDU5441 Travel (离线操作+并查集)

    Travel Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

  2. 《火球——UML大战需求分析》(第3章 分析业务模型-类图)——3.8 小结与练习

    摘要:类图(Class Diagram)可能是用得最多的一种UML图.类图的基本语法并不复杂,你可能最多学习两三天就可以掌握,然而要真正做到活用类图则可能需要几年的功力.类图是锻炼面向对象分析(OOA ...

  3. jquery第二期:三个例子带你走进jquery

    jquery是完全支持css的,我们举个例子来看看使用jquery的方便之处,这功劳是属于选择器的: 例1: <!DOCTYPE html PUBLIC "-//W3C//DTD HT ...

  4. MVC4中 jquery validate 不用submit方式验证表单或单个元素

    正确引入MVC4 jquery验证的相关文件 <script src="/Scripts/jquery-1.4.4.js"></script> <sc ...

  5. notepad++和gcc搭建语言环境

    1,工具: Notepad++:http://pan.baidu.com/s/1sjlXl6X MinGW:http://pan.baidu.com/s/1qWyQ3lq 2,安装notepad++ ...

  6. Unhandled event loop exception 解决办法

    网上搜索了一下.对其他人有效的办法有两种: 1. 安装了adsafe  .卸载掉就可以了. 2.安装了流氓软件:百度杀毒. 卸载掉也解决问题了 我就是第三种情况.到现在还没解决的热.!. 谁还有更好的 ...

  7. struts2之chain的使用

    /** * 实现功能表单提交给action1先处理,再交由action2进行处理,中间传递参数a,b **/ /** * 1. 配置文件 **/ <action name="actio ...

  8. C# 限制Text只能输入数字

    private void InputNumber(KeyPressEventArgs e) { //如果输入的不是数字键,也不是回车键.Backspace键,则取消该输入 && e.K ...

  9. Eclipse MyEclipse 复制项目 复制现有项目 复制功能相似项目

    如果现在已经存在一个Java Web项目 ProjectA,现在想做另外一个项目,里面绝大部分功能和结构都可以复用,如果想通过复制的方法来,那么可以这么做: 1.到资源管理器中,将ProjectA文件 ...

  10. Dubbo使用详解及环境搭建

    一:Dubbo简介 Dubbo是阿里巴巴提供的开源的SOA(面向服务的体系结构)服务化治理的技术框架,据说只是一部分开源的,但一些基本的需求已经可以满足的,而且可扩展性.是一种能取代PHRPC的服务调 ...