zoukankan      html  css  js  c++  java
  • 【线段树】BAPC2014 E Excellent Engineers (Codeforces GYM 100526)

    题目链接:

      http://codeforces.com/gym/100526

      http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11668&courseid=0

    题目大意:

      N个人,每个人有三个能力排名X Y Z,每种能力没有同名次,如果当前的人比在清单上的人中至少有一项能力都要优,则这个人也会被加到清单上。

      求最终清单上有几个人。(N<=100000)

    题目思路:

      【线段树】

      首先按第三关键字排序,确定一维的大小关系,接下来如果(X,Y)中的其中一个比之前的人都要优,则这个人就会被添加。

      考虑用a[X]表示1到X中最小的Y值,则只需要比较Y和a[X]的大小就能确定出是否需要添加这个人。

      用线段树记录区间最小Y值,并且实时更新。

     1 //
     2 //by coolxxx
     3 //#include<bits/stdc++.h>
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<string>
     7 #include<iomanip>
     8 #include<map>
     9 #include<memory.h>
    10 #include<time.h>
    11 #include<stdio.h>
    12 #include<stdlib.h>
    13 #include<string.h>
    14 //#include<stdbool.h>
    15 #include<math.h>
    16 #define min(a,b) ((a)<(b)?(a):(b))
    17 #define max(a,b) ((a)>(b)?(a):(b))
    18 #define abs(a) ((a)>0?(a):(-(a)))
    19 #define lowbit(a) (a&(-a))
    20 #define sqr(a) ((a)*(a))
    21 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
    22 #define mem(a,b) memset(a,b,sizeof(a))
    23 #define eps (1e-8)
    24 #define J 10
    25 #define mod 1000000007
    26 #define MAX 0x7f7f7f7f
    27 #define PI 3.14159265358979323
    28 #define N 100004
    29 using namespace std;
    30 typedef long long LL;
    31 int cas,cass;
    32 int n,m,lll,ans;
    33 struct xxx
    34 {
    35     int x,y,z;
    36 }a[N];
    37 int t[N<<2];
    38 bool cmp(xxx aa,xxx bb)
    39 {
    40     return aa.x<bb.x;
    41 }
    42 void change(int l,int r,int x,int c,int k)
    43 {
    44     if(l>r || x<l || x>r)return;
    45     if(l==r){t[k]=c;return;}
    46     change(l,(l+r)>>1,x,c,k+k);
    47     change((l+r)/2+1,r,x,c,k+k+1);
    48     t[k]=min(t[k+k],t[k+k+1]);
    49 }
    50 int query(int l,int r,int a,int b,int k)
    51 {
    52     if(l>r || l>b || r<a)return MAX;
    53     if(a<=l && r<=b)return t[k];
    54     int x1=query(l,(l+r)>>1,a,b,k+k),x2=query((l+r)/2+1,r,a,b,k+k+1);
    55     return t[k]=min(x1,x2);
    56 }
    57 int main()
    58 {
    59     #ifndef ONLINE_JUDGE
    60 //    freopen("1.txt","r",stdin);
    61 //    freopen("2.txt","w",stdout);
    62     #endif
    63     int i,j,k;
    64     for(scanf("%d",&cas);cas;cas--)
    65 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
    66 //    while(~scanf("%s",s+1))
    67 //    while(~scanf("%d",&n))
    68     {
    69         ans=1;mem(t,0x7f);
    70         scanf("%d",&n);
    71         for(i=1;i<=n;i++)
    72             scanf("%d%d%d",&a[i].y,&a[i].z,&a[i].x);
    73         sort(a+1,a+1+n,cmp);
    74         change(1,n,a[1].y,a[1].z,1);
    75         for(i=2;i<=n;i++)
    76         {
    77             j=query(1,n,1,a[i].y,1);
    78             if(j>a[i].z)ans++;
    79             change(1,n,a[i].y,a[i].z,1);
    80         }
    81         printf("%d
    ",ans);
    82     }
    83     return 0;
    84 }
    85 /*
    86 //
    87 
    88 //
    89 */
    View Code
  • 相关阅读:
    init进程解析rc文件的相关函数分析
    Ubuntu 安装Android Studio与使用手册
    Vim的撤销与重做
    Vim 配色设置与配色脚本语法
    js常用的语句
    xshell常用的命令
    java常用的语句
    maven工程配置日志
    根据一个oss的pdf文件的 地址转换成一个File文件
    根据一个oss的地址把图片转换成一个文件
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/5807925.html
Copyright © 2011-2022 走看看