BestCoder Round #3 A,B
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時間有一個工作表之外的任務請求,請計算何時這個任務才能被執行。
機器總是按照工作表執行,當機器空閒時立即執行工作表之外的任務請求。
有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
對於每組測試資料:
第一行是兩個數字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.
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
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 #25 A,B
- BestCoder Round #20 B,C
- hdu 5086 Revenge of Segment Tree(BestCoder Round #16)
- BestCoder Round #861001Price List(數學)
- BestCoder Round #2 1001 TIANKENG’s restaurant(區間內查詢)REST
- Restaurant Testing Round #12 BREST
- Codeforces Round #399 (A,B,C)
- Codeforces Round #448 (Div. 2)B
- Codeforces Round #450 (Div. 2) B
- CF 2B The least round way(DP)AST
- Codeforces Round 840題解(A、B、C)
- codeforces round 961題解(A、B、C)
- Codeforces Testing Round #10 B. Balancer
- Codeforces Round #251 (Div. 2) A/B/D
- Codeforces Round 949題解(A、B、C、D)
- 牛客周賽 Round 3
- codeforces round #234B(DIV2) B Inna and New Matrix of Candies
- 【Codeforces Round #499 (Div. 1) B】Rocket
- Codeforces Round #362 (Div. 2) B 模擬
- Codeforces Round #336 (Div. 2) B 暴力
- Codeforces Round #325 (Div. 2) B 遞推
- Codeforces Round #290 (Div. 2) A,B,C,D
- Codeforces Round #245 (Div. 2) B - Balls GameGAM
- Codeforces Round 934 2D/1B
- Codeforces Round 962(Div .3)
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B 暴力
- Codeforces Round #491 (Div. 2) B. Getting an A
- Codeforces Round #361 (Div. 2) B BFS最短路
- Codeforces Round #323 (Div. 2) B 模擬
- Codeforces Round #321 (Div. 2) B 二分
- Codeforces Round #288 (Div. 2) A,B,C,D,E
- Codeforces Round #287 (Div. 2)A,B,C,D,E
- Codeforces Round #242 (Div. 2) B. Megacity
- Codeforces Round #249 (Div. 2) B. Pasha Maximizes
- Codeforces Round #247 (Div. 2) B - Shower Line
- Codeforces Round #253 (Div. 2) B - Kolya and Tandem Repeat
- Codeforces Round #252 (Div. 2) B. Valera and FruitsUI
- Codeforces Round #246 (Div. 2) B. Football Kit