codeforce 895B XK Segments (结论)
来源:互联网 发布:php开源库存管理系统 编辑:程序博客网 时间:2024/05/22 07:06
the link : http://codeforces.com/contest/895/problem/B
this is a clever question ,witch tell you some N
numbers and k,x and wish you find how many pair of number ai,aj that there are exactly k of them within the range [ai,aj] can be divide evenly by x…
sorry for my terrible English,so here is a conclusion: in the range of [l,r] ,there are r/x - (l-1)/x of numbers that can be divided by x.
then we can sort the array first and for each ai as l, find minimum and maximum r that r/x - (l-1)/x equals to k
#include <bits/stdc++.h>#define ll long longusing namespace std;ll a[100005];int n;ll x,k;int main(){ ios::sync_with_stdio(0); cin>>n>>x>>k; for(int i = 1;i<=n;i++) { cin>>a[i]; //aa[i] = a[i]/x; } ll ans = 0; sort(a+1,a+n+1); //sort(aa+1,aa+n+1); for(int i = 1;i<=n;i++) { ll d = max(a[i], ((a[i]-1)/x + k)*x); ll u = ((a[i]-1)/x +k+1)*x -1; ans += max(0,upper_bound(a+1,a+n+1,u) - lower_bound(a+1,a+n+1,d)); } cout<<ans<<endl; return 0;}
阅读全文
0 0
- codeforce 895B XK Segments (结论)
- codeforce 448 B. XK Segments
- Codeforces-895B XK Segments
- CodeForces 895B XK Segments
- CodeForces 895 B. XK Segments 二分查找
- codeforces 895B XK Segments 思维 二分
- codeforces B. XK Segments
- B. XK Segments(暴力)
- codeforces 895B. XK Segments (二分搜索)
- Codeforces Round #448 (Div. 2) 895B. XK Segments
- #448 div.2 B.XK Segments
- Codeforces Round #448 (Div. 2) B. XK Segments 排序+二分
- Codeforces895B. XK Segments
- XK Segments(二分)
- cfB. XK Segments(二分)
- codeforces895B XK segments
- Codeforces Round #448 (Div. 2)B. XK Segments (双指针 or 二分 )
- CodeForce 652D Nested Segments 树状数组
- 码农的日志12.5
- 从IDC到云端架构迁移之路
- 剑指offer-从尾到头打印链表
- 计算机网络系列(11)之应用场景Virtual Private Networks
- MIT18.06线性代数课程笔记17:正交标准矩阵
- codeforce 895B XK Segments (结论)
- 纯css写出爱心版加载效果,等待加载也是一种享受
- 浅谈Opencv Mat类(常用构造函数和成员函数整理)
- C语言第二讲
- java泛型详解和反射泛型通用BaseDao实现
- 1003. 我要通过!(20)
- ctguoj-取石头 (15分)
- cisco 命令行(静态路由 配置)CCNA
- JSP内置对象(下)