A. Unimodal Array
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Array of integers is unimodal, if:

  • it is strictly increasing in the beginning;
  • after that it is constant;
  • after that it is strictly decreasing.

The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.

For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6].

Write a program that checks if an array is unimodal.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000) — the elements of the array.

Output

Print "YES" if the given array is unimodal. Otherwise, print "NO".

You can output each letter in any case (upper or lower).

Examples
Input
6
1 5 5 5 4 2
Output
YES
Input
5
10 20 30 20 10
Output
YES
Input
4
1 2 1 2
Output
NO
Input
7
3 3 3 3 3 3 3
Output
YES
Note

In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).

题意:给你一个序列,判断这个序列是否第一部分严格递增,第二部分相同 第三部分严格递减  第一第三部分可以省去

题解:迷之题意 如下代码可ac

 #pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll __int64
using namespace std;
int n;
int a[];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
int l=,r=n;
for(int i=;i<n;i++)
{
if(a[i+]>a[i]){
l++;
}
else
break;
}
for(int i=n;i>;i--)
{
if(a[i-]>a[i]){
r--;
}
else
break;
}
for(int i=l;i<r;i++)
{
if(a[i]!=a[i+]){
printf("NO\n");
return ;
}
}
printf("YES\n");
return ;
}
B. Keyboard Layouts
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.

You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order.

You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.

Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters.

Input

The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout.

The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout.

The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000.

Output

Print the text if the same keys were pressed in the second layout.

Examples
Input
qwertyuiopasdfghjklzxcvbnm
veamhjsgqocnrbfxdtwkylupzi
TwccpQZAvb2017
Output
HelloVKCup2017
Input
mnbvcxzlkjhgfdsapoiuytrewq
asdfghjklqwertyuiopzxcvbnm
7abaCABAABAcaba7
Output
7uduGUDUUDUgudu7
题意:给你两个乱序字母表 以及一个按照第一个字母表的一段输出 输出按照第二个字母表的输出
题解:map<char,char>
 #pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll __int64
using namespace std;
char a[];
char b[];
char d[];
map<char,char> mp;
int main()
{
scanf("%s",a);
scanf("%s",b);
for(char i='';i<='';i++)
mp[i]=i;
for(int i=;i<;i++)
{
mp[a[i]]=b[i];
mp[a[i]-'a'+'A']=b[i]-'a'+'A';
}
scanf("%s",d);
int len=strlen(d);
for(int i=;i<len;i++)
{
printf("%c",mp[d[i]]);
}
cout<<endl;
return ;
}
C. Jury Marks
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.

Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b1, b2, ..., bn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.

Your task is to determine the number of options for the score the participant could have before the judges rated the participant.

Input

The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.

The second line contains k integers a1, a2, ..., ak ( - 2 000 ≤ ai ≤ 2 000) — jury's marks in chronological order.

The third line contains n distinct integers b1, b2, ..., bn ( - 4 000 000 ≤ bj ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.

Output

Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).

Examples
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
Note

The answer for the first example is 3 because initially the participant could have  - 10, 10 or 15 points.

In the second example there is only one correct initial score equaling to 4 002 000.

题意:k个人依次打分(k个分数是按照打分的时间顺序给的) 给你n个在打分过程中出现过的分数 判断有多少种初始分的选择

题解:以n个打分过程中出现过的分数 做为第k个人打分后得到的分数 可以求得每个人打分可能对应哪些初始分  判断初始分的正确性即可 统计个数输出

 #include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll __int64
using namespace std;
int n,k;
int sum[];
map<int,set<int>>m;
set<int>::iterator it;
int main()
{
scanf("%d %d",&k,&n);
sum[]=;
int exm;
for(int i=; i<=k; i++)
{
scanf("%d",&exm);
sum[i]=sum[i-]+exm;
}
for(int i=; i<=n; i++)
{
scanf("%d",&exm);
for(int j=; j<=k; j++)
{
m[i].insert(exm-sum[j]);
}
}
int ans=;
for(it=m[].begin(); it!=m[].end(); it++)
{
int jishu=;
for(int i=;i<=n;i++){
if(m[i].find(*it)!=m[i].end()){
jishu++;
}
else
break;
}
if(jishu==n-)
ans++;
}
printf("%d\n",ans);
return ;
}
D. Office Keys
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.

