[Solución del problema] Resumen de preguntas del cepillo OI para tumores tóxicos [SCOI2011]

[Solución del problema] Resumen de preguntas del cepillo OI para tumores tóxicos [SCOI2011]

Como el orden de las preguntas no está claro, se ordenan de acuerdo con \ (\ text {BZOJ} \) .


Un tablero de teoría de grafos de estudiantes de primaria, una estructura de datos problema de grasa, una simulación de náuseas, un tapón tumoral \ (dp \) , dos preguntas muertas, seco TAT ...


【Día1 T1】 Dulces

Portal: Candy \ (\ text {[P3275]} \) \ (\ text {[Bzoj2330]} \)

【Descripción del título】

Dadas las restricciones \ (m \) \ ((m \ leqslant 10 ^ 5) \) , las condiciones se dividen en las siguientes \ (5 \) :

\(1\ x\ y:\) \(A[x]=A[y]\)

\ (2 \ x \ y: \) \ (A [x] <A [y] \)

\(3\ x\ y:\) \(A[x]\geqslant A[y]\)

\ (4 \ x \ y: \) \ (A [x]> A [y] \)

\(5\ x\ y:\) \(A[x]\leqslant A[y]\)

Ahora necesitamos construir una secuencia legal \ (A \) de longitud \ (n \) \ ((n \ leqslant 10 ^ 5) \) , de modo que la suma de los números en la secuencia sea la más pequeña, y generar este valor mínimo, si no hay solución \ (-1 \) .

【Análisis】

No hay nada que decir sobre la pregunta de la junta restringida de diferencia, y violentamente construya un lado y huya (SPFA \) y el agua pasará.

Complejidad de tiempo: \ (O (SPFA) \) .

【Código】

#include<cstring>
#include<cstdio>
#include<queue>
#define Re register int
using namespace std;
const int N=1e5+5,M=3e5+5,inf=2e9;
int x,y,n,m,o,op,chu[N],dis[N],pan[N],head[N];long long ans;
struct QAQ{int w,to,next;}a[M];queue<int>Q;
inline void add(Re x,Re y,Re z){a[++o].to=y,a[o].w=z,a[o].next=head[x],head[x]=o;}
inline void in(Re &x){
    Re fu=0;x=0;char ch=getchar();
    while(ch<'0'||ch>'9')fu|=ch=='-',ch=getchar();
    while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    x=fu?-x:x;
}
inline int SPFA(Re st,Re ed){//求最小值跑最长路 
    for(Re i=0;i<=n;++i)dis[i]=-inf,chu[i]=0;
    dis[st]=0,chu[st]=pan[st]=1,Q.push(st);
    while(!Q.empty()){
        x=Q.front(),Q.pop();
        pan[x]=0;
        for(Re i=head[x],to;i;i=a[i].next)
            if(dis[to=a[i].to]<dis[x]+a[i].w){
                dis[to]=dis[x]+a[i].w;
                if((chu[to]=chu[x]+1)>n+1)return 1;
                if(!pan[to])pan[to]=1,Q.push(to);
            }
    }
    return 0;
}
int main(){
    in(n),in(m);
    for(Re i=n;i>=1;--i)add(0,i,1); //a[i]>=a[0]=1,a[i]-a[0]>=1
    while(m--){
        in(op),in(x),in(y);
        if(op<2)add(y,x,0),add(x,y,0);//a[x]==a[y]: a[x]-a[y]>=0且a[y]-a[x]>=0
        else if(op<3)add(x,y,1);//a[x]<a[y]: a[y]-a[x]>=1
        else if(op<4)add(y,x,0);//a[x]>=a[y]: a[x]-a[y]>=0
        else if(op<5)add(y,x,1);//a[x]>a[y]: a[x]-a[y]>=1
        else add(x,y,0);//a[x]<=a[y]: a[y]-a[x]>=0
        if(!(op%2)&&x==y){puts("-1");return 0;}
    }
    if(SPFA(0,n))puts("-1");
    else{
        for(Re i=1;i<=n;++i)ans+=dis[i];
        printf("%lld",ans);
    }
}

