50wa求调

P3740 [HAOI2014] 贴海报

Miss_SGT @ 2023-05-03 00:18:39

#include<bits/stdc++.h>
using namespace std;
int n,m,c[10000005][2];
struct cz{int x,f,v;}e[200005]; 
int t[400005];
bool cmp(cz a,cz b){return a.v<b.v;}
inline void down(int p){
    if(t[p]){
        t[2*p]=t[2*p+1]=t[p];
        t[p]=0;
    }
}
void change(int p,int lt,int rt,int l,int r,int vs){
    if(l<=lt&&rt<=r){
        t[p]=vs;
        return;
    }int mid=(lt+rt)>>1;
    down(p);
    if(l<=mid) change(2*p,lt,mid,l,r,vs);
    if(mid+1<=r) change(2*p+1,mid+1,rt,l,r,vs);
}
int get(int p,int lt,int rt,int x){
    if(lt==rt) return t[p];
    down(p);
    int mid=(lt+rt)>>1;
    if(x<=mid) return get(2*p,lt,mid,x);
    return get(2*p+1,mid+1,rt,x);
}int col,ans;
bool vis[100005]={1,0};
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&e[i].v,&e[i+m].v);
        e[i].x=e[i+m].x=i;
        e[i].f=0;
        e[i+m].f=1;
    }n=1;
    sort(e+1,e+m*2+1,cmp);
    for(int i=1;i<=m*2;i++){
        if(e[i].v!=e[i-1].v) n+=2;
        c[e[i].x][e[i].f]=n;
    }
    for(int i=1;i<=m;i++)
        change(1,1,n,c[i][0],c[i][1],i);
    for(int i=1;i<=n;i++){
        col=get(1,1,n,i);
        if(!vis[col]){
            vis[col]=1;
            ans++;
        }
    }printf("%d",ans);
    return 0;
}

by Miss_SGT @ 2023-05-03 00:21:41

数据太水很难受,那暴力总共才跑70ms,评测机吃了金坷垃吗


|