You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.

Input

The first line contains three integers n, k and p (1 ≤ n ≤ 1 000, n ≤ k ≤ 2 000, 1 ≤ p ≤ 109) — the number of people, the number of keys and the office location.

The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — positions in which people are located initially. The positions are given in arbitrary order.

The third line contains k distinct integers b1, b2, ..., bk (1 ≤ bj ≤ 109) — positions of the keys. The positions are given in arbitrary order.

Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.

Output

Print the minimum time (in seconds) needed for all n to reach the office with keys.

Examples
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
Note

In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys.

题意:给你n个人的位置 k把钥匙的位置 以及办公室的位置p  每个人只能拿一把钥匙去开办公室的门 问最少需要多少时间才能使所有的人都到达办公室

题解:暴力 细想一下n个人应当取相邻的n把钥匙

 #pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll __int64
using namespace std;
ll n,k,p;
ll a[];
ll b[];
int main()
{
scanf("%I64d %I64d %I64d",&n,&k,&p);
for(int i=;i<=n;i++)
scanf("%I64d",&a[i]);
for(int i=;i<=k;i++)
scanf("%I64d",&b[i]);
sort(a+,a++n);
sort(b+,b++k);
ll ans=1e18;
for(int i=,j=n;j<=k;i++,j++)
{
ll maxn=;
for(int l=i;l<=j;l++)
maxn=max(maxn,abs(a[l-i+]-b[l])+abs(b[l]-p));
ans=min(ans,maxn);
}
printf("%I64d\n",ans);
return ;
}
E. Cards Sorting
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.

Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is.

You are to determine the total number of times Vasily takes the top card from the deck.

Input

The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of cards in the deck.

The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), where ai is the number written on the i-th from top card in the deck.

Output

Print the total number of times Vasily takes the top card from the deck.

Examples
Input
4
6 3 1 2
Output
7
Input
1
1000
Output
1
Input
7
3 3 3 3 3 3 3
Output
7
Note

In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.

题意:给你一些card上面写着数字 每次操作 如果当前数字是所有牌中最小的值则将这个牌扔掉 否则放到底部 问最少要进行多少次操作能够扔掉所有的牌

题解:树状数组+二分  注意一点 将数字i都扔掉之后 是从最后一个数字i的右边开始 扔掉 数字i+1 这就是为什么要在数字i+1的所有位置中二分一个第一个大于be的位置

 #pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll __int64
using namespace std;
ll tree[];
ll n;
ll a[];
map<ll,set<ll> >mp;
set<ll> ::iterator it,mid;
ll lowbit(ll x)
{
return x&(-x);
}
void add(ll x,ll y)
{
while(x<n+)
{
tree[x]+=y;
x+=lowbit(x);
}
}
ll sum(ll x){
ll res=;
while(x>)
{
res+=tree[x];
x-=lowbit(x);
}
return res;
}
int main()
{
scanf("%I64d",&n);
for(int i=;i<=n;i++)
{
scanf("%I64d",&a[i]);
mp[a[i]].insert(i);//将数a[i]出现的位置存下来
add(i,);//将位置加到树状数组
}
ll be=;
ll j=;
ll ans=;
for(int i=;i<=;i++)//从小到大枚举每个值
{
mid=mp[i].upper_bound(be);//找到第一个大于be的位置
for(it=mid;it!=mp[i].end();it++)//先扔掉后面位置的
{
j++;
add(*it,-);
be=*it;
}
for(it=mp[i].begin();it!=mid;it++)//扔掉前面的
{
if(it==mp[i].begin())//这里说明 已经结束了一轮 计算上一轮的ans贡献
{
ans=ans+j+sum(n);
j=;
}
add(*it,-);
j++;
be=*it;
}
}
printf("%I64d\n",ans+j);
return ;
}

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) A 水 B stl C stl D 暴力 E 树状数组的更多相关文章

  1. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 831E) - 线段树 - 树状数组

    Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this int ...

  2. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)

    http://codeforces.com/contest/831 A. Unimodal Array time limit per test 1 second memory limit per te ...

  3. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法

    Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...

  4. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)A,B,C

    A:链接:http://codeforces.com/contest/831/problem/A 解题思路: 从前往后分别统计递增,相等,递减序列的长度,如果最后长度和原序列长度相等那么就输出yes: ...

  5. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

    题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...

  6. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  7. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem A - B

    Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is cons ...

  8. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) - D

    题目链接:http://codeforces.com/contest/831/problem/D 题意:在一个一维坐标里,有n个人,k把钥匙(钥匙出现的位置不会重复并且对应位置只有一把钥匙),和一个终 ...

  9. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) - C

    题目链接:http://codeforces.com/contest/831/problem/C 题意:给定k个评委,n个中间结果. 假设参赛者初始分数为x,按顺序累加这k个评委的给分后得到k个结果, ...

