zoukankan      html  css  js  c++  java
  • 寻找宝藏

    IV.VI.寻找宝藏

    又是四维偏序板子。只不过是打一遍再熟悉一下代码罢了。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    const int mod=998244353;
    int n,m;
    typedef long long ll;
    struct dat{
    	ll val;
    	int ways;
    	dat(){val=ways=0;}
    	dat(ll V,int W){val=V,ways=W;}
    	friend dat operator+(const dat&u,const dat&v){
    		dat w;
    		w.val=max(u.val,v.val);
    		if(w.val==u.val)w.ways+=u.ways;
    		if(w.val==v.val)w.ways+=v.ways;
    		w.ways%=mod;
    		return w;
    	}
    }f[80100],t[80100],res;
    void ADD(int x,dat y){while(x<=n)t[x]=t[x]+y,x+=x&-x;}
    dat SUM(int x){dat ret;while(x)ret=ret+t[x],x-=x&-x;return ret;}
    void ERA(int x){while(x<=n)t[x]=dat(),x+=x&-x;}
    struct node{
    	int a,b,c,d,id;
    	ll e;
    	bool fir;
    	friend bool operator==(const node&x,const node&y){return x.a==y.a&&x.b==y.b&&x.c==y.c&&x.d==y.d;}
    }o[80100],p[80100],q[80100];
    bool cmpa(const node&x,const node&y){
    	if(x.a!=y.a)return x.a<y.a;
    	if(x.b!=y.b)return x.b<y.b;
    	if(x.c!=y.c)return x.c<y.c;
    	return x.d<y.d;
    }
    bool cmpb(const node&x,const node&y){
    	if(x.b!=y.b)return x.b<y.b;
    	if(x.c!=y.c)return x.c<y.c;
    	if(x.d!=y.d)return x.d<y.d;
    	return x.a<y.a;
    }
    bool cmpc(const node&x,const node&y){
    	if(x.c!=y.c)return x.c<y.c;
    	if(x.d!=y.d)return x.d<y.d;
    	if(x.a!=y.a)return x.a<y.a;
    	return x.b<y.b;
    }
    void CDQ2(int l,int r){
    	if(l==r)return;
    	int mid=(l+r)>>1;
    	CDQ2(l,mid);
    	for(int i=l;i<=r;i++)q[i]=p[i];
    	sort(q+l,q+mid+1,cmpc),sort(q+mid+1,q+r+1,cmpc);
    	for(int i=l,j=mid+1;j<=r;j++){
    		for(;i<=mid&&q[i].c<=q[j].c;i++)if(q[i].fir)ADD(q[i].d,f[q[i].id]);
    		if(!q[j].fir){
    			dat tmp=SUM(q[j].d);tmp.val+=q[j].e;
    			f[q[j].id]=f[q[j].id]+tmp;
    		}
    	}
    	for(int i=l;i<=mid;i++)if(q[i].fir)ERA(q[i].d);
    	CDQ2(mid+1,r);
    }
    void CDQ1(int l,int r){
    	if(l==r){res=res+f[o[l].id];return;}
    	int mid=(l+r)>>1;
    	CDQ1(l,mid);
    	for(int i=l;i<=r;i++)p[i]=o[i];
    	for(int i=l;i<=mid;i++)p[i].fir=true;
    	sort(p+l,p+r+1,cmpb);
    	CDQ2(l,r);
    	CDQ1(mid+1,r);
    }
    vector<int>v;
    int main(){
    	scanf("%d%d",&n,&m);
    	for(int i=1;i<=n;i++)scanf("%d%d%d%d%lld",&o[i].a,&o[i].b,&o[i].c,&o[i].d,&o[i].e);
    	sort(o+1,o+n+1,cmpa),m=1;
    	for(int i=2;i<=n;i++)if(o[m]==o[i])o[m].e+=o[i].e;else o[++m]=o[i];
    	n=m;
    	for(int i=1;i<=n;i++)v.push_back(o[i].d);
    	sort(v.begin(),v.end()),v.resize(m=unique(v.begin(),v.end())-v.begin());
    	for(int i=1;i<=n;i++)o[i].d=lower_bound(v.begin(),v.end(),o[i].d)-v.begin()+1,f[i]=dat(o[i].e,1),o[i].id=i;
    	CDQ1(1,n);
    	printf("%lld\n%d\n",res.val,res.ways);
    	return 0;
    }
    

  • 相关阅读:
    windows计数器和瓶颈
    SQL Server 2005的Resource数据库
    Android学习笔记 json数据的解析
    android的消息处理机制(图+源码分析)——Looper,Handler,Message
    JS刷新验证码
    Java取得Unix的timestamp
    (转载)DBMS_SQL package 学习
    关于Java中Http下载的一些整理
    (转载)sqlserver内存释放
    关于EL表达式
  • 原文地址:https://www.cnblogs.com/Troverld/p/14620835.html
Copyright © 2011-2022 走看看