QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#740428#5173. 染色zwh2008Compile Error//C++14879b2024-11-13 09:54:432024-11-13 09:54:43

Judging History

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

  • [2024-11-13 09:54:43]
  • 评测
  • [2024-11-13 09:54:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pi=pair<int,int>;
#define fi first
#define se second
const int N=1e6+5;
int n,m,a[N],c[N],pre[N],p[N],fa[21][N];
int main() {
    #ifndef ONLINE_JUDGE
        freopen(".in","r",stdin);
        freopen(".out","w",stdout);
    #endif
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i],c[i]=n+1;
    for(int i=1;i<=n;i++)pre[i]=p[a[i]],c[pre[i]]=min(c[pre[i]],i),p[a[i]]=i;
    fa[0][n+1]=n+1;
    for(int i=n,j=n+1;i;i--)j=min(j,c[i]),fa[0][i]=j;
    for(int i=1;i<=20;i++)for(int j=1;j<=n+1;j++)fa[i][j]=fa[i-1][fa[i-1][j]];
    while(m--) {
        int l,r;cin>>l>>r;
        if(l>r)swap(l,r);
        int as=(r-l)*2;
        for(int i=20;~i;i--)if(fa[i][l]<=r)l=fa[i][l],as-=1<<i;
        cout<<as<<'\n';
    }
    return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:19:52: error: ‘j;’ was not declared in this scope
   19 |     for(int i=n,j=n+1;i;i--)j=min(j,c[i]),fa[0][i]=j;
      |                                                    ^~~
answer.code:20:17: error: ‘i’ was not declared in this scope; did you mean ‘pi’?
   20 |     for(int i=1;i<=20;i++)for(int j=1;j<=n+1;j++)fa[i][j]=fa[i-1][fa[i-1][j]];
      |                 ^
      |                 pi
answer.code:20:39: error: ‘j’ was not declared in this scope
   20 |     for(int i=1;i<=20;i++)for(int j=1;j<=n+1;j++)fa[i][j]=fa[i-1][fa[i-1][j]];
      |                                       ^