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中有两个类型,第一 ...
随机推荐
- Java快速排序 分别以数组0位作为基准 和最后一位作为基准的排序演示
package util; public class Pub { public static void beforeSort(int[] arr){ System.out.println(" ...
- lintcode : 二叉树的序列化和反序列化
题目 二叉树的序列化和反序列化 设计一个算法,并编写代码来序列化和反序列化二叉树.将树写入一个文件被称为“序列化”,读取文件后重建同样的二叉树被称为“反序列化”. 如何反序列化或序列化二叉树是没有限制 ...
- Tomcat就是个容器,一种软件
1.tomcat就是一个容器而已,一个软件,运行在java虚拟机. 2.tomcat是一种能接收http协议的软件,java程序猿自己也可以写出http解析的服务器啊. 3.tomcat支持servl ...
- 261. Graph Valid Tree
题目: Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nod ...
- OSSEC 安装执行./install.sh详细信息
下载好ossec安装文件后解压得到如下目录 [root@localhost ~]# cd ossec-hids-/ [root@localhost ossec-hids-]# ll total drw ...
- 解决PHP开启gd库无效的问题
最近需要重新安装PHP,以前一直使用的都是XAMPP,基本上都不需要自己配置,现在准备直接下载官方原版的Apache和PHP,自己来慢慢摸索如何继承配置. 我下载的Apache版本为2.2.25,PH ...
- NYOJ-253 凸包
LK的旅行 时间限制:2000 ms | 内存限制:65535 KB 难度:5 描述 LK最近要去某几个地方旅行,她从地图上计划了几个点,并且用笔点了出来,准备在五一假期去这几个城市旅行.现在 ...
- java转换json需导入的jar包说明
commons-beanutils-1.8.0.jar不加这个包 java.lang.NoClassDefFoundError: org/apache/commons/beanutils/DynaBe ...
- truncate table 和delete
delete table 和 truncate table 使用delete语句删除数据的一般语法格式: delete [from] {table_name.view_name} [where< ...
- UVa 1638 (递推) Pole Arrangement
很遗憾,这么好的一道题,自己没想出来,也许太心急了吧. 题意: 有长度为1.2.3...n的n个杆子排成一行.问从左到右看能看到l个杆子,从右往左看能看到r个杆子,有多少种排列方法. 分析: 设状态d ...