随机推荐

  1. centos7.2部署docker-17.06.0-ce的bug:Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"\"".

    现象: 操作系统:centos 7.2 kernel 3.10.0-327.el7.x86_64 mesos:1.3.0 docker:docker-17.06.0-ce 在做mesos验证时,通过m ...

  2. 苹果任命奢侈品牌博柏利CEO为零售与在线商店高级副总裁

    苹果今天宣布任命英国奢侈品牌博柏利(Burberry)CEO安吉拉•阿伦茨(Angela Ahrendts)为零售与在线商店高级副总裁.这是一个新设的职位,未来她将直接向CEO蒂姆•库克(Tim Co ...

  3. spring mvc ajaxfileupload文件上传返回json下载问题

    问题:使用spring mvc ajaxfileupload 文件上传在ie8下会提示json下载问题 解决方案如下: 服务器代码: @RequestMapping(value = "/ad ...

  4. 【算法设计与数据结构】为何程序员喜欢将INF设置为0x3f3f3f3f?(转)

    摘自https://blog.csdn.net/jiange_zh/article/details/50198097 在算法竞赛中,我们常常需要用到一个“无穷大”的值,对于我来说,大多数时间我会根据具 ...

  5. 软件工程第七周psp

    1.PSP表格 类别 任务 开始时间 结束时间 中断时间 delta时间 立会 汇报昨天的成绩,分配任务,部署计划 10月27日18:00 10月27日18:36 0 36分钟 准备工作 查阅有关资料 ...

  6. NSURLErrorDomain错误代码

    kCFURLErrorUnknown = -998, kCFURLErrorCancelled = -999, kCFURLErrorBadURL = -1000, kCFURLErrorTimedO ...

  7. sql数据库表容量

    标题:SQL Server 的最大容量规范 数据库的文件大小,文件数量都有限制. 表的大小也有限制,如果表过大,查询效率就会下降,考虑对数据进行分割,对历史数据进行独立存储.

  8. swift - tabBar图片设置的一些注意点

    图片大小尺寸 刚刚开始接触的话,从美工那边拿来的图标大小一般都是偏大的,就像这样: 在此建议,tabBar的图标大小可以是32*32,个人感觉效果不错 图片的颜色问题 如上图所示,该图标的期望颜色(也 ...

  9. 关于“问吧APP”问卷调查报告分析与体会

         上周根据我们走廊奔跑队的“问吧APP”项目对本校范围内的学生发放了上百份调查问卷,并对此作出了统计和整理.针对我们项目所提出的问题涉及到的用户信息有性别.年龄.学历.职业.平时上网途径以及对 ...

  10. 【剑指offer】Java实现(持续更新中)

    面试题3 二维数组中的查找 Leetcode--74 Search a 2D Matrix /*Java Write an efficient algorithm that searches for ...