HDU - 6534 Chika and Friendly Pairs】的更多相关文章

这个题其实也是很简单的莫队,题目要求是给一个序列,询问l-r区间内部,找到有多少对答案满足 i < j 并且 | a[ i ] -a[ j ] | <=k 也就是有多少对,满足差值小于k的个数. 把这个式子展开,其实就是-k<= a[ i ] -a [ j ] <= k 也就是  a[ j ] -k <= a[ i ] <= a[ j ] + k,也就是说,对于某个 j 位置,我们需要在询问的区间内,找到 i < j 并且在[ a[j] -k ,a[j] +k ]…
HDU6534 Chika and Friendly Pairs 莫队,树状数组的简单题 #include<bits/stdc++.h> using namespace std; const int maxn = 30005; const int maxq = 27005; int n, m, k, num, sz, len; int a[maxn], belong[maxn], t[maxn], tree[maxn], ans[maxq]; int lowerl[maxn], lowerr[…
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=6534 题意: 给你一个数组,对于第i个数来说,如果存在一个位置j,使得j>i并且a[j]-k<=a[i]<=a[j]+k,那么这对数就称为好的,有q个询问,问你l到r区间有多少对好的数. 思路: 离线询问,想到可以用莫队维护区间,新加入元素(或删除元素)x时要统计区间[x-k,x+k]内的元素个数,想到 可以利用树状数组存元素个数(cnt)(权值数组),区间和就是元素个数,数据<=1e…
链接: https://vjudge.net/contest/308446#problem/C 题意: Chika gives you an integer sequence a1,a2,-,an and m tasks. For each task, you need to answer the number of " friendly pairs" in a given interval. friendly pair: for two integers ai and aj, if…
题意及思路:https://blog.csdn.net/tianyizhicheng/article/details/90369491 代码: #include <bits/stdc++.h> #define lowbit(x) (x & (-x)) using namespace std; const int maxn = 30010; int c[maxn * 3], num[maxn], b[maxn * 3], lb[maxn], rb[maxn], a[maxn]; int…
A. Chessboard 做法1 单纯形. 做法2 最大费用可行流问题,行列模型. 对每行建一个点,每列建一个点.物品 \(i\) 在 \((r,c)\),那么 \(r\) 向 \(c\) 连流量为 1 费用为 \(i\) 的边. 若第 i 至第 inf 行可选择物品上界为 k.那么 i-1 行向 i 行连流量为 k 的边,源点向第 0 行连流量为 inf 的边.列同理. B. Build Tree 贪心,把边权小的边,深度小. C. Chika and Friendly Pairs 对询问离…
Problem Statement On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (ai,bi), and the coordinates of the i-th blue point are (ci,di). A red point and a blue point can form a friendly pair w…
题目链接:https://abc091.contest.atcoder.jp/tasks/arc092_a 题意 On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (ai,bi), and the coordinates of the i-th blue point are (ci,di). A red point and…
Problem Statement On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (ai,bi), and the coordinates of the i-th blue point are (ci,di). A red point and a blue point can form a friendly pair w…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5178 pairs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3090    Accepted Submission(s): 1085 Problem Description John has n points on the X axi…