zoukankan      html  css  js  c++  java
  • hdu4742 Pinball Game 3D

    真他娘的搞不懂cdq分治的顺序问题。但是candy?的博客里提到过,多想想吧……

    #include <algorithm>
    #include <iostream>
    #include <cstdio>
    using namespace std;
    typedef pair<int,int> par;
    int T, n, num[100005], tot;
    const int mod=1<<30;
    par ans[100005], c[100005];
    struct Node{
    	int x, y, z, id;
    }a[100005], b[100005];
    bool cmp(Node u, Node v){
    	if(u.x!=v.x)	return u.x<v.x;
    	else if(u.y!=v.y)	return u.y<v.y;
    	else	return u.z<v.z;
    }
    bool cmp2(Node u, Node v){
    	if(u.y!=v.y)	return u.y<v.y;
    	else	return u.z<v.z;
    }
    int lb(int x){
    	return x & -x;
    }
    void getRet(par &x, par y){
    	if(x.first<y.first)	x = y;
    	else if(x.first==y.first)
    		x.second = (x.second + y.second) % mod;
    }
    void add(int x, par y){
    	for(; x<=tot; x+=lb(x))
    		getRet(c[x], y);
    }
    par query(int x){
    	par re=par(0, 0);
    	for(; x; x-=lb(x))
    		getRet(re, c[x]);
    	return re;
    }
    void clr(int x){
    	for(; x<=tot; x+=lb(x))
    		c[x] = par(0, 0);
    }
    void cdq(int l, int r){
    	if(l==r)	return ;
    	int mid=(l+r)>>1;
    	cdq(l, mid);
    	for(int i=l; i<=r; i++)
    		b[i] = a[i];
    	sort(b+l, b+1+r, cmp2);
    	for(int i=l; i<=r; i++){
    		if(b[i].id<=mid)
    			add(b[i].z, ans[b[i].id]);
    		else{
    			par tmp=query(b[i].z);
    			tmp.first++;
    			getRet(ans[b[i].id], tmp);
    		}
    	}
    	for(int i=l; i<=r; i++)
    		if(b[i].id<=mid)
    			clr(b[i].z);
    	cdq(mid+1, r);
    }
    int main(){
    	cin>>T;
    	while(T--){
    		scanf("%d", &n);
    		for(int i=1; i<=n; i++){
    			scanf("%d %d %d", &a[i].x, &a[i].y, &a[i].z);
    			num[i] = a[i].z;
    		}
    		sort(num+1, num+1+n);
    		tot = unique(num+1, num+1+n) - num - 1;
    		sort(a+1, a+1+n, cmp);
    		for(int i=1; i<=n; i++){
    			a[i].id = i;
    			ans[i] = par(1, 1);
    			a[i].z = lower_bound(num+1, num+1+tot, a[i].z) - num;
    		}
    		cdq(1, n);
    		par tmp=par(0, 0);
    		for(int i=1; i<=n; i++)
    			getRet(tmp, ans[i]);
    		printf("%d %d
    ", tmp.first, tmp.second);
    	}
    	return 0;
    }
    
  • 相关阅读:
    ElasticSearch 概念解析
    CSS Selector (part 1)
    ruby 把字符串转为正则匹配表达式
    SQL ISNULL应用
    logstash input jdbc连接数据库
    Logstash add_field 参数应用
    函数返回局部变量/局部指针
    内存四区模型
    释放内存触发断点及数组、指针的NULL初始化
    动态分配内存
  • 原文地址:https://www.cnblogs.com/poorpool/p/9158417.html
Copyright © 2011-2022 走看看