【Codeforces Round #433 (Div. 1) C】Boredom(树状数组)
【链接】h在这里写链接
【题意】
【题解】
【错的次数】
【反思】
【代码】
#include <bits/stdc++.h>
using namespace std; const int M = 2e5; int n, m;
vector <tuple<int, int, int, int> > a;
long long num[M * 10 + 10],ans[M+10][9]; struct BI { int a[M + 10]; int lowbit(int x) {
return x&(-x);
} void add(int x, int y) {
while (x <= M) {
a[x] += y;
x += lowbit(x);
}
} int sum(int x) {
int now = 0;
while (x > 0) {
now += a[x];
x -= lowbit(x);
}
return now;
} int get_sum(int l, int r) {
return sum(r) - sum(l - 1);
} }b; long long C(long long x) {
return x*(x - 1) / 2;
} int main() {
//freopen("F:\\rush.txt", "r", stdin);
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (int i = 1,p; i <= n; i++) {
cin >> p;
a.push_back(make_tuple(i,p,0,0));
}
for (int i = 1,l,d,r,u; i <= m; i++) {
cin >> l >> d >> r >> u;
a.push_back(make_tuple(l-1,d-1,i,1));
a.push_back(make_tuple(l - 1, u, i, 2));
a.push_back(make_tuple(l - 1, n, i, 3));
a.push_back(make_tuple(n, u, i, 4));
a.push_back(make_tuple(n, d-1, i, 5));
a.push_back(make_tuple(r, n, i, 6));
a.push_back(make_tuple(r, d - 1, i, 7));
a.push_back(make_tuple(r, u, i, 8));
}
sort(a.begin(), a.end());
for (int i = 0; i <= (int)a.size() - 1; i++) {
int x, y, j, id;
tie(x, y, j, id) = a[i];
if (j == 0) {
b.add(y, 1);
}
else
ans[j][id] = b.get_sum(1, y);
}
vector <long long> v;
v.resize(9);
for (int i = 1; i <= m; i++) {
v[1] = ans[i][1];
v[2] = ans[i][3];
v[3] = ans[i][5];
v[4] = n - ans[i][4];
v[5] = ans[i][3] - ans[i][2];
v[6] = n - ans[i][6];
v[7] = ans[i][5] - ans[i][7];
v[8] = n - ans[i][6] - ans[i][4] + ans[i][8];
long long temp = 0;
temp += C(v[2]) + C(v[4]) + C(v[6]) + C(v[3]) - C(v[5]) - C(v[1]) - C(v[7]) - C(v[8]);
cout << C(n) - temp << endl;
}
return 0;
}
【Codeforces Round #433 (Div. 1) C】Boredom(树状数组)的更多相关文章
- Codeforces Round #401 (Div. 1) C(set+树状数组)
题意: 给出一个序列,给出一个k,要求给出一个划分方案,使得连续区间内不同的数不超过k个,问划分的最少区间个数,输出时将k=1~n的答案都输出 比赛的时候想的有点偏,然后写了个nlog^2n的做法,T ...
- CF Educational Codeforces Round 10 D. Nested Segments 离散化+树状数组
题目链接:http://codeforces.com/problemset/problem/652/D 大意:给若干个线段,保证线段端点不重合,问每个线段内部包含了多少个线段. 方法是对所有线段的端点 ...
- Educational Codeforces Round 10 D. Nested Segments 离线树状数组 离散化
D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n ...
- Educational Codeforces Round 10 D. Nested Segments 【树状数组区间更新 + 离散化 + stl】
任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds mem ...
- Educational Codeforces Round 8 E. Zbazi in Zeydabad 树状数组
E. Zbazi in Zeydabad 题目连接: http://www.codeforces.com/contest/628/problem/D Description A tourist wan ...
- HDU5465/BestCoder Round #56 (div.2) 二维树状数组
Clarke and puzzle 问题描述 克拉克是一名人格分裂患者.某一天,有两个克拉克(aa和bb)在玩一个方格游戏. 这个方格是一个n*mn∗m的矩阵,每个格子里有一个数c_{i, j}ci ...
- Codeforces Round #433 (Div. 2)【A、B、C、D题】
题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...
- DP Codeforces Round #260 (Div. 1) A. Boredom
题目传送门 /* 题意:选择a[k]然后a[k]-1和a[k]+1的全部删除,得到点数a[k],问最大点数 DP:状态转移方程:dp[i] = max (dp[i-1], dp[i-2] + (ll) ...
- 递推DP Codeforces Round #260 (Div. 1) A. Boredom
题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #in ...
随机推荐
- [React] Write Compound Components
Compound component gives more rendering control to the user. The functionality of the component stay ...
- stl--vector 操作实现
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...
- easyui datagird 总计栏
在使用easyui 的表格的时.非常多时候须要加一个总计栏,当然easyui中有加总计栏的方法,写一个footer就好,然而我认为这样的方法并不好.由于加入的总计栏是和列表每一个单元格相应的,有长度限 ...
- 在 Android 应用程序中使用 SQLite 数据库以及怎么用
part one : android SQLite 简单介绍 SQLite 介绍 SQLite 一个非常流行的嵌入式数据库.它支持 SQL 语言,而且仅仅利用非常少的内存就有非常好的性能.此外它还是开 ...
- [python]CompressionError: bz2 module is not available
事情是这种,在centos6 上本来是python2.6 然后我下载了一个python2.7.5 安装之后,把默认python改动为python2.7.5版本号. 使用pip安装twisted的时候出 ...
- #学习笔记#——JavaScript 数组部分编程(二)
2.移除数组 arr 中的所有值与 item 相等的元素,直接在给定的 arr 数组上进行操作,并将结果返回 function removeWithoutCopy(arr, item) { if(!A ...
- Android实现QQ分享及注意事项
一.获取APPID和帮助文档 在前面我介绍了关于Android中微信分享的文章< Android实现微信分享及注意事项>这一篇文章来看看关于QQ分享. 可以参看新手引导和接入说明:http ...
- C#之用户自定义控件
一.新建用户自定义控件 如下图所示,想通过LED的点击来实现亮和灭使用去控制下位机. LED亮: LED灭: 首先新建一个用户控件类,如下图所示步骤: 在资源中,添加现有文件中加入图片 加入的图片可以 ...
- 【习题 8-15 UVA - 1617】Laptop
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 贪心. 把所有的区间按照右端点为第一关键字,左端点为第二关键字升序排. 然后令now = a[i].second. (now即当前的 ...
- Encoding encoding = Encoding.GetEncoding("gb2312"); 与byte[] ping = Encoding.UTF8.GetBytes(inputString);区别
Encoding encoding = Encoding.GetEncoding("gb2312"); 与byte[] ping = Encoding.UTF8.GetBytes( ...