A. Vladik and Courtesy
2 seconds
256 megabytes
 

At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.

More formally, the guys take turns giving each other one candy more than they received in the previous turn.

This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, theydon’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.

Input

Single line of input data contains two space-separated integers ab (1 ≤ a, b ≤ 109) — number of Vladik and Valera candies respectively.

Output

Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.

 
input
1 1
output
Valera
input
7 6
output
Vladik
Note:

Illustration for first test case:

Illustration for second test case:

题目大意:

     Vladik and Valera 各有a块和b块糖,他两个轮流送给对方糖果,Vladik and Valera 1块、

     Valera送给Vladik 2块、Vladik and Valera 3块....直到有一方无法送出相应的糖果时结束。

     输出对应的人名。

解题思路:暴力模拟即可。

 #include <stdio.h>
int main ()
{
int a,b;
while (~scanf("%d%d",&a,&b))
{
for (int i = ;a>=&&b>=; i ++)
{
if (i%) a-= i;
else b -= i;
}
if (a < )
printf("Vladik\n");
else
printf("Valera\n");
}
return ;
}
B. Vladik and Complicated Book
 

2 seconds

256 megabytes
 

Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.

Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.

Input

First line contains two space-separated integers nm (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.

Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.

Each of the next m lines contains three space-separated integers lirixi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.

Output

For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.

 
input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
output
Yes
No
Yes
Yes
No
input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
output
Yes
No
Yes
No
Yes
Note:

Explanation of first test case:

  1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
  2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
  3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
  4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
  5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".

题目大意:

     输入n个整数,然后有m次询问。每次询问输入三个整数L,R,X,将[L,R]范围内的整数从小到大排序,

     判断第X个整数的位置是否发生变化。

解题思路:

     下午写的时候,特意看了下数据范围,发现不是太大就直接sort了。不过最后被无情的hack了。。。。

     后来在codeforces群里看大佬们讨论时提到一种思路,对于每一个询问只用判断[L,R]中小于第X个整数的个数

     是否等于X-L(因为 (1 ≤ li ≤ xi ≤ ri ≤ n) 所以只要在[L,R]中有X-L个整数小于Xi排序之后就不会影响Xi的位置)

 #include <stdio.h>
int main ()
{
int n,m,i,l,r,x;
int p[];
while (~scanf("%d%d",&n,&m))
{
for (i = ; i <= n; i ++)
scanf("%d",&p[i]);
while (m --)
{
int sum = ;
scanf("%d%d%d",&l,&r,&x);
for(i = l; i <= r; i ++)
if (p[i] < p[x])
sum ++;
if (x-l == sum)
printf("Yes\n");
else
printf("No\n");
}
}
return ;
}

Codeforces Round #416 (Div. 2) A+B的更多相关文章

  1. Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)

    A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

  2. Codeforces Round#416 Div.2

    A. Vladik and Courtesy 题面 At regular competition Vladik and Valera won a and b candies respectively. ...

  3. Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip

    http://codeforces.com/contest/811/problem/C 题意: 给出一行序列,现在要选出一些区间来(不必全部选完),但是相同的数必须出现在同一个区间中,也就是说该数要么 ...

  4. Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game

    地址:http://codeforces.com/contest/811/problem/D 题目: D. Vladik and Favorite Game time limit per test 2 ...

  5. Codeforces Round #416(Div. 2)-811A.。。。 811B.。。。 811C.dp。。。不会

    CodeForces - 811A A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 meg ...

  6. Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book

    B. Vladik and Complicated Book time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  7. Codeforces Round #416 (Div. 2)A B C 水 暴力 dp

    A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  8. 【分类讨论】【spfa】【BFS】Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game

    那个人第一步肯定要么能向下走,要么能向右走.于是一定可以判断出上下是否对调,或者左右是否对调. 然后他往这个方向再走一走就能发现一定可以再往旁边走,此时就可以判断出另一个方向是否对调. 都判断出来以后 ...

  9. 【动态规划】 Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip

    划分那个序列,没必要完全覆盖原序列.对于划分出来的每个序列,对于某个值v,要么全都在该序列,要么全都不在该序列.  一个序列的价值是所有不同的值的异或和.整个的价值是所有划分出来的序列的价值之和.   ...

随机推荐

  1. js对函数参数的封装

    对函数参数的封装 一个原始函数有n个参数,用wrap对函数进行封装,生成一个新的函数,当给它传入参数数量为n的时候,将执行原始函数,否则不执行 //函数封装 function wrap(func){ ...

  2. windows下实现屏幕分享(C#)

    采用UDP广播进行数据的传输,实现windows下进行低延迟的屏幕共享. 开发语言:C# 第三方组件:Redis 1.实现思路 总体流程图 DGIS.DesktopShare实现windows下屏幕分 ...

  3. archlinux安装tftp

    1. 安装  [guo@archlinux ~]$ sudo pacman -S tftp-hpa 2. 启用  [guo@archlinux ~]$ systemctl start tftpd.se ...

  4. mongo嵌套查询

    db.getCollection('TradeBookingRepresentation').find({uitid:'168282:20190214010009224', tradeVersion: ...

  5. zipimport.ZipImportError: can't find module 'encodings'

    环境说明:windows 7.python 3.7.0.pyinstaller 3.1. 解决方案:升级pyinstaller 到 3.4.

  6. 线程局部存储空间 pthread_key_t、__thread 即 ThreadLocal

    https://www.jianshu.com/p/495ea7ce649b?utm_source=oschina-app 该博客还未学习完  还有   pthread_key_t    Thread ...

  7. Linux-文件目录类命令

    l 文件目录类 pwd 指令 基本语法 pwd (功能描述:显示当前工作目录的绝对路径) 应用实例 案例:显示当前工作目录的绝对路径 ls指令 基本语法 ls [选项] [目录或是文件] 常用选项 - ...

  8. windows 下创建 sqlite 数据库

    说明:windows 下执行创建 sqlite 数据库命令后数据库文件不会马上生成,需要创建表以后才会生成. 1.将 sqlite3.exe 文件放在任何位置(如放在 d:\tools )2.在 CM ...

  9. Array【数组】和Object【对象】的特性比较

    数组是JavaScript提供的一个内部对象,它是一个标准的集合,我们可以添加(push).删除(shift)里面元素,我们还可以通过for循环遍历里面的元素. 那么除了数组我们在JavaScript ...

  10. 关于DeferredResult的思考

    使用SpringBoot搭建web程序,里面内置了tomcat,一般都不会关心内部实现机制,上来就可以写程序,并且可以跑起来.但是是思考了每次的请求是如何工作的. 简单的来讲就是tomcat是将每次请 ...