17多校contest 6- 1003 Inversion ( 模拟

来源:互联网 发布:java开发在公司任务 编辑:程序博客网 时间:2024/06/02 05:52

Description

Give an array A, the index starts from 1.
Now we want to know Bi=maxi∤jAj , i≥2.

Input

The first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with one integer n : the size of array A.
Next one line contains n integers, separated by space, ith number is Ai.

Limits
T≤20
2≤n≤100000
1≤Ai≤1000000000
∑n≤700000

Output

For each test case output one line contains n-1 integers, separated by space, ith number is Bi+1.

Sample Input

241 2 3 441 4 2 3

Sample Output

3 4 32 4 4

题解:

签到题 把数组从大到小排个序就好

AC代码

#include <bits/stdc++.h>using namespace std;#define LL long long#define CLR(a,b) memset(a,(b),sizeof(a))const int INF = 0x3f3f3f3f;const LL INFLL = 0x3f3f3f3f3f3f3f3f;const int N = 1e6+10;struct node {    int x, pos;}p[N];int arr[N], brr[N];bool cmp(node a,node b){    return a.x > b.x;}int main(){    int T;    scanf("%d",&T);    while(T--) {        int n;        scanf("%d",&n);        for(int i = 1; i <= n; i++) {            scanf("%d",&arr[i]);            p[i].x = arr[i];            p[i].pos = i;        }        int k = 0;        sort(p+1, p+n+1, cmp);        for(int i = 2; i <= n; i++) {            for(int j = 1; j <= n; j++) {                if(p[j].pos%i != 0) {                    brr[i] = p[j].x; break;                }            }        }        for(int i = 2;i <= n; i++) {            if(i == 2) printf("%d",brr[i]);            else printf(" %d",brr[i]);        }        printf("\n");    }return 0;}