QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#290074#4617. Arithmetic SubsequenceyspmCompile Error//C++201.6kb2023-12-24 12:30:512023-12-24 12:30:51

Judging History

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

  • [2023-12-24 12:30:51]
  • 评测
  • [2023-12-24 12:30:51]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
template<typename T>inline void ckmax(T &x,T y){x=x<y?y:x;}
template<typename T>inline void ckmin(T &x,T y){x=x>y?y:x;}
template<typename T=int>inline T read(){
    T res=0,f=1; char k;
    while(!isdigit(k=getchar())) if(k=='-') f=-1;
    while(isdigit(k)) res=res*10+k-'0',k=getchar();
    return res*f;
}
template<typename T>inline void print(T x,bool fl=1){
    if(x<0) putchar('-'),x=-x; 
    if(x>=10) print(x/10,0);
    putchar(x%10+'0');
    if(fl) putchar('\n');
}
const int N=5010;
int a[N],b[N],n,ta[N],tb[N];
inline void solve(int l,int r){
    while(1){
        bool fl1=1,fl2=1;
        for(int i=l;i<=r;++i){
            if(a[i]&1) fl2=0;
            else fl1=0;
        }
        if(fl1==0&&fl2==0) break;
        for(int i=l;i<=r;++i) a[i]=a[i]/2;
        bool fl=0;
        for(int i=l;i<=r;++i) fl|=a[i]!=0;
        if(!fl) return ;
    }
    int cc=l-1;
    for(int i=l;i<=r;++i){
        if(a[i]&1){
            ta[++cc]=a[i];
            tb[cc]=b[i];
        }
    }
    int mid=cc;
    rep(i,l,r) if(a[i]%2==0) ta[++cc]=a[i],tb[cc]=b[i];
    rep(i,l,r) a[i]=ta[i],b[i]=tb[i];
    solve(l,mid); solve(mid+1,r);
    return ;
}
int main(){
    int T=read();
    while(T--){
        n=read();
        map<int,int> cnt;
        for(int i=1;i<=n;++i) cnt[b[i]=a[i]=read()]++;
        bool ee=0;
        for(auto t:cnt) if(t.second>=3) puts("NO"),ee=1;
        if(ee) continue;  
        solve(1,n);
        puts("YES");
        for(int i=1;i<n;++i) printf("%d ",b[i]);
        printf("%d\n",b[i]);
    }
    return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:58:25: error: ‘i’ was not declared in this scope
   58 |         printf("%d\n",b[i]);
      |                         ^