QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#501273#6511. Balancing Sequencesucup-team4352WA 359ms236140kbC++231.8kb2024-08-02 16:17:162024-08-02 16:17:17

Judging History

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

  • [2024-08-02 16:17:17]
  • 评测
  • 测评结果:WA
  • 用时:359ms
  • 内存:236140kb
  • [2024-08-02 16:17:16]
  • 提交

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 st[maxn][20];
int fa[maxn],dfn[maxn],rk[maxn],dep[maxn],ans[maxn],nans[maxn],tot;
int L[maxn],R[maxn];
int f[maxn];
void dfs(int x,int f){
	fa[x]=f;
	dfn[x]=++tot;
	rk[tot]=x;
	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)]);
}
int find(int x){
	return f[x]==x?x:f[x]=find(f[x]);
}
void solve(){
	int n;
	//cin>>n;
	n=1e6;
	tot=0;
	for(int i=1;i<=n;i++){
		e[i].clear();
		f[i]=i;
		nans[i]=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=n/2;i>=2;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 now=find(j);
			while(dep[now]>dep[l]){
				nans[now]=i;
				f[now]=fa[now];
				now=find(now);
			}
		}
	}
	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<<nans[ans[i]]<<" \n"[i==n-1];
	}
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0);
	int size(256<<20); //256M
	__asm__ ( "movq %0, %%rsp\n"::"r"((char*)malloc(size)+size));
    int t=1;
    ///cin>>t;
    while(t--)solve();
	exit(0);
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 359ms
memory: 236140kb

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 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...

result:

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