[Problem Solution] Summary of OI Brush Questions for Toxic Tumors [SCOI2011]

[Problem Solution] Summary of OI Brush Questions for Toxic Tumors [SCOI2011]

Since the order of the questions is not clear, they are arranged according to \ (\ text {BZOJ} \) .


A primary school student graph theory board, a data structure fat problem, a nausea simulation, a tumor plug \ (dp \) , two dead questions, I dry TAT ...


【Day1 T1】 Candy

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

【Title description】

Given \ (m \) \ ((m \ leqslant 10 ^ 5) \) constraints, the conditions are divided into the following \ (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] \)

Now we need to construct a legal sequence \ (A \) of length \ (n \) \ ((n \ leqslant 10 ^ 5) \) , so that the sum of the numbers in the sequence is the smallest, and output this minimum value, if there is no solution \ (-1 \) .

【analysis】

There is nothing to say about the difference constrained board question, and violently build a side and run away (SPFA \) and the water will pass.

Time complexity: \ (O (SPFA) \) .

【Code】

#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);
    }
}

【Day1 T2】 Floor

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

【Title description】

slightly.

【analysis】

Don't plug \ (dp \) , whisper first.

【Code】

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

[Day1 T3] Plants vs. Zombies

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

【Title description】

slightly.

【analysis】

It seems to be a tumor network tumor.

Deadline, no.

【Code】

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

【Day2 T1】 Tricky operation

Portal: tricky operation \ (\ text {[P3273]} \) \ (\ text {[Bzoj2333]} \)

【Title description】

There are \ (n \) \ ((n \ leqslant 3 * 10 ^ 5) \) points that are not connected to the initial phase, the weight of the \ (i \) th node is \ (a_i \) , giving \ ( m \) \ ((m \ leqslant 3 * 10 ^ 5) \) operations, the operations are as follows:

  • \ (U \ x \ y: \) adds an edge connecting node \ (x \) and node \ (y \) .

  • \ (A1 \ x \ v: \) Increase the weight of node \ (x \) \ (v \) .

  • \ (A2 \ x \ v: \) increases the weight of all nodes in the connected block where node \ (x \) is located \ (v \) .

  • \ (A3 \ v: \) Increase the weight of all nodes \ (v \) .

  • \ (F1 \ x: \) The weight of the output node \ (x \) .

  • \ (F2 \ x: \) The maximum weight in the connected block where the output node \ (x \) is located.

  • \ (F3: \) Output the maximum weight of all nodes.

【analysis】

Bingcha Ji pretreatment + line tree messing around.

Since there are only connected edges and no broken edges, it is possible to find a numbered arrangement for all nodes, so that the points in the same connected block at any time are a continuous numbered interval.

Write a retreatable rank and merge Bingcha Ji to pre-process the number, and then use the line tree to maintain.

Time complexity: \ (O (m \ log n) \) .

【Code】

#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);
        }
    }
}

[Day2 T2] Mirror split

Portal: mirror split \ (\ text {[P3276]} \) \ (\ text {[Bzoj2334]} \)

【Title description】

slightly.

【analysis】

It seems to be a digital tumor \ (dp \) .

Deadline, no.

【Code】

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

[Day2 T3] Darts

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

【Title description】

slightly.

【analysis】

Math tumor simulation problem, disgusting, do not want to do.

【Code】

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

Guess you like

Origin www.cnblogs.com/Xing-Ling/p/12708360.html