【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所 ...
随机推荐
- 使用表单向action提交时出现 “Error setting expression 'button' with value……”
原因是,form中的组件设置了name属性,struts2会通过OGNL在action中找相应的属性. 如 <form action="login"> <intp ...
- 解决WIN7远程登录提示无法保存凭据的问题
事由:今天到公司,想起手上还有点小东西没有改动完,就打算连上server进行小改动.结果发现昨天还能好好的远程连接server的WIN7,今天突然间不能远程登录了~ 无奈~悲催~ 我仅仅能猜是不是有什 ...
- (一一〇)正則表達式的基本使用与RegexKitLite的使用
正則表達式经常常使用于匹配keyword,以下先介绍基本的语法. [基本的语法] ①中括号表示满足当中之中的一个就可以,比如[abc],则这个位置能够是a.b.c中随意一个. ②在中括号里,能够通过- ...
- socket编程之中的一个:计算机网络基础
在開始学习网络之前先复习下计算机网络基础吧. 鲁迅说,天下文章一大抄.看你会炒不会炒,基础知识就抄抄书吧. 一 分层模型 1 为什么分层 为了简化网络设计的复杂性.通讯协议採用分层结构.各层协议之间既 ...
- Android_L(64bit) 模拟器配置及创建项目
Android L可能就是Android 5.0.随之而来的还有Android Watch. Android TV. 而据说在10月中旬也就是15号Google的公布会上应该会推出Nexus 6和Ne ...
- [论文笔记] CUDA Cuts: Fast Graph Cuts on the GPU
Paper:V. Vineet, P. J. Narayanan. CUDA cuts: Fast graph cuts on the GPU. In Proc. CVPR Workshop, 200 ...
- ajax的内容
ajax是什么? 通过在后台与服务器进行少量数据交换,Ajax 可以使网页实现异步更新,可以局部刷新而不必整个页面整体刷新. url的简单认识: 进入服务器的三种方式: 1.localhost:端口号 ...
- zhizhang错误(每天更新更新)
做题反思(Think twice ,Code once) 1.2013NOIP转圈游戏,交代码前一定要静态查错,看看代码写得和自己意思一不一样,竟然把变量n写成了常数10,低级错误 2.2013NOI ...
- Android开发数据库之第三方ORM框架(GreenDao)
移动APP追求追求功能实现的同一时候,用户体验很重要.開始APP的同一时候.要时刻的切换开发人员的角色,如你开发的时候.是 站在APP的开发角色,处于生产者的位置:当你測试的时候.你应该把自己放在用户 ...
- Hadoop权威指南学习笔记三
HDFS简单介绍 声明:本文是本人基于Hadoop权威指南学习的一些个人理解和笔记,仅供学习參考.有什么不到之处还望指出,一起学习一起进步. 转载请注明:http://blog.csdn.net/my ...