其他分享
首页 > 其他分享> > 【JZOJ6273】欠钱

【JZOJ6273】欠钱

作者:互联网

description


analysis


code

#pragma GCC optimize("O3")
#pragma G++ optimize("O3")
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<cctype>
#define MAXN 100005
#define INF 1000000007
#define reg register int
#define max(x,y) ((x>y)?(x):(y))
#define min(x,y) ((x<y)?(x):(y))
#define fo(i,a,b) for (reg i=a;i<=b;++i)
#define fd(i,a,b) for (reg i=a;i>=b;--i)

using namespace std;

int tr[MAXN*2][2];
int fa[MAXN*2],pf[MAXN*2],st[MAXN*2],fat[MAXN];
int n,m,lastans,cnt,pos,root;
bool flag,bz;

struct node
{
    int val,mn;
    bool rev;
}a[MAXN*2];
__attribute__((optimize("-O3")))
inline char getcha()
{
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
__attribute__((optimize("-O3")))
inline int read()
{
    int res=0;char ch=getcha();bool XX=false;
    for(;!isdigit(ch);ch=getcha())
    (ch=='-') && (XX=true);
    for(;isdigit(ch);ch=getcha())
    res=(res<<3)+(res<<1)+(ch^48);
    return XX?-res:res;
}
__attribute__((optimize("-O3")))
inline void write(int x)  
{  
    int num=0;static char c[15];
    while (x)c[++num]=(x%10)+48,x/=10;
    while (num)putchar(c[num--]);
    putchar('\n'); 
}
__attribute__((optimize("-O3")))
inline void swap(int &x,int &y){int z=x;x=y,y=z;}
__attribute__((optimize("-O3")))
inline int getfa(int x){return fat[x]==x?x:fat[x]=getfa(fat[x]);}
__attribute__((optimize("-O3")))
inline void update(int x)
{
    if (x)a[x].mn=min(a[x].val,min(a[tr[x][0]].mn,a[tr[x][1]].mn));
}
__attribute__((optimize("-O3")))
inline void reverse(int x)
{
    if (x)a[x].rev^=1,swap(tr[x][0],tr[x][1]);
}
__attribute__((optimize("-O3")))
inline void down(int x)
{
    if (a[x].rev)
    {
        reverse(tr[x][0]),reverse(tr[x][1]);
        a[x].rev=0;
    }
}
__attribute__((optimize("-O3")))
inline void downdata(int x)
{
    while (x)st[++st[0]]=x,x=fa[x];
    while (st[0])down(st[st[0]--]);
}
__attribute__((optimize("-O3")))
inline int lr(int x)
{
    return tr[fa[x]][1]==x;
}
__attribute__((optimize("-O3")))
inline void rotate(int x)
{
    int y=fa[x],k=lr(x);
    tr[y][k]=tr[x][!k];
    if (tr[x][!k])fa[tr[x][!k]]=y;
    fa[x]=fa[y];if (fa[y])tr[fa[y]][lr(y)]=x;
    tr[x][!k]=y,fa[y]=x,pf[x]=pf[y];
    update(y),update(x);
}
__attribute__((optimize("-O3")))
inline void splay(int x,int y)
{
    downdata(x);
    while (fa[x]!=y)
    {
        if (fa[fa[x]]!=y)rotate(lr(fa[x])==lr(x)?fa[x]:x);
        rotate(x);
    }
}
__attribute__((optimize("-O3")))
inline void access(int x)
{
    for (int y=0;x;update(x),y=x,x=pf[x])
    {
        splay(x,0);
        fa[tr[x][1]]=0,pf[tr[x][1]]=x;
        tr[x][1]=y,fa[y]=x,pf[y]=0;
    }
}
__attribute__((optimize("-O3")))
inline void makeroot(int x)
{
    access(x),splay(x,0),reverse(x);
}
__attribute__((optimize("-O3")))
inline void link(int x,int y)
{
    makeroot(x),pf[x]=y;
}
__attribute__((optimize("-O3")))
inline bool judge(int x,int y)
{
    access(x),access(y),splay(x,0);
    return pf[x]==y;
}
int main()
{
    //freopen("T3.in","r",stdin);
    freopen("money.in","r",stdin);
    freopen("money.out","w",stdout);
    n=read(),m=read();
    fo(i,0,n)a[i].mn=a[i].val=INF,fat[i]=i;
    while (m--)
    {
        int type=read(),x=(read()+lastans)%n+1,y=(read()+lastans)%n+1,z;
        if (!type)
        {
            if (!root || root==x)root=y;
            z=(read()+lastans)%n+1,++cnt;
            link(x,n+cnt),link(n+cnt,y);
            a[n+cnt].mn=a[n+cnt].val=z;
            fat[getfa(x)]=getfa(y);
        }
        else
        {
            if (getfa(x)==getfa(y) && judge(x,y))
            {
                makeroot(y),access(x),splay(x,0);
                write(a[x].mn),lastans=a[x].mn,makeroot(root);
            }
            else printf("0\n"),lastans=0;
        }
    }
    return 0;
}

标签:GCC,ch,int,欠钱,MAXN,JZOJ6273,pragma,optimize
来源: https://www.cnblogs.com/horizonwd/p/11299905.html