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 1
output
  1. Valera
input
  1. 7 6
output
  1. 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块....直到有一方无法送出相应的糖果时结束。

     输出对应的人名。

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

  1. #include <stdio.h>
  2. int main ()
  3. {
  4. int a,b;
  5. while (~scanf("%d%d",&a,&b))
  6. {
  7. for (int i = ;a>=&&b>=; i ++)
  8. {
  9. if (i%) a-= i;
  10. else b -= i;
  11. }
  12. if (a < )
  13. printf("Vladik\n");
  14. else
  15. printf("Valera\n");
  16. }
  17. return ;
  18. }
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
  1. 5 5
    5 4 3 2 1
    1 5 3
    1 3 1
    2 4 3
    4 4 4
    2 5 3
output
  1. Yes
    No
    Yes
    Yes
    No
input
  1. 6 5
    1 4 3 2 5 6
    2 4 3
    1 6 2
    4 5 4
    1 3 3
    2 6 3
output
  1. 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的位置)

  1. #include <stdio.h>
  2. int main ()
  3. {
  4. int n,m,i,l,r,x;
  5. int p[];
  6. while (~scanf("%d%d",&n,&m))
  7. {
  8. for (i = ; i <= n; i ++)
  9. scanf("%d",&p[i]);
  10. while (m --)
  11. {
  12. int sum = ;
  13. scanf("%d%d%d",&l,&r,&x);
  14. for(i = l; i <= r; i ++)
  15. if (p[i] < p[x])
  16. sum ++;
  17. if (x-l == sum)
  18. printf("Yes\n");
  19. else
  20. printf("No\n");
  21. }
  22. }
  23. return ;
  24. }

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. anaconda安装出现failed to create anacoda menue

    1.卸载Anaconda后重新安装Anaconda出现各种问题,粗暴解决方式:直接将安装目录放在C盘主路径下,完美解决. 2.然后无选择忽略,忽略,忽略,提示安装成功,依旧没有 菜单 进入 cmd,找 ...

  2. String字符串补位

    String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的读者应该记得C语言的sprintf()方法,两者有类似之处.format()方法有两种重载形式. l    ...

  3. L2-3 名人堂与代金券 (25 分)

    #include<cstdio> #include<algorithm> #include<cstring> using namespace std; int N, ...

  4. Runas命令巧用

    Runas,从字面上看就知道,以谁的身份去run一个程序,那么他就是在当前登陆的Windows帐号下,以本地或者是域中的其他帐号的身份去运行一个程序.简明语法如下: Runas /user:usern ...

  5. Python用于http/https接口自动化

    本接口自动化框架主要用到的类: 1. unittest:组织测试用例 2. requests:http/https请求 3. HTMLTestRunner:生成测试报告 4. Dingtalkchat ...

  6. 关于cmdbuild

    哪位大神用过cmdbuild,网上的资料非常少,而且都是关于如何安装的,就在这少只又少的文章里,居然还都是互抄的,哎!!!

  7. docker && k8s

    1.docker中网络模式中,有四个: host none bridge container 其中host模式相当于没用,省略了DNAT转换,直接运行在主机. docker network conne ...

  8. 阿里云Centos7上安装MySQL教程

    1 基本安装过程 1.查看系统是否安装了mysql软件 # rpm -qa|grep -i mysql 2.将已经安装过的软件卸载掉.注意:这样的卸载是不彻底,不过这里够用了 # yum remove ...

  9. Spark中自定义累加器Accumulator

    1. 自定义累加器 自定义累加器需要继承AccumulatorParam,实现addInPlace和zero方法. 例1:实现Long类型的累加器 object LongAccumulatorPara ...

  10. KVC、KVO实现过程

    1.KVC的实现过程 以 [object setValue:@"134567" forKey:@"uid"];为例子,来探究KVC的实现过程 第一步:搜索1.首 ...