P2163 [SHOI2007] 园丁的烦恼
1.[博客迁移20190713]题解 P4169 【[Violet]天使玩偶/SJY摆棋子】2.模拟题3.SP666 VOCV - Con-Junctions 题解4.Codeforces Round #900 (Div. 3)5.Codeforces Round 962 (Div. 3)6.题解 CF993E 【Nikita and Order Statistics】7.题解 P6891 【[JOISC2020]ビルの飾り付け 4】
8.P2163 [SHOI2007] 园丁的烦恼
9.[POI2011] LIZ-Lollipop10.Codeforces Round 973 (Div. 2)11.Codeforces Round 974 (Div. 3)12.NEERC2013题解13.CF1446C Xor Tree14.Codeforces Round 709 (Div. 1)15.Codeforces Round 975 (Div. 2)16.NEERC2014题解17.题解 P2726 【[SHOI2005]树的双中心】18.CF2019 F. Max Plus Min Plus Size19.Codeforces Round 757 (Div. 2)20.大工之星第一周题解中学的时候年轻气盛,应该拿主席树把这道题艹过去了。正好复习离线二维数点,再做了一遍。
我们把询问差分安排到x轴上,然后y轴用树状数组统计即可。注意到此题要离散化,但是询问中的x可能不在原序列中。不过这不要紧,记得二分完减一就好。
const int N = 5e5 + 5, S = 1e7 + 5;
int n, m, t, ans[N], x[N];
pair <int, int> a[N];
struct Query {
int p, q, x, y;
Query(int p = 0, int q = 0, int x = 0, int y = 0) : p(p), q(q), x(x), y(y) {}
};
int c[S];
inline void update(int pos, int val) {
for (; pos < N; pos += lowbit(pos)) c[pos] += val;
}
inline int query(int pos) {
int ret = 0;
for (; pos; pos -= lowbit(pos)) ret += c[pos];
return ret;
}
vector <Query> v[N];
signed main(void) {
read(n), read(m);
for (int i = 1; i <= n; i++) read(a[i].first), read(a[i].second), x[i] = a[i].first;
sort(a + 1, a + n + 1); sort(x + 1, x + n + 1); t = unique(x + 1, x + n + 1) - (x + 1);
for (int i = 1; i <= m; i++) {
int l, r, _x, _y;
read(l), read(_x), read(r), read(_y);
int _l = lower_bound(x + 1, x + t + 1, l) - x - 1;
int _r = upper_bound(x + 1, x + t + 1, r) - x - 1;
v[_l].push_back(Query(i, -1, _x, _y));
v[_r].push_back(Query(i, 1, _x, _y));
}
for (int i = 1, j = 1; i <= t; i++) {
while (a[j].first == x[i] && j <= n) update(a[j].second + 1, 1), j++;
for (auto u : v[i]) ans[u.p] -= u.q * query(u.x), ans[u.p] += u.q * query(u.y + 1);
}
for (int i = 1; i <= m; i++) writeln(ans[i]);
//fwrite(pf, 1, o1 - pf, stdout);
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现