首页 技术 正文
技术 2022年11月8日
0 收藏 520 点赞 1,880 浏览 1974 个字

题目传送

做法

  • 对于每个人,inc为x,pref为y;对于每道菜,p和s为x,b为y
  • 于是根据题意有$$p[i]<=x<=s[i]$$$$p[i]+b[i]<=x+y$$$$p[i]-b[i]<=x-y$$
  • 把所有出现的点都离散化一下,然后开始扫x轴
  • 对于x+y和x-y这两个函数,分别开一个树状数组去维护合法点的个数
#include <cstdio>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, a, b)for (int i = a; i <= b; i++)
#define All(x)(x.begin()), (x.end())
using namespace std;template <typename T> void read(T &x) {
x = 0;
T s = 1, c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')s = -1;
for (; isdigit(c); c = getchar())
x = x * 10 + c - 48;
x *= s;
}typedef long long ll;
const int maxn = 1e5 + 5;
int n, m, tot;
ll p[maxn], s[maxn], b[maxn], inc[maxn], pref[maxn];
int ans[maxn];
vector<ll> A, B;
vector<pair<ll, int>>que;class FenwickTree {
public:
int F[maxn << 1];void Modify(int x, int val) {
for (; x <= maxn << 1; x += x&-x)
F[x] += val;
}int Query(int x) {
int ret = 0;
for (; x; x -= x&-x)
ret += F[x];
return ret;
}
}bitA, bitB;inline void Read() {
read(n), read(m);
rep(i, 1, n)read(p[i]);
rep(i, 1, n)read(s[i]);
rep(i, 1, n)read(b[i]);
rep(i, 1, m)read(inc[i]);
rep(i, 1, m)read(pref[i]);
}inline void Discrete() {
A.push_back(-(1LL << 60));
B.push_back(-(1LL << 60));
rep(i, 1, n) {
que.push_back({p[i], i});
que.push_back({s[i], i + maxn * 2});
A.push_back(p[i] + b[i]);
B.push_back(p[i] - b[i]);
}
rep(i, 1, m) {
que.push_back({inc[i], i + maxn});
A.push_back(inc[i] + pref[i]);
B.push_back(inc[i] - pref[i]);
}sort(All(que)), sort(All(A)), sort(All(B));
A.erase(unique(All(A)), A.end());
B.erase(unique(All(B)), B.end());
}inline void Sweep() {
int num = 0;
for (auto i : que) {
int x = i.second, y;
if (x < maxn) {
num++;
y = lower_bound(All(A), p[x] + b[x]) - A.begin();
bitA.Modify(y, 1);
y = lower_bound(All(B), p[x] - b[x]) - B.begin();
bitB.Modify(y, 1);
} else if (x < maxn * 2) {//注意排序顺序p < inc < s
x -= maxn;
y = lower_bound(All(A), inc[x] + pref[x]) - A.begin();
ans[x] += bitA.Query(y);
y = lower_bound(All(B), inc[x] - pref[x]) - B.begin();
ans[x] += bitB.Query(y);
ans[x] -= num;
//当一个x一定大于等于另一个x时,无论y的关系如何,这样容斥一定能得到正确答案
} else {
x -= maxn * 2;
num--;
y = lower_bound(All(A), p[x] + b[x]) - A.begin();
bitA.Modify(y, -1);
y = lower_bound(All(B), p[x] - b[x]) - B.begin();
bitB.Modify(y, -1);
}
}
rep(i, 1, m)printf("%d%c", ans[i], " \n"[i == m]);
}int main() {
Read();
Discrete();
Sweep();
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,954
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,479
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,291
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,108
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,740
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,774