XTUOJ1247 Pair-Pair 预处理+暴力
分析:开个1000*1000的数组,预处理矩阵和,然后分类讨论就好
时间复杂度:O(n)
#include <cstdio>
#include <iostream>
#include <ctime>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=1e5+;
const int INF=0x3f3f3f3f;
const int mod=1e9+;
struct Node{
int x,y;
}p[N];
int a[][];
int high[],low[],mid[];
LL ret[];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m)){
memset(a,,sizeof(a));
memset(ret,,sizeof(ret));
memset(high,,sizeof(high));
memset(low,,sizeof(low));
memset(mid,,sizeof(mid));
for(int i=;i<=n;++i){
scanf("%d%d",&p[i].x,&p[i].y);
++a[p[i].x][p[i].y];
if(p[i].y>p[i].x)++high[p[i].x];
else if(p[i].y==p[i].x)++mid[p[i].x];
else ++low[p[i].x];
}
for(int i=;i<=m;++i){
low[i]+=low[i-];
mid[i]+=mid[i-];
high[i]+=high[i-];
}
for(int i=;i<=m;++i)
for(int j=;j<=m;++j)
a[i][j]+=a[i-][j]+a[i][j-]-a[i-][j-];
for(int i=;i<=n;++i){
if(p[i].y>p[i].x){
int tmp=,t;
t=high[m]-high[p[i].y];
tmp+=t;ret[]+=t;
t=low[m]-low[p[i].y]+mid[m]-mid[p[i].y];
tmp+=t;ret[]+=t;
t=high[p[i].y]-high[p[i].y-];
tmp+=t;ret[]+=t;
t=high[p[i].y-]-high[p[i].x];
tmp+=t;ret[]+=t;
t=a[p[i].x][m]-a[p[i].x][p[i].y];
tmp+=t;ret[]+=t;
ret[]+=1ll*(n-tmp);
}
else if(p[i].x==p[i].y){
int tmp=,t;
t=high[m]-high[p[i].x];
tmp+=t;ret[]+=t;
t=low[p[i].x]+mid[p[i].x];
tmp+=t;ret[]+=t;
ret[]+=1ll*(n-tmp);
}
else {
int tmp=,t;
t=low[p[i].y]+mid[p[i].y];
tmp+=t;ret[]+=t;
t=high[m]-high[p[i].y];
tmp+=t;ret[]+=t;
ret[]+=1ll*(n-tmp);
}
}
printf("%I64d %I64d %I64d %I64d\n",ret[],ret[],ret[],ret[]);
}
return ;
}
XTUOJ1247 Pair-Pair 预处理+暴力的更多相关文章
- CodeForces 359D Pair of Numbers (暴力)
题意:给定一个正整数数组,求最长的区间,使得该区间内存在一个元素,它能整除该区间的每个元素. 析:暴力每一个可能的区间,从数组的第一个元素开始考虑,向两边延伸,设延伸到的最左边的点为l, 最右边的点为 ...
- 51Nod 1158 全是1的最大子矩阵 —— 预处理 + 暴力枚举 or 单调栈
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1158 1158 全是1的最大子矩阵 基准时间限制:1 秒 空 ...
- bzoj 3752: Hack 预处理+暴力dfs
题目大意: 定义字符串的hash值\(h = \sum_{i=0}^{n-1}p^{n-i-1}s_i\) 现在给定K个长度不超过L的字符串S,对于每个字符串S,求字典序最小长度不超过L的字符串T使得 ...
- C++学习之Pair
C++学习之Pair Pair类型概述 pair是一种模板类型,其中包含两个数据值,两个数据的类型可以不同,基本的定义如下: pair<int, string> a; 表示a中有两个类型, ...
- 找最大重复次数的数和重复次数(C++ Pair)
Problem A: 第一集 你好,世界冠军 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 265 Solved: 50[Submit][Statu ...
- STL模板整理 pair
pair pair是一种模板类型,其中包含两个数据值,两个数据的类型可以不同.如果一个函数有两个返回值的话,如果是相同类型,就可以用数组返回,如果是不同类型,就可以自己写个struct ,但为了方便就 ...
- C++编程->pair(对组)
pair 是 一种模版类型.每一个pair 能够存储两个值.这两种值无限制,能够是tuple.vector ,string,struct等等. 首先来看一下pair的函数 初始化.复制等相关操作例如以 ...
- STL pair 常见用法详解
<算法笔记>学习笔记 pair 常见用法详解 //pair是一个很实用的"小玩意",当想要将两个元素绑在一起作为一个合成元素, //又不想因此定义结构体时,使用pair ...
- C++ pair
C++ pair Pair类型概述 pair是一种模板类型,其中包含两个数据值,两个数据的类型可以不同,基本的定义如下: pair<int, string> a; 表示a中有两个类型,第一 ...
随机推荐
- Ubuntu环境下nutch2.2.1集成HBase0.94.25
nutch2.2.1集成HBase0.94.25 (详见:http://duguyiren3476.iteye.com/blog/2085973 ) 1. 修改nutch的hbase配置 //将自己的 ...
- Gulp实战和原理解析
Gulp实战和原理解析(以weui作为项目实例)http://i5ting.github.io/stuq-gulp/
- 李洪强iOS开发之【零基础学习iOS开发】【01-前言】01-开篇
从今天开始,我就开始更新[零基础学习iOS开发]这个专题.不管你是否涉足过IT领域,也不管你是理科生还是文科生,只要你对iOS开发感兴趣,都可以来阅读此专题.我尽量以通俗易懂的语言,让每个人都能够看懂 ...
- lintcode 中等题:majority number III主元素III
题目 主元素 III 给定一个整型数组,找到主元素,它在数组中的出现次数严格大于数组元素个数的1/k. 样例 ,返回 3 注意 数组中只有唯一的主元素 挑战 要求时间复杂度为O(n),空间复杂度为O( ...
- lintcode :旋转字符串
题目: 旋转字符串 给定一个字符串和一个偏移量,根据偏移量旋转字符串(从左向右旋转) 样例 对于字符串 "abcdefg". offset=0 => "abcdef ...
- sql语句面试总结
1.用一条SQL语句 查询出每门课都大于80分的学生姓名 name kecheng fenshu 张三 语文 81张三 数学 75李四 语文 ...
- 一起学Maven
转载自:http://blog.csdn.net/songdeitao/article/details/18452459 一. 初识Maven 开场白 在现在的项目开发过程中,越来越重视项目的管理,而 ...
- VIM Taglist + ctags
Windows下 进入http://ctags.sourceforge.net/ 下载ctags 把ctags58.zip解压,随便放个地方,我放到了Home\Vim\vim72下,在ctags58文 ...
- HDU5099——Comparison of Android versions(简单题)(2014上海邀请赛重现)
Comparison of Android versionsProblem DescriptionAs an Android developer, itˇs really not easy to fi ...
- Android The content of the adapter has changed but ListView did not receive a notification
The content of the adapter has changed but ListView did not receive a notification. Make sure the co ...