【Día1 T2】 Piso

Portal: Floor \ (\ text {[P3272]} \) \ (\ text {[Bzoj2331]} \)

【Descripción del título】

Ligeramente

【Análisis】

No conecte \ (dp \) , susurre primero.

【Código】

不知道这儿能放啥,干脆买个萌吧(⊙ω⊙)

[Día 1 T3] Plantas contra zombis

Portal: Plants vs. Zombies \ (\ text {[P3274]} \) \ (\ text {[Bzoj2332]} \)

【Descripción del título】

Ligeramente

【Análisis】

Parece ser un tumor de la red tumoral.

Plazo, no.

【Código】

不知道这儿能放啥,干脆买个萌吧(⊙ω⊙)

【Día2 T1】 Operación complicada

Portal: operación complicada \ (\ text {[P3273]} \) \ (\ text {[Bzoj2333]} \)

【Descripción del título】

Hay \ (n \) \ ((n \ leqslant 3 * 10 ^ 5) \) puntos que no están conectados a la fase inicial, el peso del nodo \ (i \) th es \ (a_i \) , dando \ ( m \) \ ((m \ leqslant 3 * 10 ^ 5) \) operaciones, las operaciones son las siguientes:

  • \ (U \ x \ y: \) agrega un nodo de conexión de borde \ (x \) y un nodo \ (y \) .

  • \ (A1 \ x \ v: \) Aumente el peso del nodo \ (x \) \ (v \) .

  • \ (A2 \ x \ v: \) aumenta el peso de todos los nodos en el bloque conectado donde se encuentra el nodo \ (x \) \ (v \) .

  • \ (A3 \ v: \) Aumente el peso de todos los nodos \ (v \) .

  • \ (F1 \ x: \) El peso del nodo de salida \ (x \) .

  • \ (F2 \ x: \) El peso máximo en el bloque conectado donde se encuentra el nodo de salida \ (x \) .

  • \ (F3: \) Genera el peso máximo de todos los nodos.

【Análisis】

Bingcha Ji pretratamiento + árbol de línea jugando.

Como solo hay bordes conectados y no hay bordes rotos, es posible encontrar una disposición numerada para todos los nodos, de modo que los puntos en el mismo bloque conectado en cualquier momento sean un intervalo numerado continuo.

Escriba un rango repetible y combine Bingcha Ji para preprocesar el número, y luego use el árbol de líneas para mantener.

Complejidad de tiempo: \ (O (m \ log n) \) .

【Código】

