QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#501244#6511. Balancing Sequencesucup-team4352WA 2243ms382532kbC++232.0kb2024-08-02 16:01:262024-08-02 16:01:26

Judging History

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

  • [2024-08-02 16:01:26]
  • 评测
  • 测评结果:WA
  • 用时:2243ms
  • 内存:382532kb
  • [2024-08-02 16:01:26]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define lowbit(x) (x&-x)
#define log(x) (31^__builtin_clz(x))
using namespace std;
const int maxn=1e6+5;

vector<int>e[maxn];
int tp[maxn][20],mx[maxn][20],st[maxn][20];
int fa[maxn],dfn[maxn],rk[maxn],dep[maxn],ans[maxn],tot;
int L[maxn],R[maxn];
void dfs(int x,int f){
	fa[x]=f;
	dfn[x]=++tot;
	rk[tot]=x;
	tp[x][0]=f;
	for(int i=1;i<=19;i++){
		tp[x][i]=tp[tp[x][i-1]][i-1];
	}
	for(auto u:e[x]){
		if(u==f)continue;
		dep[u]=dep[x]+1;
		dfs(u,x);
	}
}
inline int get(int x,int y){
	return dep[x]<dep[y]?x:y;
}
inline int lca(int x,int y){
	if(x==y)return x;
	x=dfn[x],y=dfn[y];
	if(x>y)swap(x,y);x++;
	return get(st[x][log(y-x+1)],st[y-(1<<log(y-x+1))+1][log(y-x+1)]);
}
void dfs1(int x,int f){
	for(int i=19;i>=1;i--){
		mx[tp[x][i-1]][i-1]=max(mx[tp[x][i-1]][i-1],mx[x][i]);
		mx[x][i-1]=max(mx[x][i-1],mx[x][i]);
	}
	for(auto u:e[x]){
		if(u==f)continue;
		dfs1(u,x);
	}
}
void solve(){
	int n;
	//cin>>n;
	n=1e6;
	tot=0;
	for(int i=1;i<=n;i++){
		e[i].clear();
		for(int j=0;j<=19;j++){
			mx[i][j]=1;
		}
	}
	for(int i=1;i<n;i++){
		int u,v;
		//cin>>u>>v;
		u=i,v=i+1;
		e[u].push_back(v);
		e[v].push_back(u);
		L[i]=u;R[i]=v;
	}
	dep[1]=1;
	dfs(1,0);
	for(int i=n;i>=1;i--){
		st[i][0]=fa[rk[i]];
		for(int j=1;j<=19;j++){
			st[i][j]=get(st[i][j-1],st[min(i+(1<<j-1),n)][j-1]);
		}
	}
	for(int i=1;i*2<=n;i++){
		int l=i;
		for(int j=i*2;j<=n;j+=i){
			l=lca(l,j);
		}
		for(int j=i;j<=n;j+=i){
			int u=j,d=dep[j]-dep[l];
			while(d){
				int k=log(d);
				mx[u][k]=max(mx[u][k],i);
				u=tp[u][k];
				d^=1<<k;
			}
		}
	}
	dfs1(1,0);
	for(int i=1;i<n;i++){
		if(fa[L[i]]==R[i])ans[i]=L[i];
		else ans[i]=R[i];
	}
	for(int i=1;i<n;i++){
		cout<<mx[ans[i]][0]<<" \n"[i==n-1];
	}
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--)solve();
	exit(0);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2243ms
memory: 382532kb

input:

2
2
1 2
3 4
4 3
2 1
3
1 2 4
3 5 6
1 2 4
5 3 6

output:

1 2 3 3 5 6 7 7 9 10 11 11 13 14 15 15 17 18 19 19 21 22 23 23 25 26 27 27 29 30 31 31 33 34 35 35 37 38 39 39 41 42 43 43 45 46 47 47 49 50 51 51 53 54 55 55 57 58 59 59 61 62 63 63 65 66 67 67 69 70 71 71 73 74 75 75 77 78 79 79 81 82 83 83 85 86 87 87 89 90 91 91 93 94 95 95 97 98 99 99 101 102 1...

result:

wrong answer Integer parameter [name=x2] equals to 3, violates the range [1, 2] (test case 1)