A. Vladik and Courtesy
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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, they don’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.

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

Illustration for first test case:

Illustration for second test case:

两个人的糖果数分别-1-3-5-7,-2-4-6-8,看谁更持久,等差数列求和啊,因为数据量不大,所以直接模拟也是可以过的

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll a, b, n, m;
cin >> a >> b;
n = sqrt(a);
m = (-1.0+sqrt(+*b))/2.0;
if (n > m){
cout << "Valera";
}
else cout << "Vladik";
return ;
}
B. Vladik and Complicated Book
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
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".
题意:给出一串数,然后有m个问题,每个问题给出一个区间 【l,r】对区间内的数进行排序,问第x个数的位置是否改变。

群里有大佬用了线数段的做法,可是div2怎么会那么难啊,统计下<=a[x]的不久好了

#include <bits/stdc++.h>
using namespace std;
const int maxn=+;
int n,m;
int p[maxn];
int main()
{
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++)
scanf("%d",&p[i]);
int l,r,x;
for(int i=;i<m;i++){
scanf("%d %d %d",&l,&r,&x);
int hh=p[x];
int cnt=;
for(int j=l;j<=r;j++){
if(j==x)
continue;
if(p[j]<hh)
cnt++;
}
if(cnt+l-==x)
printf("Yes\n");
else printf("No\n");
}
return ;
}
C. Vladik and Memorable Trip
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 lined up in some order, and for each of them the city code ai is known (the code of the city in which they are going to).

Train chief selects some number of disjoint segments of the original sequence of people (covering entire sequence by segments is not necessary). People who are in the same segment will be in the same train carriage. The segments are selected in such way that if at least one person travels to the city x, then all people who are going to city x should be in the same railway carriage. This means that they can’t belong to different segments. Note, that all people who travel to the city x, either go to it and in the same railway carriage, or do not go anywhere at all.

Comfort of a train trip with people on segment from position l to position r is equal to XOR of all distinct codes of cities for people on the segment from position l to position r. XOR operation also known as exclusive OR.

Total comfort of a train trip is equal to sum of comfort for each segment.

Help Vladik to know maximal possible total comfort.

Input

First line contains single integer n (1 ≤ n ≤ 5000) — number of people.

Second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 5000), where ai denotes code of the city to which i-th person is going.

Output

The output should contain a single integer — maximal possible total comfort.

Examples
input
6
4 4 2 5 2 3
output
14
input
9
5 1 3 1 5 2 4 2 5
output
9
Note

In the first test case best partition into segments is: [4, 4] [2, 5, 2] [3], answer is calculated as follows: 4 + (2 xor5) + 3 = 4 + 7 + 3 = 14

In the second test case best partition into segments is: 5 1 [3] 1 5 [2, 4, 2] 5, answer calculated as follows: 3 + (2 xor 4) = 3 + 6 = 9.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mem(s,v) memset(s,v,sizeof(s))
#define inf 0x3f3f3f3f
int a[],fi[],se[],dp[],vis[5010];
int main(){
int n;
scanf("%d",&n);
mem(a,);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(!fi[a[i]]) fi[a[i]]=i;
se[a[i]]=i;
}
for(int i=;i<=n;i++){
dp[i]=dp[i-];
mem(vis,);
int st=i,res=;
for(int j=i;j;j--){
if(!vis[a[j]]){
if(se[a[j]]>i) break;
if(fi[a[j]]<st) st=fi[a[j]];
res^=a[j];vis[a[j]]=;
}
if(j<=st) dp[i]=max(dp[i],dp[j-]+res);
}
}
printf("%d\n",dp[n]);
return ;
}
 

Codeforces Round #416 (Div. 2) 本来以为这个时间是晚上的,下午就没做的更多相关文章

  1. Codeforces Round#416 Div.2

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

  2. 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 ...

  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) A+B

    A. Vladik and Courtesy 2 seconds 256 megabytes   At regular competition Vladik and Valera won a and  ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

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

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

随机推荐

  1. datagrid数据网格获取所有选中行的索引,插入某个列值为其他列的运算值

    获取所有选中行的索引,存入数组ary中: var data=$("#dg").datagrid("getSelections"); var ary=[]; fo ...

  2. 【R语言进行数据挖掘】回归分析

    1.线性回归 线性回归就是使用下面的预测函数预测未来观测量: 其中,x1,x2,...,xk都是预测变量(影响预测的因素),y是需要预测的目标变量(被预测变量). 线性回归模型的数据来源于澳大利亚的C ...

  3. C++拾遗(三)——函数

    函数的定义 C++是一种静态强类型语言,对于每一次的函数调用,编译时都会检查其实参,必须与形参类型相同,或可被转换为该类型. 参数传递 普通的非引用类型的参数通过复制对应的实参实现初始化.引用形参直接 ...

  4. LR中下载文件的脚本

    #include "web_api.h" Action(){ int iflen; //文件大小 long lfbody; //响应数据内容大小 web_url("xxx ...

  5. Flask信号流程

    首先先我们来看看Flask里面的信号是什么样的,我们可以找到一个叫signals.py的文件 这里面是所有定义了的后面请求流程中会用到的信号 二.哪些地方用到了信号 1.请求app上下文时执行的,在执 ...

  6. 51nod 1526 分配笔名

    题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 320 难度:7级算法题. 班里有n个同学.老师为他们选了n个笔名.现在要把这些笔名分配给每一个同学,每一 ...

  7. 洛谷 P2910 [USACO08OPEN]寻宝之路Clear And Present Danger

    题目描述 Farmer John is on a boat seeking fabled treasure on one of the N (1 <= N <= 100) islands ...

  8. (十)maven之排除冲突jar包

    排除冲突jar包 jar包冲突 <dependencies> <dependency> <groupId>org.springframework</group ...

  9. win7上安装虚拟机并上网

    一.安装Workstation Pro 二.下载CentOS-7-x86_64-DVD-1511.iso包 三.创建新的虚拟机,按照向导安装即可 四.使用cd /etc/sysconfig/netwo ...

  10. 在Terminal中,如何打开Finder,并显示当前的目录

    这是一个非常方便实用的小技巧,在Terminal中输入如下命令: $ open . 有图有真相: 参考: Open Finder in Current Folder from Terminal