【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 ...
随机推荐
- html5中的容器标签和文本标签
html5中的容器标签和文本标签 html中的容器级标签和文本级标签,css中的块级元素和行内元素是我们常常拿来比较的四个名词(行内块级暂时先不考虑). 容器标签 容器级的标签可以简单的理解为能嵌套其 ...
- Scott Hanselman的问题-3
.Net程序员面试 中级篇 (回答Scott Hanselman的问题) 继<.Net 程序员面试 C# 语言篇 (回答Scott Hanselman的问题)>跟<.Net程序员 ...
- es6 -- set 数据结构
ES6 提供了新的数据结构 Set.它类似于数组,但是成员的值都是唯一的,没有重复的值. Set 本身是一个构造函数,用来生成 Set 数据结构. const s = new Set(); [2, 3 ...
- 4.cocos场景和层的调用
调用关系: AppDeligate.cpp bool AppDelegate::applicationDidFinishLaunching() { // initialize director aut ...
- POJ 3037 SPFA
题意: 思路: 我们可以发现 到每个点的速度是一样的 那这就成水题了-. 裸的SPFA跑一哈 搞定 //By SiriusRen #include <cmath> #include < ...
- wmic windows
http://www.ynpxrz.com/n614885c2025.aspx http://www.ynpxrz.com/n614883c2025.aspx http://www.ynpxrz.co ...
- IOS越狱开发错误解决
Questions: haseScriptExecution Run\ Script /Users/jun/Library/Developer/Xcode/DerivedData/ButtonMa ...
- WIN8.1的安装和打开"这台电脑"速度很慢的解决办法
WIN8.1的安装和打开"这台电脑"速度很慢的解决办法 对于非服务器用的电脑,如果电脑的内存在2G或更高,首推的操作系统是 WINDOWS8.1 64位企业版,用了就知道,没有比这流畅懂事的操作系统. ...
- Android学习笔记技巧之垂直和水平滚动视图
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android=" ...
- android图片特效处理之光照效果
这篇将讲到图片特效处理的光照效果.跟前面一样是对像素点进行处理,算法是通用的. 算法原理:图片上面的像素点按照给定圆心,按照圆半径的变化,像素点的RGB值分别加上相应的值作为当前点的RGB值. 例: ...