【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 ...
随机推荐
- [Python] Slicing Lists
In addition to accessing individual elements from a list we can use Python's slicing notation to acc ...
- StdTranslator - Translate PDMS to STD for STAAD.Pro
StdTranslator - Translate PDMS to STD for STAAD.Pro eryar@163.com STAAD.Pro是由美国世界著名的工程咨询和CAD软件开发公司—R ...
- IIS7下设置AD单点登录
简介:IIS7下设置AD单点登录 1.选中网站,双击“身份验证”: 2.启用“Window身份验证”.禁用“匿名身份验证”.启用“基本身份验证”: 3.在“基本身份验证”上面点右键,选择“编辑”,输入 ...
- c#数据类型格式转换大全
来源:网络 1.DateTime 数字型 System.DateTime currentTime=new System.DateTime(); 1.1 取当前年月日时分秒 ...
- 图片压缩优化kraken
https://kraken.io/web-interface 测试过,可以节省10%左右的大小,图片清晰度不受影响.
- ElasticSearch 5.2.2 安装及 head 插件的安装
ElasticSearch 是一个基于 Lucene 的高度可扩展的开源全文搜索和分析引擎.它能够做到可以快速.实时地存储.搜索和分析大量数据.它通常作为底层引擎/技术,为具有复杂搜索功能和要求的应用 ...
- 一个简易版的Angular js 三层 示例
var myApp = angular.module('produceline', []); myApp.factory('ajax', ["$http", "$q&qu ...
- Drupal 关于节点(nodes)的理解
在 Drupal 构建的站点中.全部的内容都是以节点形式存储的,一个节点能够是公布的不论什么一个内容,比方说一个单面(page).一个投票(Poll).一篇文章(article).论坛主题(forum ...
- js16--自定义原型对象
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- RingtoneManager-获得系统当前的铃声
我们直接看代码 bt1 = (Button) findViewById(R.id.bt1); bt2 = (Button) findViewById(R.id.bt2); bt3 = (Button) ...