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

时间:2022-09-26 09:08:45
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 a, b (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:

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

Illustration for second test case:

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

题意:给你两个数 a,b   按照 1 2 3 4 ...i   a b轮流减少相应的i值  若a先减少到0 输出Vladik 反之输出Valera

题解:水

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#define ll __int64
using namespace std;
int main()
{
int a,b;
scanf("%d %d",&a,&b);
int s=,d=;
s=sqrt(a);
for(int i=sqrt(b);;i--)
{
if(i*(i+)<=b)
{
d=i;
break;
}
}
// cout<<s<<" "<<d<<endl;
if(s<=d)
printf("Vladik\n");
else
printf("Valera\n");
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 n, m (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 li, ri, xi (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".

题意:给你一个长度为n的序列p   m个查询  将[l,r] 升序排列 判断px是否改变 如果没有改变输出Yes 否则输出No

题解:遍历判断当前区间 小于px的数的数量;

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#define ll __int64
using namespace std;
int n,m;
int a[];
int main(){
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
int l,r,x;
for(int i=;i<=m;i++){
scanf("%d %d %d",&l,&r,&x);
int jishu=;
for(int j=l;j<=r;j++)
{
if(a[j]<=a[x])
jishu++;
}
if(jishu==(x-l+))
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 xor 5) + 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.

题意:给出n,然后n个数,要你选择一些不相交的区间,使得这些区间中出现的数字的异或的和最大,区间有这样的限制,对于区间的任何数,其余相同的数都要在这个区间,否者这个区间就是不合法的。

题解:求出每个数出现的最左端和最右端,定义dp[i]为1到i这个区间所能选出的最大值,然后枚举右端点,找合法的左端点即可

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#define ll __int64
using namespace std;
int n;
ll a[];
int l[],r[];
ll we[][];
ll dp[];
int mp[];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
l[a[i]]=n;
r[a[i]]=;
}
for(int i=;i<=n;i++){
l[a[i]]=min(l[a[i]],i);
r[a[i]]=max(r[a[i]],i);
}
for(int i=;i<=n;i++){
memset(mp,,sizeof(mp));
we[i][i]=a[i];
mp[a[i]]=;
int sum=a[i];
for(int j=i+;j<=n;j++){
if(mp[a[j]]==){
sum=sum^a[j];
mp[a[j]]=;
}
we[i][j]=sum;
}
}
dp[]=;
for(int i=;i<=n;i++){
if(r[a[i]]==i){
int L=l[a[i]];
int what=;
for(int j=l[a[i]]+;j<r[a[i]];j++){
if(r[a[j]]>i){
what=;
break;
}
L=min(L,l[a[j]]);
}
if(what==)
dp[i]=max(dp[i-],dp[L-]+we[L][i]);
else
dp[i]=dp[i-];
}
else
dp[i]=dp[i-];
}
printf("%I64d\n",dp[n]);
return ;
}

Codeforces Round #416 (Div. 2)A B C 水 暴力 dp的更多相关文章

  1. Codeforces Round &num;416 &lpar;Div&period; 2&rpar;&lpar;A&comma;思维题,暴力,B&comma;思维题,暴力&rpar;

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

  2. Codeforces Round &num;127 &lpar;Div&period; 1&rpar; D&period; Brand New Problem 暴力dp

    D. Brand New Problem 题目连接: http://www.codeforces.com/contest/201/problem/D Description A widely know ...

  3. Codeforces Round &num;372 &lpar;Div&period; 2&rpar; A B C 水 暴力&sol;模拟 构造

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. Codeforces Round &num;407 &lpar;Div&period; 2&rpar;A B C 水 暴力 最大子序列和

    A. Anastasia and pebbles time limit per test 1 second memory limit per test 256 megabytes input stan ...

  5. Codeforces Round &num;401 &lpar;Div&period; 2&rpar; A B C 水 贪心 dp

    A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...

  6. Codeforces Round &num;367 &lpar;Div&period; 2&rpar; A&period; Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  7. Codeforces Round &num;297 &lpar;Div&period; 2&rpar;D&period; Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

  8. Codeforces Round &num;267 &lpar;Div&period; 2&rpar; C&period; George and Job(DP)补题

    Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...

  9. Codeforces Round &num;603 &lpar;Div&period; 2&rpar; A&period; Sweet Problem&lpar;水&period;&period;&period;&period;&period;&period;&period;没做出来&rpar;&plus;C题

    Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...

随机推荐

  1. ATS连接 https

    HTTPS协议是Http Over SSL,简单来说就是HTTP的安全版本,在HTTP的基础上增加SSL/TLS加密传输协议,通过HTTPS加密传输和身份认证保证了传输过程的安全性.在登录网银和电子邮 ...

  2. PHP中使用Luhn算法校验信用卡及借记卡卡号

    Luhn算法会通过校验码对一串数字进行验证,校验码通常会被加到这串数字的末尾处,从而得到一个完整的身份识别码. 我们以数字“7992739871”为例,计算其校验位: 从校验位开始,从右往左,偶数位乘 ...

  3. Android自定义下拉刷新

    网上的下拉刷新功能很多,不过基本上都是隐藏header的,而项目里面需要只隐藏部分的header,类似QQ好友动态的效果,修改了一些现有的,最后有很多问题,所以就自己自定义了一个,逻辑也很简单,首先就 ...

  4. CreateThread函数

    当使用CreateProcess调用时,系统将创建一个进程和一个主线程. CreateThread将在主线程的基础上创建一个新线程,大致做例如以下步骤: 1在内核对象中分配一个线程标识/句柄,可供管理 ...

  5. Android学习----Android架构

    android分为四个层,从高层到低层分别是应用程序层.应用程序框架层.系统运行库层和linux核心层.蓝色的代表java程序,黄色的代码为运行JAVA程序而实现的虚拟机,绿色部分为C/C++语言编写 ...

  6. TensorFlow练习13&colon; 制作一个简单的聊天机器人

    现在很多卖货公司都使用聊天机器人充当客服人员,许多科技巨头也纷纷推出各自的聊天助手,如苹果Siri.Google Now.Amazon Alexa.微软小冰等等.前不久有一个视频比较了Google N ...

  7. 自动加载以及Composer的实现

    类的自动加载 两个函数 __autoload()魔术方法.spl_autoload_register 当php文件中使用了new关键字实例化一个对象时,如果该类没有在本php文件中被定义,将会触发__ ...

  8. Xshell无法使用root远程登录Ubuntu16服务器

    修改/etc/ssh/sshd_config文件,把PermitRootLogin Prohibit-password 添加#注释掉 新添加:PermitRootLogin yes 2. 重启ssh服 ...

  9. java基础解疑!!!

    疑问一:0.01+0.09的结果? public class MathTest{ public static void main(String[]args){ double a = 0.01, b = ...

  10. WampServer访问出现403forbidden的问题解决

    1,软件装上以后出现所有服务运行,80端口未被占用的情况下服务器一直处于离线状态 解决方案如下: 网络上面很多教程多说切换服务器为在线状态即可,但是我发现我的菜单里面并没有,用命令又嫌麻烦 在图表上面 ...