题目链接:http://codeforces.com/contest/597

A. Divisibility
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.

Input

The only line contains three space-separated integers ka and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).

Output

Print the required number.

Examples
input
  1. 1 1 10
output
  1. 10
input
  1. 2 -4 4
output
  1. 5

题意:找出[a,b]区间内整除k的数的个数;

思路:小心点特判即可;

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cmath>
  5. #include<string>
  6. #include<queue>
  7. #include<algorithm>
  8. #include<stack>
  9. #include<cstring>
  10. #include<vector>
  11. #include<list>
  12. #include<set>
  13. #include<map>
  14. using namespace std;
  15. #define ll long long
  16. #define pi (4*atan(1.0))
  17. #define eps 1e-14
  18. #define bug(x) cout<<"bug"<<x<<endl;
  19. const int N=1e5+,M=4e6+,inf=;
  20. const ll INF=1e18+,mod=1e9+;
  21. /// 数组大小
  22. int main()
  23. {
  24. ll k,a,b;
  25. scanf("%lld%lld%lld",&k,&a,&b);
  26. if(a<=&&b>=)
  27. printf("%lld\n",(b/k)-(a/k)+);
  28. else if(a>=&&b>=)
  29. printf("%lld\n",(b/k)-(a/k+(a%k?:))+);
  30. else
  31. printf("%lld\n",(abs(a)/k)-(abs(b)/k+(abs(b)%k?:))+);
  32. return ;
  33. }
B. Restaurant
time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order is characterized by two time values — the start time li and the finish time ri (li ≤ ri).

Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept?

No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both.

Input

The first line contains integer number n (1 ≤ n ≤ 5·105) — number of orders. The following n lines contain integer values li and ri each (1 ≤ li ≤ ri ≤ 109).

Output

Print the maximal number of orders that can be accepted.

Examples
input
  1. 2
    7 11
    4 7
output
  1. 1
input
  1. 5
    1 2
    2 3
    3 4
    4 5
    5 6
output
  1. 3
input
  1. 6
    4 8
    1 5
    4 7
    2 5
    1 3
    6 8
output
  1. 2

贪心:按r从小到大排序即可;

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cmath>
  5. #include<string>
  6. #include<queue>
  7. #include<algorithm>
  8. #include<stack>
  9. #include<cstring>
  10. #include<vector>
  11. #include<list>
  12. #include<set>
  13. #include<map>
  14. using namespace std;
  15. #define ll long long
  16. #define pi (4*atan(1.0))
  17. #define eps 1e-14
  18. #define bug(x) cout<<"bug"<<x<<endl;
  19. const int N=5e5+,M=4e6+,inf=;
  20. const ll INF=1e18+,mod=1e9+;
  21. struct is
  22. {
  23. int l,r;
  24. bool operator <(const is &c)const
  25. {
  26. return r<c.r;
  27. }
  28. }a[N];
  29.  
  30. /// 数组大小
  31.  
  32. int main()
  33. {
  34. int n;
  35. scanf("%d",&n);
  36. for(int i=;i<=n;i++)
  37. scanf("%d%d",&a[i].l,&a[i].r);
  38. sort(a+,a++n);
  39. int s=,ans=;
  40. for(int i=;i<=n;i++)
  41. {
  42. if(a[i].l>s)
  43. {
  44. ans++;
  45. s=a[i].r;
  46. }
  47. }
  48. printf("%d\n",ans);
  49. return ;
  50. }
C. Subsequences
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.

Input

First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) — the length of sequence and the number of elements in increasing subsequences.

Next n lines contains one integer ai (1 ≤ ai ≤ n) each — elements of sequence. All values ai are different.

Output

Print one integer — the answer to the problem.

Examples
input
  1. 5 2
    1
    2
    3
    5
    4
output
  1. 7

题意:给你n个数,最长上升子序列长度为k+1的个数;

思路:看下数据范围k<10很关键,dp[i][j]表示以i为结束长度为j时候的方案数

   现在你到i的时候你只需要再T[j](树状数组)的a[i]的位置表示方案数;

   统计小于a[i]的方案,k==0时候特判;

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cmath>
  5. #include<string>
  6. #include<queue>
  7. #include<algorithm>
  8. #include<stack>
  9. #include<cstring>
  10. #include<vector>
  11. #include<list>
  12. #include<set>
  13. #include<map>
  14. using namespace std;
  15. #define ll long long
  16. #define pi (4*atan(1.0))
  17. #define eps 1e-14
  18. #define bug(x) cout<<"bug"<<x<<endl;
  19. const int N=1e5+,M=4e6+,inf=;
  20. const ll INF=1e18+,mod=1e9+;
  21. struct AYT
  22. {
  23. ll tree[N];
  24. int lowbit(int x)
  25. {
  26. return x&-x;
  27. }
  28. void update(int x,ll c)
  29. {
  30. while(x<N)
  31. {
  32. tree[x]+=c;
  33. x+=lowbit(x);
  34. }
  35. }
  36. ll query(int x)
  37. {
  38. ll ans=;
  39. while(x)
  40. {
  41. ans+=tree[x];
  42. x-=lowbit(x);
  43. }
  44. return ans;
  45. }
  46. };
  47. AYT T[];
  48.  
  49. /// 数组大小
  50. int a[N];
  51. int main()
  52. {
  53. int n,k;
  54. scanf("%d%d",&n,&k);
  55. for(int i=;i<=n;i++)
  56. scanf("%d",&a[i]);
  57. if(k==)
  58. return *printf("%d\n",n);
  59. ll ans=;
  60. for(int i=;i<=n;i++)
  61. {
  62. ans+=T[k].query(a[i]-);
  63. for(int j=k;j>=;j--)
  64. {
  65. ll x=T[j-].query(a[i]-);
  66. T[j].update(a[i],x);
  67. }
  68. T[].update(a[i],);
  69. }
  70. printf("%lld\n",ans);
  71. return ;
  72. }
