hdu517 Triple
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 160 Accepted Submission(s): 72
of integers, an another finite multi-set B of m triples
of integers, we define the product of A and B as
a multi-set
C=A∗B={⟨a,c,d⟩∣⟨a,b⟩∈A, ⟨c,d,e⟩∈B and b=e}
For each ⟨a,b,c⟩∈C,
its BETTER set is defined as
BETTERC(⟨a,b,c⟩)={⟨u,v,w⟩∈C∣⟨u,v,w⟩≠⟨a,b,c⟩, u≥a, v≥b, w≥c}
As a \textbf{multi-set} of triples, we define the TOP subset (as a multi-set as well) of C,
denoted by TOP(C),
as
TOP(C)={⟨a,b,c⟩∈C∣BETTERC(⟨a,b,c⟩)=∅}
You need to compute the size of TOP(C).
is the number of test case. Then t test
cases follow.
Each test case contains three lines. The first line contains two integers n (1≤n≤105) and m (1≤m≤105) corresponding
to the size of A and B respectively.
The second line contains 2×n nonnegative
integers
which describe the multi-set A,
where 1≤ai,bi≤105.
The third line contains 3×m nonnegative
integers
corresponding to the m triples
of integers in B,
where 1≤ci,di≤103 and 1≤ei≤105.
5 9
1 1 2 2 3 3 3 3 4 2
1 4 1 2 2 1 4 1 1 1 3 2 3 2 2 4 1 2 2 4 3 3 2 3 4 1 3
3 4
2 7 2 7 2 7
1 4 7 2 3 7 3 2 7 4 1 7
Case #2: 12
#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<algorithm>
using namespace std;
typedef long long ll;
#define inf 99999999
#define maxn 100050
int first[maxn],last[maxn],cnt[maxn],maxnum[maxn];
struct node1{
int x,y;
}a[maxn];
struct node2{
int x,y,z;
}c[maxn];
bool cmp(node1 a,node1 b){
if(a.y==b.y)return a.x>b.x;
return a.y<b.y;
}
bool cmp1(node2 a,node2 b){
return a.z<b.z;
}
struct node{
int x,y,z;
}temp,temp2;
bool operator<(node a,node b){
if(a.x==b.x){
if(a.y==b.y)return a.z>b.z;
return a.y>b.y;
}
return a.x>b.x;
}
map<node,int>mp;
map<node,int>::iterator it;
int b[1005][1005],pan[1006][1006];
int lowbit(int x){
return x&(-x);
}
void update(int x,int y,int num)
{
int i,j;
for(i=x;i<=1003;i+=lowbit(i)){
for(j=y;j<=1003;j+=lowbit(j)){
b[i][j]+=num;
}
}
}
int getsum(int x,int y)
{
int num=0,i,j;
for(i=x;i>0;i-=lowbit(i)){
for(j=y;j>0;j-=lowbit(j)){
num+=b[i][j];
}
}
return num;
}
int cal(int x,int y){
return getsum(1003,1003)-getsum(1003,y-1)-getsum(x-1,1003)+getsum(x-1,y-1);
}
int main()
{
int n,m,i,j,T,d,e,f,t,maxx,num,cas=0;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++){
scanf("%d%d",&a[i].x,&a[i].y);
}
sort(a+1,a+n+1,cmp);
for(i=1;i<=m;i++){
scanf("%d%d%d",&c[i].x,&c[i].y,&c[i].z);
}
sort(c+1,c+m+1,cmp1);
memset(first,0,sizeof(first));
memset(last,0,sizeof(last));
t=c[1].z;
first[t]=1;
c[m+1].z=-1;
for(i=2;i<=m+1;i++){
if(c[i].z!=t ){
last[t]=i-1;
t=c[i].z;
first[t]=i;
}
}
memset(maxnum,-1,sizeof(maxnum));
memset(cnt,0,sizeof(cnt));
for(i=1;i<=n;i++){
if(maxnum[a[i].y ]==-1 ){
maxnum[a[i].y ]=a[i].x;
cnt[a[i].y ]=1;
}
else{
if(maxnum[a[i].y ]<a[i].x){
maxnum[a[i].y ]=a[i].x;
cnt[a[i].y ]=1;
}
else if(maxnum[a[i].y ]==a[i].x){
cnt[a[i].y ]++;
}
}
}
mp.clear();
for(i=1;i<=10000;i++){
if(maxnum[i ]!=-1 && first[i ]!=0 ){
for(j=first[i ];j<=last[i ];j++){
temp.x=maxnum[i];temp.y=c[j].x;temp.z=c[j].y;
mp[temp]+=cnt[i];
}
}
}
memset(b,0,sizeof(b));
memset(pan,0,sizeof(pan));
int ans=0;
for(it=mp.begin();it!=mp.end();it++){
temp=it->first;
int y=temp.y;
int z=temp.z;
if(pan[y][z]==0 && cal(y,z)==0){
ans+=it->second;
}
pan[y][z]=1;
update(y,z,1);
}
cas++;
printf("Case #%d: %d\n",cas,ans);
}
return 0;
}
hdu517 Triple的更多相关文章
- 山东省第七届ACM省赛------Triple Nim
Triple Nim Time Limit: 2000MS Memory limit: 65536K 题目描述 Alice and Bob are always playing all kinds o ...
- hdu 3908 Triple(组合计数、容斥原理)
Triple Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Su ...
- hdu 5517 Triple(二维树状数组)
Triple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- Codeforces 1071 C - Triple Flips
C - Triple Flips 思路: 小范围暴力 大范围递归构造 构造方法: solve(l, r) 表示使l 到 r 区间全变为0的方法 为了使反转次数小于等于n/3 + 12 我们只需要保证每 ...
- 【BZOJ3771】Triple(生成函数,多项式运算)
[BZOJ3771]Triple(生成函数,多项式运算) 题面 有\(n\)个价值\(w\)不同的物品 可以任意选择\(1,2,3\)个组合在一起 输出能够组成的所有价值以及方案数. \(n,w< ...
- PAT 1009. Triple Inversions (35) 数状数组
Given a list of N integers A1, A2, A3,...AN, there's a famous problem to count the number of inversi ...
- 【BZOJ 3771】 3771: Triple (FFT+容斥)
3771: Triple Time Limit: 20 Sec Memory Limit: 64 MBSubmit: 547 Solved: 307 Description 我们讲一个悲伤的故事. ...
- hihoCoder #1872 : Pythagorean triple
此题是 2018 年 ICPC Asia Beijing Regional Contest 的 C 题. 题目大意 求斜边长度不超过 $n$($ n \le 10^9$) 的勾股数的数量.不计两直角边 ...
- bzoj 3771 Triple FFT 生成函数+容斥
Triple Time Limit: 20 Sec Memory Limit: 64 MBSubmit: 847 Solved: 482[Submit][Status][Discuss] Desc ...
随机推荐
- SpringBoot同时接收单个对象和List<object>参数
最近做项目的有个需求,是把多个文件移动到另一个文件夹下,这需要把 新的文件夹id -- Long类型 多个文件的信息 -- List< Object > 类型 这两个参数传给后台,我的后台 ...
- InheritableThreadlocal使用问题排查
背景 在做一个微服务系统的时候,我们的参数一般都是接在通过方法定义来进行传递的,类似这样 public void xxx(Param p, ...){ // do something } 然后这时有个 ...
- 在JavaScript种遇到这样的错误如何解决XML 解析错误:格式不佳 位置:http:/... 行 27,列 32:
相信很多人在开发的过程中都会遇到在js中解析xml文档的问题.有时候文档解析失败,但就是不知道怎么失败的,哪里格式不对.这里教大家一个方法来排查JavaScript解析xml文档格式出错的办法. 1. ...
- stat filename
查看文件的mtime,atime,ctime 3个时间
- 【Oracle】查看当前连接数和最大连接数
查看当前数据库连接数 select count(*) from v$session where username is not null; select count(*) from v$process ...
- LeetCode700. 二叉搜索树中的搜索
题目 简单递归 1 class Solution { 2 public: 3 TreeNode* searchBST(TreeNode* root, int val) { 4 if(!root) re ...
- 单片机—Arduino UNO-R3—学习笔记002
led控制 本篇主要介绍Arduino数字引脚及相关函数,通过数字I/O输出控制板载LED灯亮灭状态(数字引脚13). 数字信号是以0.1表示的电平不连续变化的信号,也就是以二进制的形式表示的信号. ...
- SAP系统跨平台字符编码转换
SAP系统在进行了夸平台的迁移,可能会遇到操作系统层文件编码不同,导致SAP系统无法识别或者乱码的问题.例如SAP系统从AIX平台迁移到linux平台,SAP应用服务器的编码会发生变化,从4102变化 ...
- 求得二叉搜索树的第k小的元素
求得二叉搜索树的第k小的元素 给定一个二叉搜索树,编写一个函数 kthSmallest 来查找其中第 k 个最小的元素. 须知:二叉搜索树,又叫二叉排序树,二叉查找树.特点是:左子树的所有元素都小于等 ...
- Percona Toolkit工具使用
Percona Toolkit简称pt工具-PT-Tools,是Percona公司开发用于管理MySQL的工具,功能包括检查主从复制的数据一致性.检查重复索引.定位IO占用高的表文件.在线DDL等 下 ...