【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所 ... 
随机推荐
- CF(438D) The Child and Sequence(线段树)
			题意:对数列有三种操作: Print operation l, r. Picks should write down the value of . Modulo operation l, r, x. ... 
- 获取个人借阅信息---图书馆client
			在上一篇利用jsoup解析个人信息----图书馆client,获得个人基本信息后.便有了进一步的需求:获取当前借阅的具体信息 获取的方法还是一样的.利用jsoup解析借阅信息页面,获得所需数据,封装成 ... 
- hdu 1003 Max Sum 最大字段和 dp
			今天看了一上午dp.看不太懂啊.dp确实不简单.今天開始学习dp,搜了杭电的dp46道,慢慢来吧.白书上的写的 又不太具体,先写几道题目再说. .. 题目连接:id=516&page=1&qu ... 
- Myeclipse集成Maven(图文说明)
			myeclipse 上安装 Maven3 环境准备: JDK 1.6 Maven 3.2.5 myeclipse 2013 安装 Maven 之前要求先确定你的 JDK 已经安装配置完毕.Maven是 ... 
- malloc,colloc,realloc内存分配,动态库,静态库的生成与调用
			 1.在main方法里面直接定义一个很大的数组的时候.可能会出现栈溢出:错误代码演示: #include<stdio.h> #include<stdlib.h> void ... 
- 关于Webpack详述系列文章 (第四篇)
			1. webpack基本概念 Entry:入口,Webpack 执行构建的第一步将从 Entry 开始,可抽象成输入.Module:模块,在 Webpack 里一切皆模块,一个模块对应着一个文件.We ... 
- CF-833B The Bakery(线段树优化Dp)
			Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredie ... 
- [Python] Different ways to test multiple flags at once in Python
			x, y, z = 0, 1, 0 if x == 1 or y == 1 or z == 1: print('passed') if 1 in (x, y, z): print('passed') ... 
- LinearLayout-layout_gravity 属性没有效果分析
			今天在一个布局文件中,遇到了一个问题,先看代码 <LinearLayout android:layout_width="match_parent" android:layou ... 
- R语言-方差分析
			方差分析指的是不同变量之间互相影响从而导致结果的变化 1.单因素方差分析: 案例:50名患者接受降低胆固醇治疗的药物,其中三种治疗条件使用药物相同(20mg一天一次,10mg一天两次,5mg一天四次) ... 
