【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 ...
随机推荐
- 动态规划 LCS,LIS
1.最大连续子序列 dp[i]=max(dp[i-1]+a[i],a[i]) 以i为结尾 2.最大不连续子序列 dp[i]=max(dp[j]+a[i],dp[j]) 3.最大连续递增子序列 if a ...
- Spring boot 解析jsp支持jsp热部署
解析jsp并且支持jsp热部署 参考地址:https://www.wanpishe.top/detail?blogId=39875536-7d45-48ec-a7b5-f36b85c3a235
- mktemp---创建暂存文件
- wget---从指定的URL下载文件
wget命令用来从指定的URL下载文件.wget非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性,如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完毕.如果是服务器打断下 ...
- 从硬件到语言,详解C++的内存对齐(memory alignment)(一)
作者:赵宗晟 出处:https://www.cnblogs.com/zhao-zongsheng/p/9099603.html 很多写C/C++的人都知道“内存对齐”的概念以及规则,但不一定对他有很深 ...
- [TypeScript] Shallow copy object by using spread opreator
For example we have an object: const todo = { text: "Water the flowers", completed: false, ...
- Trafodion:Transactional SQL on HBase
Trafodion: Transactional SQL on HBase HBase上实时分布式事务处理 介绍 HBase的SQL能力一直不足.Phoenix缺乏Join能力,eBay提出的kyli ...
- 32.Node.js中的常用工具类util
转自:http://www.runoob.com/nodejs/nodejs-module-system.html util是一个Node.js核心模块,提供常用函数的集合,用于弥补JavaScrip ...
- IIS特殊字符设置
简介:[iis7]请求筛选模块被配置为拒绝包含双重转义序列的请求.HTTP 错误 404.11 - Not Found 特殊字符最好替换成其他的字符,主要的特殊字符有”*”.”&”.”%”.” ...
- Monkey测试执行指导
1.Monkey常规测试