QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#406006#4914. Slight Hope2745518585Compile Error//C++205.8kb2024-05-06 18:34:102024-05-06 18:34:12

Judging History

你现在查看的是最新测评结果

  • [2024-05-06 18:34:12]
  • 评测
  • [2024-05-06 18:34:10]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#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<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
inline char gc()
{
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
template<typename T> inline void read(T &x)
{
    T u=1,t=0;char c=gc();
    while(c<'0'||c>'9') {if(c=='-') u=-1; c=gc();}
    while(c>='0'&&c<='9') t*=10,t+=c-'0',c=gc();
    x=u*t;return;
}
template<typename T,typename ...O> inline void read(T &x,O &...o) {read(x),read(o...);}
template<typename T> inline void print(T x)
{
    if(x==0) return putchar('0'),void();
    if(x<0) putchar('-'),x=-x;
    int c[129]={0},k=0;
    while(x) c[++k]=x%10,x/=10;
    for(int i=k;i;--i) putchar(c[i]+'0');
}
template<typename T,typename ...O> inline void print(T x,O ...o) {print(x),putchar(' '),print(o...);}
const int N=250001,M=600;
const ll P=998244353;
int n,m,a[N],b[N],c[N],*f[N/M+1],*g[N/M+1],h[N];
namespace tc
{
    int lg[N];
    vector<int> a[N],fa1[N],fa2[N];
    struct tree
    {
        int f,l,d,t,z,fa[21];
    }T[N];
    void dfs1(int x)
    {
        T[x].l=1;
        T[x].d=T[T[x].f].d+1;
        T[x].fa[0]=T[x].f;
        for(int i=1;i<=20;++i)
        {
            T[x].fa[i]=T[T[x].fa[i-1]].fa[i-1];
        }
        for(auto i:a[x])
        {
            if(i==T[x].f) continue;
            T[i].f=x;
            dfs1(i);
            if(T[i].l+1>T[x].l)
            {
                T[x].l=T[i].l+1;
                T[x].z=i;
            }
        }
    }
    void dfs2(int x,int k)
    {
        fa2[k].push_back(x);
        T[x].t=k;
        for(auto i:a[x])
        {
            if(i==T[x].f) continue;
            if(i==T[x].z) dfs2(i,k);
            else
            {
                fa1[i].push_back(i);
                for(int j=1;j<=T[i].l;++j)
                {
                    fa1[i].push_back(T[fa1[i].back()].f);
                }
                dfs2(i,i);
            }
        }
    }
    int get(int x,int k)
    {
        if(k==0) return x;
        int q=T[x].d-k;
        x=T[T[x].fa[lg[k]]].t;
        if(T[x].d<q) return fa2[x][q-T[x].d];
        else return fa1[x][T[x].d-q];
        return x;
    }
    void init()
    {
        for(int i=2;i<=n;++i)
        {
            a[b[i]].push_back(i);
        }
        dfs1(1);
        fa1[1].push_back(1);
        for(int i=1;i<=T[1].l;++i)
        {
            fa1[1].push_back(T[fa1[1].back()].f);
        }
        dfs2(1,1);
        for(int i=0;i<=20;++i)
        {
            for(int j=(1<<i);j<=min((1<<(i+1))-1,n);++j) lg[j]=i;
        }
    }
    int find(int x,int l,int r)
    {
        int z=get(x,T[x].d-(T[l].d+1));
        if(z<=c[l]) return z;
        else return b[z];
    }
}
int main()
{
    read(n,m);
    for(int i=1;i<=n;++i) read(a[i]);
    for(int i=2;i<=n;++i) read(b[i]);
    tc::init();
    for(int i=1;i<=n;++i)
    {
        c[i]=c[i-1];
        while(c[i]<=n&&b[c[i]+1]<i) ++c[i];
    }
    for(int i=0;i<=n/M;++i)
    {
        f[i]=new int[(i+1)*M+10];
        g[i]=new int[(i+1)*M+10];
        f[i][0]=g[i][0]=0;
        for(int j=1;j<=min((i+1)*M,n);++j) f[i][j]=a[j];
        for(int j=i*M;j>=1;--j) f[i][b[j]]=(f[i][b[j]]+f[i][j])%P;
        for(int j=1;j<=min((i+1)*M,n);++j) g[i][j]=(g[i][j-1]+(ll)f[i][j]*f[i][j])%P;
    }
    int las=0;
    for(int i=1;i<=m;++i)
    {
        int l,r;
        read(l,r);
        l^=las,r^=las;
        int p=r/M;
        ll s=(g[p][min(r,c[l])]-g[p][l-1])%P;
        for(int j=max(p*M,c[l])+1;j<=r;++j)
        {
            int x=tc::find(j,l,r);
            s+=((ll)f[p][x]*2+a[j])*a[j]%P;
            f[p][x]=(f[p][x]+a[j])%P;
            h[j]=x;
        }
        for(int j=max(p*M,c[l])+1;j<=r;++j)
        {
            f[p][h[j]]=(f[p][h[j]]-a[j])%P;
        }
        print(las=((s%P+P)%P));
        putchar('\n');
    }
    return 0;
}

Details

answer.code:22:39: warning: bad option ‘-fwhole-program’ to pragma ‘optimize’ [-Wpragmas]
   22 | #pragma GCC optimize("-fwhole-program")
      |                                       ^
answer.code:29:41: warning: bad option ‘-fstrict-overflow’ to pragma ‘optimize’ [-Wpragmas]
   29 | #pragma GCC optimize("-fstrict-overflow")
      |                                         ^
answer.code:31:41: warning: bad option ‘-fcse-skip-blocks’ to pragma ‘optimize’ [-Wpragmas]
   31 | #pragma GCC optimize("-fcse-skip-blocks")
      |                                         ^
answer.code:45:51: warning: bad option ‘-funsafe-loop-optimizations’ to pragma ‘optimize’ [-Wpragmas]
   45 | #pragma GCC optimize("-funsafe-loop-optimizations")
      |                                                   ^
answer.code:53:16: warning: bad option ‘-fwhole-program’ to attribute ‘optimize’ [-Wattributes]
   53 | inline char gc()
      |                ^
answer.code:53:16: warning: bad option ‘-fstrict-overflow’ to attribute ‘optimize’ [-Wattributes]
answer.code:53:16: warning: bad option ‘-fcse-skip-blocks’ to attribute ‘optimize’ [-Wattributes]
answer.code:53:16: warning: bad option ‘-funsafe-loop-optimizations’ to attribute ‘optimize’ [-Wattributes]
answer.code:58:43: warning: bad option ‘-fwhole-program’ to attribute ‘optimize’ [-Wattributes]
   58 | template<typename T> inline void read(T &x)
      |                                           ^
answer.code:58:43: warning: bad option ‘-fstrict-overflow’ to attribute ‘optimize’ [-Wattributes]
answer.code:58:43: warning: bad option ‘-fcse-skip-blocks’ to attribute ‘optimize’ [-Wattributes]
answer.code:58:43: warning: bad option ‘-funsafe-loop-optimizations’ to attribute ‘optimize’ [-Wattributes]
answer.code:65:65: warning: bad option ‘-fwhole-program’ to attribute ‘optimize’ [-Wattributes]
   65 | template<typename T,typename ...O> inline void read(T &x,O &...o) {read(x),read(o...);}
      |                                                                 ^
answer.code:65:65: warning: bad option ‘-fstrict-overflow’ to attribute ‘optimize’ [-Wattributes]
answer.code:65:65: warning: bad option ‘-fcse-skip-blocks’ to attribute ‘optimize’ [-Wattributes]
answer.code:65:65: warning: bad option ‘-funsafe-loop-optimizations’ to attribute ‘optimize’ [-Wattributes]
answer.code:66:43: warning: bad option ‘-fwhole-program’ to attribute ‘optimize’ [-Wattributes]
   66 | template<typename T> inline void print(T x)
      |                                           ^
answer.code:66:43: warning: bad option ‘-fstrict-overflow’ to attribute ‘optimize’ [-Wattributes]
answer.code:66:43: warning: bad option ‘-fcse-skip-blocks’ to attribute ‘optimize’ [-Wattributes]
answer.code:66:43: warning: bad option ‘-funsafe-loop-optimizations’ to attribute ‘optimize’ [-Wattributes]
answer.code:74:64: warning: bad option ‘-fwhole-program’ to attribute ‘optimize’ [-Wattributes]
   74 | template<typename T,typename ...O> inline void print(T x,O ...o) {print(x),putchar(' '),print(o...);}
      |                                                                ^
answer.code:74:64: warning: bad option ‘-fstrict-overflow’ to attribute ‘optimize’ [-Wattributes]
answer.code:74:64: warning: bad option ‘-fcse-skip-blocks’ to attribute ‘optimize’ [-Wattributes]
answer.code:74:64: warning: bad option ‘-funsafe-loop-optimizations’ to attribute ‘optimize’ [-Wattributes]
answer.code:86:20: warning: bad option ‘-fwhole-program’ to attribute ‘optimize’ [-Wattributes]
   86 |     void dfs1(int x)
      |                    ^
answer.code:86:20: warning: bad option ‘-fstrict-overflow’ to attribute ‘optimize’ [-Wattributes]
answer.code:86:20: warning: bad option ‘-fcse-skip-blocks’ to attribute ‘optimize’ [-Wattributes]
answer.code:86:20: warning: bad option ‘-funsafe-loop-optimizations’ to attribute ‘optimize’ [-Wattributes]
answer.code:107:26: warning: bad option ‘-fwhole-program’ to attribute ‘optimize’ [-Wattributes]
  107 |     void dfs2(int x,int k)
      |                          ^
answer.code:107:26: warning: bad option ‘-fstrict-overflow’ to attribute ‘optimize’ [-Wattributes]
answer.code:107:26: warning: bad option ‘-fcse-skip-blocks’ to attribute ‘optimize’ [-Wattributes]
answer.code:107:26: warning: bad option ‘-funsafe-loop-optimizations’ to attribute ‘optimize’ [-Wattributes]
answer.code:126:24: warning: bad option ‘-fwhole-program’ to attribute ‘optimize’ [-Wattributes]
  126 |     int get(int x,int k)
      |                        ^
answer.code:126:24: warning: bad option ‘-fstrict-overflow’ to attribute ‘optimize’ [-Wattributes]
answer.code:126:24: warning: bad option ‘-fcse-skip-blocks’ to attribute ‘optimize’ [-Wattributes]
answer.code:126:24: warning: bad option ‘-funsafe-loop-optimizations’ to attribute ‘optimize’ [-Wattributes]
answer.code:135:15: warning: bad option ‘-fwhole-program’ to attribute ‘optimize’ [-Wattributes]
  135 |     void init()
      |               ^
answer.code:135:15: warning: bad option ‘-fstrict-...