A. Meeting of Old Friends
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print one integer — the number of minutes Sonya and Filya will be able to spend together.

Examples
input
1 10 9 20 1
output
2
input
1 100 50 200 75
output
50
Note

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 ;
}
B. Filya and Homework
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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

Examples
input
5
1 3 3 2 1
output
YES
input
5
1 2 3 4 5
output
NO
Note

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 ;
}
C. Sonya and Queries
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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:

  1.  +  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.
  2.  -  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.
  3. 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.

Input

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.

Output

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.

Examples
input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
output
2
1
2
1
1
input
4
+ 200
+ 200
- 200
? 0
output
1
Note

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. 1 and 241.
  2. 361.
  3. 101 and 361.
  4. 361.
  5. 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树的更多相关文章

  1. Codeforces Round #371 (Div. 2) C. Sonya and Queries 水题

    C. Sonya and Queries 题目连接: http://codeforces.com/contest/714/problem/C Description Today Sonya learn ...

  2. Codeforces Round #371 (Div. 2) B. Filya and Homework 水题

    B. Filya and Homework 题目连接: http://codeforces.com/contest/714/problem/B Description Today, hedgehog ...

  3. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

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

  5. Codeforces Round #371 (Div. 2) C 大模拟

    http://codeforces.com/contest/714/problem/C 题目大意:有t个询问,每个询问有三种操作 ①加入一个数值为a[i]的数字 ②消除一个数值为a[i]的数字 ③给一 ...

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

  7. Codeforces Round #371 (Div. 2)B. Filya and Homework

    题目链接:http://codeforces.com/problemset/problem/714/B 题目大意: 第一行输入一个n,第二行输入n个数,求是否能找出一个数x,使得n个数中的部分数加上x ...

  8. Codeforces Round #371 (Div. 2) - B

    题目链接:http://codeforces.com/contest/714/problem/B 题意:给定一个长度为N的初始序列,然后问是否能找到一个值x,然后使得序列的每个元素+x/-x/不变,最 ...

  9. Codeforces Round #371 (Div. 2) - A

    题目链接:http://codeforces.com/contest/714/problem/A 题意:有两个人A,B 给定A的时间区间[L1,R1], B的时间区间[L2,R2],然后在正好K分钟的 ...

  10. 严格递增类的dp Codeforces Round #371 (Div. 1) C dp

    http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...

随机推荐

  1. 《从零开始学Swift》学习笔记http(Day1)——我的第一行Swift代码

    Swift 2.0学习笔记(Day1)——我的第一行Swift代码 原创文章,欢迎转载.转载请注明:关东升的博客 当第一次看到下面代码时我石化了,这些代码是什么东东?单词拼出来的? import Fo ...

  2. 爬虫入门【8】Python连接MongoDB的用法简介

    MongoDB的连接和数据存取 MongoDB是一种跨平台,面向文档的NoSQL数据库,提供高性能,高可用性并且易于扩展. 包含数据库,集合,文档等几个重要概念. 我们在这里不介绍MongoDB的特点 ...

  3. node.js 关于跨域和传递给前台参数

    /*为app添加中间件处理跨域请求*/ app.use(function(req, res, next) { res.header("Access-Control-Allow-Origin& ...

  4. POJ 1039 Pipe【经典线段与直线相交】

    链接: http://poj.org/problem?id=1039 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  5. Nginx 启动、停止、平滑重启和平滑升级 graceful shutdown of worker processes

    Controlling nginx http://nginx.org/en/docs/control.html nginx can be controlled with signals. The pr ...

  6. 任务05—学习 MARKDOWN 语言

    我的简历地址: https://github.com/jinxiaohang/MyResume/blob/master/ForJavaJob.md 本任务主要目的掌握markdown. 1.首先是工具 ...

  7. MySql 安装常见问题汇总

    说明: 以下是针对 Mac 10.11 系统 以前,安装 MySql 数据库后, 设置的密码过于复杂,想更改为简单的密码, 方便数据库的使用. 1. 关闭和启动 MySql 数据库的方法: Syste ...

  8. Android系统移植与调试之------->build.prop生成过程分析

    本文简要分析一下build.prop是如何生成的.Android的build.prop文件是在Android编译时刻收集的各种property(LCD density/语言/编译时间, etc.),编 ...

  9. (4.12)全面解析-SQL事务+隔离级别+阻塞+死锁

    30分钟全面解析-SQL事务+隔离级别+阻塞+死锁 转自:https://blog.csdn.net/slowlifes/article/details/52752735 2016年10月07日 23 ...

  10. qemu-img 的使用

    qemu-img是QEMU的磁盘管理工具,在qemu-kvm源码编译后就会默认编译好qemu-img这个二进制文件.qemu-img也是QEMU/KVM使用过程中一个比较重要的工具,本节对其用法和实践 ...