Description

The 3rd round of COCI is already here! In order to bet on predict the scores, we have assumed the following:

If contestant A scored strictly more points than contestant B in each of the first two rounds, then in the

third round A will score at least an equal amount of points as B.

Of course, in each round (including this one, the 3rd one) it is possible to score from 0 to 650 points. On the

total ranking list, contestants are sorted descending according to the sum of points from all three rounds.

The contestants with an equal sum share the same place and the next contestant gets the realistic following place.

For example, contestants with sums equal to 1000, 1000, 900, 900 and 800 points win places 1., 1., 3., 3. and 5.,

respectively.

For each of the N contestants, we know the number of points scored in the first and second round. Given the

aforementioned assumption, determine the highest and lowest place each contestant can get on the total ranking

list after three rounds of COCI.

Input

The first line of input contains an integer N (1 <= N <= 500000), the number of contestants.

Each of the following N lines contains two integers from the interval [0; 650]: the number of points each contestant

won in the first and second round.

Output

For each contestant, in the order given in the input, output two integers per line: the required highest and lowest

place they can get on the total ranking list.

Sample Input

5

250 180

250 132

220 123

132 194

220 105

10

650 550

550 554

560 512

610 460

610 456

650 392

580 436

650 366

520 456

490 456

Sample Output

1 3

1 3

3 5

1 5

3 5

1 4

1 8

2 8

2 7

2 9

1 10

4 10

1 10

5 10

5 10

题意:n个人进行决斗,共有三场比赛,前两场比赛的成绩已经知道了,第三场的成绩未知,已知如果A前两场比赛每一场比赛成绩都严格高于B,那么A的第三场成绩一定大于等于B,最后的结果按三场总成绩从高到低排序,问每一个人最好的名次和最差的名词分别可能为多少。

思路:先考虑一个人A最好的情况,那么A得到的分数为650分,那么之前两场严格高于她的人最后一定也高于她,如果B之前一门小于等于她,另一门高于她,这种情况最后也不会比她高,因为可以另B的第三门成绩为0,那么A的成绩一定是大于等于B的(等于的情况有两种,一种是第二门成绩为0,但是B的第二门成绩为650,第一门成绩两者相同,另一种是第一种第二种反一下),又因为两者成绩相等自己不会退后名词,所以可以不用管。再考虑A最坏的情况,我们考虑比A考的差的人,这里和之前一样,只是要考虑(0,0,a[i]-1,b[i]-1)的总数,这里还要考虑和她成绩相同的情况,就是A的a[i]或者b[i]=650,要减去这些,然后用n减去比她考的差的人数就是答案了。

注意:这题不能用树状数组,因为会超时,又因为点的坐标大小都很小,所以可以用s[i][j]表示x小于等于i,y小于等于j的坐标总数。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef long double ldb;
#define inf 99999999
#define pi acos(-1.0)
#define NN 500050
#define MM 650
int a[NN],b[NN];
int k[MM+10][MM+10],s[MM+10][MM+10];
int solve(int p,int q,int P,int Q)
{
int i,j;
if(P<0 || Q<0)return 0;
int sum=s[P][Q];
if(p>0){
sum-=s[p-1][Q];
}
if(q>0){
sum-=s[P][q-1];
}
if(p>0 && q>0){
sum+=s[p-1][q-1];
}
return sum;
}
int main()
{
int n,m,i,j,c,d;
while(scanf("%d",&n)!=EOF)
{
memset(k,0,sizeof(k));
memset(s,0,sizeof(s));
for(i=1;i<=n;i++){
scanf("%d%d",&a[i],&b[i]);
k[a[i] ][b[i] ]++;
}
for(i=0;i<=MM;i++){
for(j=0;j<=MM;j++){
s[i][j]=k[i][j];
if(i>0){
s[i][j]+=s[i-1][j];
}
if(j>0){
s[i][j]+=s[i][j-1];
}
if(i>0 && j>0){
s[i][j]-=s[i-1][j-1];
}
}
}
for(i=1;i<=n;i++){
printf("%d ",solve(a[i]+1,b[i]+1,MM,MM)+1 );
printf("%d\n",n-solve(0,0,a[i]-1,b[i]-1)-k[a[i] ][0]*(b[i]==MM)-k[0][b[i] ]*(a[i]==MM) );
}
}
return 0;
}

