【Codeforces Round #433 (Div. 1) C】Boredom(二维线段树)
【链接】我是链接
【题意】
【题解】
【错的次数】
【反思】
【代码】
#include <bits/stdc++.h>
using namespace std; const int N = 2e5, M = 2e5 * 20; int n, q;
int root[N + 10], ls[M + 10], rs[M + 10], sum[M+10],tot = 0;
long long ans = 0; void updata(int &x, int y, int l, int r, int pos) {
x = ++tot;
ls[x] = ls[y], rs[x] = rs[y];
sum[x] = sum[y] + 1;
int m = (l + r) >> 1;
if (l == r) return;
if (pos <= m)
updata(ls[x], ls[y], l, m, pos);
else
updata(rs[x], rs[y], m + 1, r, pos);
} int Q(int x, int L, int R, int l, int r) {
if (!x) return 0;
if (L <= l && r <= R) return sum[x];
int m = (l + r) >> 1;
int sum = 0;
if (L <= m) sum += Q(ls[x], L, R, l, m);
if (m < R) sum += Q(rs[x], L, R, m + 1, r);
return sum;
} long long C(long long x) {
return x*(x - 1)/2;
} long long ask(int x1, int y1, int x2, int y2) {
return C(Q(root[x2], y1, y2, 1, n) - Q(root[x1 - 1], y1, y2, 1, n));
} int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> q;
for (int i = 1,p; i <= n; i++) {
cin >> p;
updata(root[i],root[i-1],1,n,p);
}
for (int i = 1, l, d, r, u; i <= q; i++) {
cin >> l >> d >> r >> u;
ans = ask(1, 1, l - 1, n) + ask(1, 1, n, d - 1) + ask(r + 1, 1, n, n) + ask(1, u + 1, n, n);
ans = ans - ask(1, 1, l - 1, d - 1) - ask(1, u + 1, l - 1, n) - ask(r + 1, u + 1, n, n) - ask(r + 1, 1, n, d - 1);
cout << C(n) - ans << endl;
}
return 0;
}
【Codeforces Round #433 (Div. 1) C】Boredom(二维线段树)的更多相关文章
- Codeforces Round #619 (Div. 2)E思维+二维RMQ
题:https://codeforces.com/contest/1301/problem/E 题意:给个n*m的图形,q个询问,每次询问问询问区间最大的合法logo的面积是多少 分析:由于logo是 ...
- Codeforces Round #292 (Div. 1) C. Drazil and Park 线段树
C. Drazil and Park 题目连接: http://codeforces.com/contest/516/problem/C Description Drazil is a monkey. ...
- Codeforces Round #254 (Div. 1) C. DZY Loves Colors 线段树
题目链接: http://codeforces.com/problemset/problem/444/C J. DZY Loves Colors time limit per test:2 secon ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树扫描线
D. Vika and Segments 题目连接: http://www.codeforces.com/contest/610/problem/D Description Vika has an i ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments (线段树+扫描线+离散化)
题目链接:http://codeforces.com/contest/610/problem/D 就是给你宽度为1的n个线段,然你求总共有多少单位的长度. 相当于用线段树求面积并,只不过宽为1,注意y ...
- Codeforces Round #149 (Div. 2) E. XOR on Segment (线段树成段更新+二进制)
题目链接:http://codeforces.com/problemset/problem/242/E 给你n个数,m个操作,操作1是查询l到r之间的和,操作2是将l到r之间的每个数xor与x. 这题 ...
- Codeforces Round #321 (Div. 2) E. Kefa and Watch 线段树hash
E. Kefa and Watch Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/prob ...
- Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)
题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...
- Codeforces Round #207 (Div. 1) A. Knight Tournament (线段树离线)
题目:http://codeforces.com/problemset/problem/356/A 题意:首先给你n,m,代表有n个人还有m次描述,下面m行,每行l,r,x,代表l到r这个区间都被x所 ...
随机推荐
- hdu4565---So Easy!(矩阵)
Problem Description A sequence Sn is defined as: Where a, b, n, m are positive integers.┌x┐is the ce ...
- Cocos2d-x开发的Android应用怎么加入插屏广告
Cocos2d-x系统开发游戏已经变得比較流行,但是用这个开发的游戏.想要加入广告就不是那么理想了.尤其是插屏广告.由于插屏广告通常是要在暂停或者结束游戏的时候展示才比較的合理.但是Cocos2d-x ...
- 线段树 hdu3642 Get The Treasury
不得不说,这是一题很经典的体积并.. 然而还是debug了2个多小时... 首先思路:按z的大小排序. 然后相当于扫描面一样,,从体积的最下方向上方扫描,遇到这个面 就将相应的两条线增加到set中,或 ...
- 给Linux添加新用户,新建用户,新建帐号
给Linux添加新用户,新建用户,新建帐号 添加用户组 sudo groupadd groupname 添加用户 sudo useradd username -m -s /sbin/nologin - ...
- jquery18 css() : 样式的操作
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- 深入理解Android(4)——理解Android中的JNI(下)
在前面文章中简单介绍了JNI,这一篇文章来简单看一下jni.h中定义的一些常用方法,来实现通过C++调用Android中的Java代码. 转载请说明出处:http://blog.csdn.net/da ...
- Kinect 开发 —— 骨骼追踪
骨骼追踪技术通过处理景深数据来建立人体各个关节的坐标,骨骼追踪能够确定人体的各个部分,如那部分是手,头部,以及身体.骨骼追踪产生X,Y,Z数据来确定这些骨骼点.骨骼追踪系统采用的景深图像处理技术使用更 ...
- Ansible学习记录二:命令
0.ansible 命令参数详解: [root@localhost ~]# ansible Usage: ansible <host-pattern> [options] Options: ...
- hdoj 2122 Ice_cream’s world III【最小生成树】
Ice_cream's world III Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 洛谷P3391 【模板】文艺平衡树(Splay)(FHQ Treap)
题目背景 这是一道经典的Splay模板题——文艺平衡树. 题目描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1, ...