Codeforces Round #371 (Div. 2) A ,B , C 水,水,trie树
1 second
256 megabytes
standard input
standard output
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya.
Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive.
Calculate the number of minutes they will be able to spend together.
The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
1 10 9 20 1
2
1 100 50 200 75
50
In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
题意:两个区间交集,去掉k这个点;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=1e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
int main()
{
ll l1,r1,l2,r2,k;
scanf("%lld%lld%lld%lld%lld",&l1,&r1,&l2,&r2,&k);
ll l=max(l1,l2);
ll r=min(r1,r2);
if(l>r)
printf("0\n");
else if(k>=l&&k<=r)
printf("%lld\n",max(r-l,0LL));
else
printf("%lld\n",max(0LL,r-l+));
return ;
}
1 second
256 megabytes
standard input
standard output
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers a1, a2, ..., an. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the number of integers in the Filya's array. The second line containsn integers a1, a2, ..., an (0 ≤ ai ≤ 109) — elements of the array.
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
5
1 3 3 2 1
YES
5
1 2 3 4 5
NO
In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
题意:找到一个x,将数组中每个数+x,-x,不变使得数组全为一个数;
思路:去重,剩下的数个数大于3肯定no,小于3肯定yes,等于3,判断是否等差;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=1e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
int a[N];
int main()
{
int x;
scanf("%d",&x);
for(int i=;i<x;i++)
scanf("%d",&a[i]);
sort(a,a+x);
int ans=unique(a,a+x)-a;
if(ans>)
printf("NO\n");
else if(ans<)
printf("YES\n");
else
{
sort(a,a+);
if(a[]-a[]==a[]-a[])
printf("YES\n");
else
printf("NO\n");
}
return ;
}
1 second
256 megabytes
standard input
standard output
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
- + ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
- - ai — delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
- ? s — count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
The first line of the input contains an integer t (1 ≤ t ≤ 100 000) — the number of operation Sonya has to perform.
Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci — the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 ≤ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
2
1
2
1
1
4
+ 200
+ 200
- 200
? 0
1
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
- 1 and 241.
- 361.
- 101 and 361.
- 361.
- 4000.
思路:trie数模板题,map应该也可以过;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+;
int a[M][],sum[M],len;
void init()
{
memset(a,,sizeof(a));
memset(sum,,sizeof(sum));
len=;
}
void insertt(ll x)
{
int num[];
memset(num,,sizeof(num));
int flag=;
while(x)
{
num[flag++]=x%;
x/=;
}
int u=,n=;
for(int i=n; i>=; i--)
{
if(!a[u][num[i]])
{
a[u][num[i]]=len++;
}
u=a[u][num[i]];
sum[u]++;
}
}
void del(ll x)
{
int num[];
memset(num,,sizeof(num));
int flag=;
while(x)
{
num[flag++]=x%;
x/=;
}
int u=,n=;
for(int i=n; i>=; i--)
{
int v=a[u][num[i]];
sum[v]--;
if(!sum[v])
a[u][num[i]]=;
u=v;
}
}
char gg[];
int getans(ll x)
{
scanf("%s",&gg);
int num[];
memset(num,,sizeof(num));
int flag=;
for(int i=strlen(gg)-;i>=;i--)
num[flag++]=gg[i]-'';
int u=,n=,v,w;
int ans=;
for(int i=n; i>=; i--)
{
if(!a[u][num[i]])
return ;
u=a[u][num[i]];
}
return sum[u];
}
char ch[];
int main()
{
int T,cas;
ll x;
init();
scanf("%d",&T);
for(cas=; cas<=T; cas++)
{
scanf("%s%",ch);
if(ch[]=='+')
{
scanf("%lld",&x);
insertt(x);
}
else if(ch[]=='-')
{
scanf("%lld",&x);
del(x);
}
else
{
printf("%d\n",getans(x));
} }
return ;
}
Codeforces Round #371 (Div. 2) A ,B , C 水,水,trie树的更多相关文章
- Codeforces Round #371 (Div. 2) C. Sonya and Queries 水题
C. Sonya and Queries 题目连接: http://codeforces.com/contest/714/problem/C Description Today Sonya learn ...
- Codeforces Round #371 (Div. 2) B. Filya and Homework 水题
B. Filya and Homework 题目连接: http://codeforces.com/contest/714/problem/B Description Today, hedgehog ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #371 (Div. 2) C 大模拟
http://codeforces.com/contest/714/problem/C 题目大意:有t个询问,每个询问有三种操作 ①加入一个数值为a[i]的数字 ②消除一个数值为a[i]的数字 ③给一 ...
- Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集
A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...
- Codeforces Round #371 (Div. 2)B. Filya and Homework
题目链接:http://codeforces.com/problemset/problem/714/B 题目大意: 第一行输入一个n,第二行输入n个数,求是否能找出一个数x,使得n个数中的部分数加上x ...
- Codeforces Round #371 (Div. 2) - B
题目链接:http://codeforces.com/contest/714/problem/B 题意:给定一个长度为N的初始序列,然后问是否能找到一个值x,然后使得序列的每个元素+x/-x/不变,最 ...
- Codeforces Round #371 (Div. 2) - A
题目链接:http://codeforces.com/contest/714/problem/A 题意:有两个人A,B 给定A的时间区间[L1,R1], B的时间区间[L2,R2],然后在正好K分钟的 ...
- 严格递增类的dp Codeforces Round #371 (Div. 1) C dp
http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...
随机推荐
- Apple 企业开发者账号申请记录
1.账号分类 Apple开发者账号分三种,个人,公司,还有企业.个人和公司都称为标准账号. 还有一种是教育机构的账号. 记录:申请日期2013年4月26,看申请周期多长. 个人和公司的就不说了,现在只 ...
- (三)Solrj4到Solrj5的升级之路
(三)Solrj4到Solrj5的升级之路 Solr5发布了,带来了许多激动人心的新特性,但Solrj的许多接口也发生了变化,升级是痛苦的,但也是必须的,下面就赶紧来看看有哪些代码需要升级吧. 变化1 ...
- MongoDB实践-自定义ASP.NET Session Store
Session由来 由于HTTP协议是无状态的,客户端与服务器端进行“请求-响应”操作后,建立的连接就释放了,服务器端根本不知道刚才是哪个客户端访问的.但是有些场景是需要知道客户端的状态的,最典型的就 ...
- nginx1.4.7+uwsgi+django1.9.2项目部署,liunx系统为ubuntu14.0.4。
本文基于root用户下进行部署,django项目名称为BDFS 1. 安装依赖包,终端输入命令 1) 环境依赖包 apt-get update apt-get install pyt ...
- React-学习总结
概念知识:1.JSX是什么 JSX其实是JavaScript的扩展,React为了代码的可读性更方便地创建虚拟DOM等原因,加入了一些类似XML的语法的扩展. 2.编译器——jsxTransforme ...
- 【22,23节】Django的GET和POST属性笔记
COOKIES:一个标准的python字典对象,包含所有cookies,键和值都为字符串session:一个即能读又能写的类似字典对象,表示当前的会话,只有当django启用会话的支持时才可用 一键多 ...
- Docker容器/镜像查看及删除操作
列出所有正在运行的容器 docker ps 暂停容器 docker stop <name> 删除容器 docker rm <name> 停止所有container docker ...
- 斯坦福大学Andrew Ng - 机器学习笔记(6) -- 聚类 & 降维
大概用了一个月,Andrew Ng老师的机器学习视频断断续续看完了,以下是个人学习笔记,入门级别,权当总结.笔记难免有遗漏和误解,欢迎讨论. 鸣谢:中国海洋大学黄海广博士提供课程视频和个人笔记,在此深 ...
- Js中localStorage
优点: 1.拓展了cookie的4K限制 2.将数据直接存储到本地,相当于一个5M的前端页面数据库 不足: 1.浏览器的大小不统一 2.IE8以上的IE版本才支持 3.localStorage的值类型 ...
- Linux下环境变量配置错误 导致大部分命令不可以使用的解决办法
直接解决方法:在命令行中输入:export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin 后 Enter