zoukankan      html  css  js  c++  java
  • D

    题意 贴海报 最后可以看到多少海报

    思路 :离散化大区间  其中[1,4] [5,6]不能离散化成[1,2] [2,3]因为这样破坏了他们的非相邻关系 每次离散化区间 [x,y]时  把y+1点也加入就行了

    注:参考了上海全能王csl的博客!

      1 #include<cstdio>
      2 #include<algorithm>
      3 #include<set>
      4 #include<vector>
      5 #include<cstring>
      6 #include<iostream>
      7 using namespace std;
      8 #define X first 
      9 #define Y second 
     10 const int maxn=200000+5;
     11 pair<int,int>a[maxn*2];
     12 vector<int>v;
     13 struct Node{
     14     int l,r;
     15     int col;
     16     int lazy;
     17     void update(int x){
     18         col=x;
     19         lazy=x;
     20     }
     21 }tree[maxn*6];
     22 bool vis[maxn*2];
     23 /*void push_up(int x){
     24     if(tree[x<<1].col!=tree[x<<1|1].col||tree[x<<1].col==-1||tree[x<<1|1].col==-1)tree[x].col=-1;
     25 }*/
     26 
     27 void build(int x,int l,int r){
     28     tree[x].l=l,tree[x].r=r;
     29     tree[x].col=-1;    
     30     if(l==r){
     31         return ;
     32     }
     33     else {
     34         int mid=l+r>>1;
     35         build(x<<1,l,mid);
     36         build(x<<1|1,mid+1,r);
     37     }
     38 }
     39 
     40 void push_down(int x){
     41     if(tree[x].col==-1)return;
     42     tree[x<<1].col=tree[x<<1|1].col=tree[x].col;
     43     tree[x].col=-1;
     44 }
     45 void update(int x,int l,int r,int val){
     46     int L=tree[x].l,R=tree[x].r;
     47     if(l<=L&&R<=r){
     48         tree[x].col=val;
     49         return ;
     50     }
     51     else {
     52         push_down(x);
     53         int mid=(L+R)>>1;
     54         if(l<=mid)update(x<<1,l,r,val);
     55         if(mid<r)update(x<<1|1,l,r,val);
     56     //    pudh_up(x);单点查询不需要合并
     57     }
     58 }
     59 long long query(int x,int a){
     60     int L=tree[x].l,R=tree[x].r;
     61     if(L==R)return tree[x].col;
     62     push_down(x);
     63     int mid=L+R>>1;
     64     if(mid>=a)query(x<<1,a);
     65     else if(mid<a)query(x<<1|1,a);
     66 }
     67 
     68 int main(){
     69     int t;
     70     scanf("%d",&t);
     71     while(t--){
     72         int n;
     73         memset(vis,0,sizeof(vis));
     74         scanf("%d",&n);
     75         for(int i=0;i<n;i++){
     76             scanf("%d%d",&a[i].X,&a[i].Y);
     77             v.push_back(a[i].X);
     78             v.push_back(a[i].Y);
     79             v.push_back(a[i].Y+1);
     80         }
     81     sort(v.begin(),v.end());
     82     int num=unique(v.begin(),v.end())-v.begin();
     83     for(int i=0;i<n;i++){
     84       a[i].X = lower_bound(v.begin(), v.begin() + num, a[i].X) - v.begin() + 1;
     85       a[i].Y = lower_bound(v.begin(), v.begin() + num, a[i].Y) - v.begin() + 1;
     86     }
     87     build(1,1,num);
     88     for(int i=0;i<n;i++){
     89         update(1,a[i].X,a[i].Y,i+1);
     90     }
     91     int ans=0;
     92     for(int i=1;i<=num;i++){
     93         int col=query(1,i);
     94     //    cout<<col<<endl;
     95         if(col!=-1&&vis[col]==0){
     96             vis[col]=1;
     97             ans++;
     98         }
     99     }
    100     printf("%d
    ",ans);
    101     }
    102     return 0;
    103 }
  • 相关阅读:
    [总结]链表与栈
    统计学基础知识
    图卷积神经网络(GCN)入门
    [总结]字符串
    [总结]数组
    [总结]排序算法分析与实现
    [Leetcode]307. Range Sum Query
    深度解析Droupout与Batch Normalization
    深度解析Graph Embedding
    Console命令,让js调试更简单
  • 原文地址:https://www.cnblogs.com/ttttttttrx/p/10301717.html
Copyright © 2011-2022 走看看