Codeforces Round #416 (Div. 2) A+B

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

     输出对应的人名。

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

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

5 55 4 3 2 11 5 31 3 12 4 34 4 42 5 3

output

YesNoYesYesNo

input

6 51 4 3 2 5 62 4 31 6 24 5 41 3 32 6 3

output

YesNoYesNoYes

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[10010];
 6     while (~scanf("%d%d",&n,&m))
 7     {
 8         for (i = 1; i <= n; i ++)
 9             scanf("%d",&p[i]);
10         while (m --)
11         {
12             int sum = 0;
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 0;
24 }
时间: 2024-10-13 16:24:19

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

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

题目链接:Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip 题意: 给你n个数,现在让你选一些区间出来,对于每个区间中的每一种数,全部都要出现在这个区间. 每个区间的价值为该区间不同的数的异或值,现在问你这n个数最大的价值是多少. 题解: 比赛的时间直接就想到了做法,不过在选取合法区间的时候,细节上出了点小问题. 然后一直wa到怀疑人生.太菜了. 首先,先将合法的区间选取出来. 对于这些区间,按照左端点排序, 然后对于选出来的

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

题目链接: http://codeforces.com/problemset/problem/811/D 题目描述: D. Vladik and Favorite Game This is an interactive problem. Vladik has favorite game, in which he plays all his free time. Game field could be represented as n?×?m matrix which consists of ce

(线段树+并查集) Codeforces Round #416 (Div. 2) E Vladik and Entertaining Flags

In his spare time Vladik estimates beauty of the flags. Every flag could be represented as the matrix n?×?m which consists of positive integers. Let's define the beauty of the flag as number of components in its matrix. We call component a set of cel

Codeforces Round #416 (Div. 2)

B 前几天听cwy说O(m*n)被卡常,比赛时犹豫了好久才写,然后就A了,STL的常数很牛逼 大概2种方法:根据下标位置判断这个数值是否改变(找k-th min): 根据值来确定其下标,判断下标是否改变(找这个数是第几小,常数小) C n^2 dp,当时加了一些mark,实际上由于0?≤?ai?≤?5000,完全可以每次dp memset一波 D 交互题. 比赛时因为有一个for把3写成4,导致内存溢出,调了1个多小时都没有发现,还是太粗心(不过即使如此好像rank还是挺前面的..) 真可惜呀,

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

划分那个序列,没必要完全覆盖原序列.对于划分出来的每个序列,对于某个值v,要么全都在该序列,要么全都不在该序列. 一个序列的价值是所有不同的值的异或和.整个的价值是所有划分出来的序列的价值之和. 求整个的价值的最大值 f(i)表示最后一个划分序列的右端点为i时,1~i的答案. f(i)=max{max{f(j)}(1<=j<i)+xorsum(j+1,i)(j+1到i的区间合法)}(1<=i<=n) 需要在转移的时候,顺便处理f(i)的前缀max. 最终的答案就是所有f(i)的最大

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

那个人第一步肯定要么能向下走,要么能向右走.于是一定可以判断出上下是否对调,或者左右是否对调. 然后他往这个方向再走一走就能发现一定可以再往旁边走,此时就可以判断出另一个方向是否对调. 都判断出来以后,跑个spfa或者bfs就行了. 细节较多--有一些边界情况需要处理.比如终点在第一行或者第一列的情况. #include<cstdio> #include<queue> #include<cstring> #include<algorithm> using n

(dp) Codeforces Round #416 (Div. 2)

Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips: Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are already

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i