zoukankan      html  css  js  c++  java
  • Codeforces Round #460 D. Karen and Cards

    Description

    Karen just got home from the supermarket, and is getting ready to go to sleep.
    图片
    After taking a shower and changing into her pajamas, she looked at her shelf and saw an album. Curious, she opened it and saw a trading card collection.
    She recalled that she used to play with those cards as a child, and, although she is now grown-up, she still wonders a few things about it.
    Each card has three characteristics: strength, defense and speed. The values of all characteristics of all cards are positive integers. The maximum possible strength any card can have is p, the maximum possible defense is q and the maximum possible speed is r.
    There are n cards in her collection. The i-th card has a strength ai, defense bi and speed ci, respectively.
    A card beats another card if at least two of its characteristics are strictly greater than the corresponding characteristics of the other card.
    She now wonders how many different cards can beat all the cards in her collection. Two cards are considered different if at least one of their characteristics have different values.
    题面

    Solution

    考虑枚举一维,假设枚举(c),讨论(c)与某个(c_i)的关系
    如果(c>c_i)那么 (a>a_i | b>b_i),满足一项即可
    如果(c<=c_i),需满足 (a>a_i & b>b_i)
    这两个条件分别对应 矩形去掉一个小矩形 和 矩形 这两种图形

    考虑多个矩形的情况:
    如果所有矩形都是情况1,那么情况(1)就是所有矩形的并的补集
    按第一维排序之后,第二位一定是递减序列,用一个单调栈即可维护

    如果c取(maxc)的时候,得出的图形就是上面所求出的
    考虑c减少时的情况,那么就会出现情况2
    原图形就变成一个矩形和剩余矩形的交
    我们可以通过减去补集来求出
    按卡片的c属性从大到小枚举,维护轮廓即可

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N=500010;
    int n,A,B,C;
    struct node{
    	int a,b,c;
    }p[N];
    inline bool ca(const node &i,const node &j){
    	if(i.a!=j.a)return i.a<j.a;
    	return i.b<j.b;
    }
    inline bool cc(const node &i,const node &j){return i.c>j.c;}
    int st[N],top=0,bx[N],by[N];
    int main(){
      freopen("pp.in","r",stdin);
      freopen("pp.out","w",stdout);
      scanf("%d%d%d%d",&n,&A,&B,&C);
      for(int i=1;i<=n;i++)scanf("%d%d%d",&p[i].a,&p[i].b,&p[i].c);
      sort(p+1,p+n+1,ca);
      for(int i=1;i<=n;i++){
    	  while(top && p[st[top]].b<p[i].b)top--;
    	  st[++top]=i;
      }
      ll tot=0,ans=0;st[top+1]=0;
      for(int i=1;i<=top;i++){
    	  tot+=1ll*p[st[i]].b*(p[st[i]].a-p[st[i-1]].a);
    	  for(int j=p[st[i-1]].a+1;j<=p[st[i]].a;j++)by[j]=p[st[i]].b;
    	  for(int j=p[st[i]].b;j>p[st[i+1]].b;j--)bx[j]=p[st[i]].a;
      }
      tot=1ll*A*B-tot;
      sort(p+1,p+n+1,cc);
      for(int i=C,j=1,x=1,y=1;i>=1;i--){
    	  for(;j<=n && p[j].c>=i;j++){
    		  while(x<=p[j].a)tot-=B-max(by[x],y-1),x++;
    		  while(y<=p[j].b)tot-=A-max(bx[y],x-1),y++;
    	  }
    	  ans+=tot;
      }
      cout<<ans<<endl;
      return 0;
    }
    
    
  • 相关阅读:
    RTSP协议转RTMP协议的行业视频接入网关EasyRTSPLive如何实现音频转码的
    RTSP协议转RTMP协议的行业视频接入网关EasyRTSPLive之跨平台ini配置及通道的方法
    GB/T28181协议EasyGBS播放1080p视频直播会花屏
    国标GB/T28181协议下播放器起播慢或者延迟高如何解决?
    EasyGBS查找大华设备的录像列表时失败
    ffmpeg增加h264编解码功能模块方法
    EasyNVR控制台运行出现invalid license关于计算机保护软件类似于360、腾讯云管家等限制相关问题
    摄像机经过多级路由转换无法被EasyNVR拉流问题处理方法
    使用EasyNVR软件对接海康摄像头对接失败问题解析
    GB/T28181协议使用EasyNVR降低播放延迟方法
  • 原文地址:https://www.cnblogs.com/Yuzao/p/8447425.html
Copyright © 2011-2022 走看看