zjnu1725 COCI (类似二维树状数组模拟)的更多相关文章

  1. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  2. 二维树状数组(水题) POJ1195

    前段时间遇到线段树过不了,树状数组却过了的题.(其实线段树过得了的) 回忆了下树状数组. 主要原理,还是二进制位数,每一项的和表示其为它的前((最后一位1及其后)的二进制数)和,可从二进制图来看.(用 ...

  3. 二维树状数组——SuperBrother打鼹鼠(Vijos1512)

    树状数组(BIT)是一个查询和修改复杂度都为log(n)的数据结构,主要用于查询任意两位之间的所有元素之和,其编程简单,很容易被实现.而且可以很容易地扩展到二维.让我们来看一道很裸的二维树状数组题: ...

  4. 【二维树状数组】计数问题 @JSOI2009/upcexam5911

    时间限制: 1 Sec 内存限制: 128 MB 题目描述 一个n*m的方格,初始时每个格子有一个整数权值.接下来每次有2种操作: 改变一个格子的权值: 求一个子矩阵中某种特定权值出现的个数. 输入 ...

  5. 【bzoj5173】[Jsoi2014]矩形并 扫描线+二维树状数组区间修改区间查询

    题目描述 JYY有N个平面坐标系中的矩形.每一个矩形的底边都平行于X轴,侧边平行于Y轴.第i个矩形的左下角坐标为(Xi,Yi),底边长为Ai,侧边长为Bi.现在JYY打算从这N个矩形中,随机选出两个不 ...

  6. BZOJ3132 上帝造题的七分钟 【二维树状数组】

    题目 "第一分钟,X说,要有矩阵,于是便有了一个里面写满了0的n×m矩阵. 第二分钟,L说,要能修改,于是便有了将左上角为(a,b),右下角为(c,d)的一个矩形区域内的全部数字加上一个值的 ...

  7. POJ 2155 Matrix(二维树状数组,绝对具体)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20599   Accepted: 7673 Descripti ...

  8. SCOI2014 bzoj3594 方伯伯的玉米田(二维树状数组+dp)

    3594: [Scoi2014]方伯伯的玉米田 Time Limit: 60 Sec  Memory Limit: 128 MBSubmit: 1971  Solved: 961[Submit][St ...

  9. 二维树状数组 BZOJ 1452 [JSOI2009]Count

    题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...

随机推荐

  1. 【Linux】ntp的一些坑。你肯定遇到过

    ntpdate提示 19 Jan 10:33:11 ntpdate[29616]: no server suitable for synchronization found 这种问题从下面几个点开始验 ...

  2. 【Oracle】从删除的recyclebin中查看并恢复数据

    如果数据库中用了drop删除表,后面没有加上purge的话,会出现在oracle的回收机制中 dba_recyclebin可以查看当前删除的都是哪些 这个只是部分截图,可以看到删除的对象是什么,删除的 ...

  3. 构造无字母数字Webshell

    异或: 补充: A的ascii为65,对应二进制是01000001 <?php echo "1"^"A"; ?> 将"A"和&q ...

  4. 开篇:免费开源的趣讲 ZooKeeper 教程(连载)

    本文作者:HelloGitHub-老荀 一.起因 良好的开端,是成功的一半. 我是作者老荀,一个普通的程序员,没有 985 和 211 的背景,也从没在大厂工作过.仅仅是喜欢研究技术,一直想做一个讲解 ...

  5. 源代码增强的一点说明(souce code enhance )

    souce code enhance 分为显式和隐式两种. 下面以显式创建为例子: 1.在ABAP编辑器中, 打开想要编辑的程序,切换到可编辑模式 2.在源代码中的指定位置右键,弹出菜单,选择 Enh ...

  6. JMM在X86下的原理与实现

    JMM在X86下的原理与实现 Java的happen-before模型 众所周知 Java有一个happen-before模型,可以帮助程序员隔离各个平台多线程并发的复杂性,只要Java程序员遵守ha ...

  7. java 日期与时间操作

    我们先来了解一下基本的概念 日期 2020-11-21 2020-11-22 时间 15:36:43 2020-11-21 15:36:43 时区 北京时间 2020-11-21 15:36:43 东 ...

  8. React 入门-redux 和 react-redux

    React 将页面元素拆分成组件,通过组装展示数据.组件又有无状态和有状态之分,所谓状态,可以简单的认为是组件要展示的数据.React 有个特性或者说是限制单向数据流,组件的状态数据只能在组件内部修改 ...

  9. Linux 安装分区设置分区大小

    一.Linux分区挂载点介绍 Linux分区挂载点介绍,推荐容量仅供参考不是绝对,跟各系统用途以及硬盘空间配额等因素实际调整: 分区类型 介绍 备注 /boot 启动分区 一般设置100M-200M, ...

  10. Vue使用Ref跨层级获取组件实例

    目录 Vue使用Ref跨层级获取组件实例 示例介绍 文档目录结构 安装vue-ref 根组件自定义方法[使用provide和inject] 分别说明各个页面 结果 Vue使用Ref跨层级获取组件实例 ...