A. Divisibility
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.

Input

The only line contains three space-separated integers ka and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).

Output

Print the required number.

Examples
input
  1. 1 1 10
output
  1. 10
input
  1. 2 -4 4
output
  1. 5

Testing Round #12 A,B,C 讨论,贪心,树状数组优化dp的更多相关文章

  1. Codeforces Beta Round #12 (Div 2 Only) D. Ball 树状数组查询后缀、最值

    http://codeforces.com/problemset/problem/12/D 这里的BIT查询,指的是查询[1, R]或者[R, maxn]之间的最值,这样就够用了. 设三个权值分别是b ...

  2. Codeforces Round #333 (Div. 1) C. Kleofáš and the n-thlon 树状数组优化dp

    C. Kleofáš and the n-thlon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  3. 【bzoj4240】有趣的家庭菜园 贪心+树状数组

    题目描述 对家庭菜园有兴趣的JOI君每年在自家的田地中种植一种叫做IOI草的植物.JOI君的田地沿东西方向被划分为N个区域,由西到东标号为1~N.IOI草一共有N株,每个区域种植着一株.在第i个区域种 ...

  4. 贪心+树状数组维护一下 Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) D

    http://codeforces.com/contest/724/problem/D 题目大意:给你一个串,从串中挑选字符,挑选是有条件的,按照这个条件所挑选出来的字符集合sort一定是最后选择当中 ...

  5. [JZO6401]:Time(贪心+树状数组)

    题目描述 小$A$现在有一个长度为$n$的序列$\{x_i\}$,但是小$A$认为这个序列不够优美. 小$A$认为一个序列是优美的,当且仅当存在$k\in [1,n]$,满足:$$x_1\leqsla ...

  6. D 洛谷 P3602 Koishi Loves Segments [贪心 树状数组+堆]

    题目描述 Koishi喜欢线段. 她的条线段都能表示成数轴上的某个闭区间.Koishi喜欢在把所有线段都放在数轴上,然后数出某些点被多少线段覆盖了. Flandre看她和线段玩得很起开心,就抛给她一个 ...

  7. [BZOJ4240]有趣的家庭菜园(贪心+树状数组)

    最后数列一定是单峰的,问题就是最小化最后的位置序列的逆序对数. 从大到小加数,每次贪心看放左边和右边哪个产生的逆序对数更少,树状数组即可. 由于大数放哪对小数不产生影响,所以正确性显然. 注意相同数之 ...

  8. [P4064][JXOI2017]加法(贪心+树状数组+堆)

    题目描述 可怜有一个长度为 n 的正整数序列 A,但是她觉得 A 中的数字太小了,这让她很不开心. 于是她选择了 m 个区间 [li, ri] 和两个正整数 a, k.她打算从这 m 个区间里选出恰好 ...

  9. [luoguP2672] 推销员(贪心 + 树状数组 + 优先队列)

    传送门 贪心...蒟蒻证明不会... 每一次找最大的即可,找出一次最大的,数列会分为左右两边,左边用stl优先队列维护,右边用树状数组维护.. (线段树超时了....) 代码 #include < ...

随机推荐

  1. 实习培训——Java基础(3)

    实习培训——Java基础(3) 1 Java 继承 1.1  super和this关键字 super关键字:我们可以通过super关键字来实现对父类成员的访问,用来引用当前对象的父类. this关键字 ...

  2. hdu2159FATE(二维背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=2159 Problem Description 最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在 ...

  3. CNN实现垃圾邮件分类(行大小不一致要补全)

    以下是利用卷积神经网络对某一个句子的处理结构图 我们从上图可知,将一句话转化成一个矩阵.我们看到该句话有6个单词和一个标点符号,所以我们可以将该矩阵设置为7行,对于列的话每个单词可以用什么样的数值表示 ...

  4. 初次使用git上传代码(转)

    转自 http://www.cnblogs.com/cxk1995/p/5800196.html 首先你需要一个github账号,所有还没有的话先去注册吧! https://github.com/ 我 ...

  5. mysql导入数据方法和报错解决

    mysql -u root -p databasename < db.sql 数据库导入数据时,MySQL收到下面异常:ERROR 1153 (08S01): Got a packet bigg ...

  6. UVM中factory机制的使用

    UVM中的factory机制一般用在sequence的重载,尤其是virtual sequence.当Test_case变化时,通过virtual sequence的重载,可以很容易构建新的测试. 因 ...

  7. 去n的第一个出现的1

    实例十八:去n的第一个出现的1 方法:result=n & (n-1) 与实例十七 思路类似.实例十七是不断取1,本例只去最低位. 解释:n 0000 1111n-1 0000 1110&am ...

  8. uva10905

    /* 很好的字符串 比较方法 很多个字符串 组成的 数字 需要最大 然后 比较 a和b 是 比较a+b 和b+a 的大小 */ #include<cstdio> #include<s ...

  9. Oracle性能优化之HINT的用法

    1. /*+ALL_ROWS*/ 表明对语句块选择基于开销的优化方法,并获得最佳吞吐量,使资源消耗最小化. 例如: SELECT /*+ALL+_ROWS*/ EMP_NO,EMP_NAM,DAT_I ...

  10. 谷歌插件--Advanced REST client

    早上在测试调用服务去获取数据的时候,因为自己的单元测试不是很熟悉,问了同事,同事给我介绍了一个插件Advanced REST client,这个可以在谷歌的“扩展与应用”中找打,使用 安装之后会提示要 ...