hdu5178 尺取
会爆int
/*
给定数轴上一些点对,问有多少点对之间的距离差不超过k
点对排序后尺取法:枚举每个左边界,找到一个右边界使得
*/
#include<bits/stdc++.h>
#define maxn 100005
using namespace std; int n,k,sum,l,r,x[maxn];
long long ans;
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++) scanf("%d",&x[i]);
sort(x+,x++n);
l=r=sum=;ans=;
for(l=;l<=n;l++){
while(x[r]-x[l]<=k && r<=n)
r++;
ans+=r-l-;
}
printf("%lld\n",ans);
}
return ;
}
hdu5178 尺取的更多相关文章
- Gym 100703I---Endeavor for perfection(尺取)
题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatement ...
- NOJ 1072 The longest same color grid(尺取)
Problem 1072: The longest same color grid Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit in ...
- hdu 4123 Bob’s Race 树的直径+rmq+尺取
Bob’s Race Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...
- poj2566尺取变形
Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...
- poj2100还是尺取
King George has recently decided that he would like to have a new design for the royal graveyard. Th ...
- hdu 6231 -- K-th Number(二分+尺取)
题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...
- Codeforces 939E Maximize! (三分 || 尺取)
<题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...
- cf1121d 尺取
尺取,写起来有点麻烦 枚举左端点,然后找到右端点,,使得区间[l,r]里各种颜色花朵的数量满足b数组中各种花朵的数量,然后再judge区间[l,r]截取出后能否可以供剩下的n-1个人做花环 /* 给定 ...
随机推荐
- Cleanup failed to process the following paths错误的解决
在使用TortoiseSVN工具执行Cleanup操作时经常出现Cleanup failed to process the following paths的错误,具体如下图: 网上搜索了一下,找到了解 ...
- Python 爬虫的工具列表 附Github代码下载链接
Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...
- nginx错误集合
遇到 nginx: [warn] server name "http://127.0.0.1" has suspicious symbols in D:\nginx-1.12.1/ ...
- spring boot 2.0.3+spring cloud (Finchley)2、搭建负载均衡Ribbon (Eureka+Ribbon+RestTemplate)
Ribbon是Netflix公司开源的一个负载均衡组件,将负载均衡逻辑封装在客户端中,运行在客户端的进程里. 本例子是在搭建好eureka的基础上进行的,可参考spring boot 2.0.3+sp ...
- WorkerMan 入门学习之(三)基础教程-Timer类的使用
1.ServerTimer.php 代码: <?php /** * 定时器学习 */ require_once __DIR__ . '/Workerman/Autoloader.php'; us ...
- mysql的事件
mysql的事件定时器的使用: SHOW VARIABLES LIKE 'event_scheduler' --查询event_scheduler开启状态 SET GLOBAL event_sched ...
- [C++]指针和指向数组的指针[一维数组与指针]
1.一维数组与指针 形如:int型 数组 a[10] 1)&a[0] 地址常量;地址类型:int *型 ; 存储数组a的首地址 ...
- REUSE_ALV_GRID_DISPLAY详解
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_INTERFACE_CHECK = ' ' "接口一致性检查 * I_BYPASSING ...
- luogu P1437 [HNOI2004]尻♂砖块
传送门 想明白了其实不难 强行瞎扯 这题的限制比较烦,导致了一行行转移几乎不能做(吧) 那么一列列转移呢? 设\(f_{i,j,k}\)表示前\(i\)列,取\(j\)个,其中第\(i\)列取从上往下 ...
- shell 终端常用插件
参考链接: http://get.ftqq.com/992.get 1.zsh 2.autojump 3.apt-get install lamp-server^ 4.tldr 5.tree (显示目 ...