#include<algorithm>
#include<cstdio>
#include<stack>
#define LL long long
#define Re register int
using namespace std;
const int N=3e5+3,inf=2e9;
int n,T,O,A[N],id[N],idx[N];
struct QAQ{int x,y;char op[5];}a[N];
inline void in(Re &x){
    int f=0;x=0;char c=getchar();
    while(c<'0'||c>'9')f|=c=='-',c=getchar();
    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
    x=f?-x:x;
}
int fa[N],size[N];
struct QWQ{int x,fa,size;};stack<QWQ>Q;
inline int find(Re x){return fa[x]==x?x:find(fa[x]);}
inline void merge(Re x,Re y){
    if((x=find(x))==(y=find(y)))return;
    if(size[x]<size[y])swap(x,y);
    Q.push((QWQ){y,x,size[y]});
    fa[y]=x,size[x]+=size[y];
}
inline void sakura(Re o){
    if(o>T){
        for(Re i=1;i<=n;++i)if(!id[find(i)])
            id[find(i)]=++O,O+=size[find(i)]-1;
        return;
    }
    Re tmp=Q.size();
    if(a[o].op[0]=='U')merge(a[o].x,a[o].y);
    sakura(o+1);
    if(Q.size()!=tmp){
        QWQ a=Q.top();Q.pop();
        fa[a.x]=a.x,size[a.fa]-=(size[a.x]=a.size);
        id[a.x]=id[a.fa]+size[a.fa];
    }
}
struct Segment_Tree{
    #define pl (p<<1)
    #define pr (p<<1|1)
    #define mid ((L+R)>>1)
    struct QAQ{int max,add;}tr[N<<2];
    inline void build(Re p,Re L,Re R){
        if(L==R){tr[p].max=A[idx[L]];return;}
        build(pl,L,mid),build(pr,mid+1,R);
        tr[p].max=max(tr[pl].max,tr[pr].max);
    }
    inline void updata(Re p,Re v){tr[p].max+=v,tr[p].add+=v;}
    inline void pushdown(Re p){
        if(tr[p].add)updata(pl,tr[p].add),updata(pr,tr[p].add),tr[p].add=0;
    }
    inline void change(Re p,Re L,Re R,Re l,Re r,Re v){
        if(l<=L&&R<=r){updata(p,v);return;}
        pushdown(p);
        if(l<=mid)change(pl,L,mid,l,r,v);
        if(r>mid)change(pr,mid+1,R,l,r,v);
        tr[p].max=max(tr[pl].max,tr[pr].max);
    }
    inline int ask(Re p,Re L,Re R,Re l,Re r){
        if(l<=L&&R<=r)return tr[p].max;
        Re ans=-inf;pushdown(p);
        if(l<=mid)ans=max(ans,ask(pl,L,mid,l,r));
        if(r>mid)ans=max(ans,ask(pr,mid+1,R,l,r));
        return ans;
    }
}TR;
#define op0 a[i].op[0]
#define op1 a[i].op[1]
int main(){
//    freopen("123.txt","r",stdin);
    in(n);
    for(Re i=1;i<=n;++i)in(A[i]),fa[i]=i,size[i]=1;
    in(T);
    for(Re i=1;i<=T;++i){
        scanf("%s",a[i].op);
        if(a[i].op[0]=='F'&&a[i].op[1]=='3')continue;
        in(a[i].x);
        if(a[i].op[0]=='U'||(a[i].op[0]=='A'&&a[i].op[1]!='3'))in(a[i].y);
    }
    sakura(1);
    for(Re i=1;i<=n;++i)idx[id[i]]=i;
    TR.build(1,1,n);
    for(Re i=1,dlt=0;i<=T;++i){
        if(op0=='U')merge(a[i].x,a[i].y);
        else if(op0=='A'){
            if(op1=='1')TR.change(1,1,n,id[a[i].x],id[a[i].x],a[i].y);
            else if(op1=='2')a[i].x=find(a[i].x),TR.change(1,1,n,id[a[i].x],id[a[i].x]+size[a[i].x]-1,a[i].y);
            else dlt+=a[i].x;
        }
        else{
            if(op1=='1')printf("%d\n",dlt+TR.ask(1,1,n,id[a[i].x],id[a[i].x]));
            else if(op1=='2')a[i].x=find(a[i].x),printf("%d\n",dlt+TR.ask(1,1,n,id[a[i].x],id[a[i].x]+size[a[i].x]-1));
            else printf("%d\n",dlt+TR.tr[1].max);
        }
    }
}

[Día2 T2] Espejo dividido

Portal: división de espejo \ (\ text {[P3276]} \) \ (\ text {[Bzoj2334]} \)

【Descripción del título】

Ligeramente

【Análisis】

Parece ser un tumor digital \ (dp \) .

Plazo, no.

【Código】

不知道这儿能放啥,干脆买个萌吧(⊙ω⊙)

[Día 2 T3] Dardos

Portal: Darts \ (\ text {[P3277]} \) \ (\ text {[Bzoj2335]} \)

【Descripción del título】

Ligeramente

【Análisis】

Problema de simulación de tumor matemático, asqueroso, no quiero hacer.

【Código】

不知道这儿能放啥,干脆买个萌吧(⊙ω⊙)

Supongo que te gusta

Origin www.cnblogs.com/Xing-Ling/p/12708360.html
Recomendado
Clasificación