QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#859304#9676. AncestorsShumomoCompile Error//C++143.5kb2025-01-17 17:13:552025-01-17 17:13:56

Judging History

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

  • [2025-01-17 17:13:56]
  • 评测
  • [2025-01-17 17:13:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define tm asdfdfg
int n,B,N,m,l,r,u,tm,mp,mm,tt,tmp,tot,d[100009],f[100009],g[100009],h[100009],v[100009],lg[200009],dfn[100009],ans[1000009],st[200009][22],ts[200009][22];
set<int> s[100009];
set<int>::iterator it;
vector<int> to[100009];
struct node{
    int l,r,x,id;
    bool operator < (const node aa)const{
        return l/B<aa.l/B||(l/B==aa.l/B&&r<aa.r);
    }
}q[1000009];
void add(int x){
    it=s[d[x]].lower_bound(dfn[x]);
    tmp=d[x];
//    cout<<x<<" "<<d[x]<<" "<<tmp<<endl;
    if(it!=s[d[x]].end()){
        tm=*it;
        tt=lg[tm-dfn[x]+1];
        mp=min(st[dfn[x]][tt],st[tm-(1<<tt)+1][tt]);
        tmp=min(tmp,d[x]-mp);
//        cout<<x<<" "<<d[x]<<" "<<tmp<<endl;
    }
    if(it!=s[d[x]].begin()){
        it--;
        tm=*it;
        tt=lg[dfn[x]-tm+1];
        mp=min(st[tm][tt],st[dfn[x]-(1<<tt)+1][tt]);
        tmp=min(tmp,d[x]-mp);
//        cout<<x<<" "<<d[x]<<" "<<tmp<<" "<<tm<<" "<<mp<<" "<<dfn[x]<<" "<<tt<<" "<<st[2][2]<<endl;
    }
    s[d[x]].insert(dfn[x]);
    g[x]=tmp-1;
    for(int i=n+1-g[x];i<=n+1;i+=(i&(-i)))v[i]++;
}
void del(int x){
    s[d[x]].erase(dfn[x]);
    for(int i=n+1-g[x];i<=n+1;i+=(i&(-i)))v[i]--;
}
void dfs(int x){
    st[++tot][0]=d[x];+----------------------
    dfn[x]=tot;
    for(auto i:to[x]){
        d[i]=d[x]+1;
        dfs(i);
        st[++tot][0]=d[x];
    }
}
int main(){
    scanf("%d%d",&n,&m);
    B=1;
//    B=1ll*n*n/sqrt(m);
//    B=sqrt(B);
//    cerr<<B<<endl;
    for(int i=1;i<=n;i++){
        scanf("%d",&u);
        ts[i][0]=u;
        to[u].emplace_back(i);
    }
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",&q[i].l,&q[i].r,&q[i].x);
        q[i].id=i;
    }
    sort(q+1,q+m+1);
    tot=-1;
    dfs(0);
    lg[1]=0;
    N=n<<1;
    N--;
    for(int i=2;i<=N;i++)lg[i]=lg[i>>1]+1;
    for(int i=1;i<=lg[N];i++){
        for(int j=1;j+(1<<i)<=N;j++){
            st[j][i]=min(st[j][i-1],st[j+(1<<(i-1))][i-1]);
        }
    }
    for(int i=1;i<=lg[n];i++){
        for(int j=1;j<=n;j++){
            ts[j][i]=ts[ts[j][i-1]][i-1];
        }
    }
    l=1;
    r=0;
    q[0].l=0xc0c0c0c0;
    for(int i=1;i<=m;i++){
        if(q[i].l/B==q[i].r/B){
//            cout<<q[i].l<<" "<<q[i].r<<" "<<q[i].x<<endl;
            tmp=0;
            for(int j=q[i].l;j<=q[i].r;j++){
                h[j]=j;
            }
            for(int j=lg[q[i].x];j>=0;j--){
                if(q[i].x&(1<<j)){
                    for(int k=q[i].l;k<=q[i].r;k++){
                        h[k]=ts[h[k]][j];
                    }
                }
            }
            f[0]=i;
            for(int j=q[i].l;j<=q[i].r;j++){
                if(f[h[j]]<i){
                    f[h[j]]=i;
                    tmp++;
                }
            }
            ans[q[i].id]=tmp;
            continue;
        }
        if(q[i].l/B!=q[i-1].l/B){
            for(int j=1;j<=n+1;j++){
                v[j]=0;
                set<int> t;
                swap(s[j],t);
            }
            mm=q[i].l/B*B+B;
            r=mm-1;
        }
        l=mm;
        while(r<q[i].r){
            r++;
            add(r);
        }
        while(l>q[i].l){
            l--;
            add(l);
        }
        tmp=0;
        for(int j=n+1-q[i].x;j;j-=(j&(-j)))tmp+=v[j];
        ans[q[i].id]=tmp;
        while(l<mm){
            del(l);
            l++;
        }
    }
    for(int i=1;i<=m;i++){
        printf("%d\n",ans[i]);
    }
    return 0;
}

详细

answer.code: In function ‘void dfs(int)’:
answer.code:42:23: error: lvalue required as left operand of assignment
   42 |     st[++tot][0]=d[x];+----------------------
      |                       ^~~~~~~~~~~~~~~~~~~~~~~
   43 |     dfn[x]=tot;
      |     ~~~~~~             
answer.code: In function ‘int main()’:
answer.code:51:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
answer.code:57:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   57 |         scanf("%d",&u);
      |         ~~~~~^~~~~~~~~
answer.code:62:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   62 |         scanf("%d%d%d",&q[i].l,&q[i].r,&q[i].x);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~