首页 技术 正文
技术 2022年11月11日
0 收藏 618 点赞 4,231 浏览 1431 个字

分析:开个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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,954
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,479
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,291
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,108
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,740
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,774