hdu6098

来源:互联网 发布:行省制的影响知乎 编辑:程序博客网 时间:2024/06/05 19:47

Inversion

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 271    Accepted Submission(s): 183


Problem Description
Give an array A, the index starts from 1.
Now we want to know Bi=maxijAj , i2.
 

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
T20
2n100000
1Ai1000000000
n700000
 

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
 

Source
2017 Multi-University Training Contest - Team 6

——————————————————————————————————
题目的意思是给出一个序列,求2~n每一个数,下标不是这个数倍数的最大值是什么?
思路:从大到小排个序,然后枚举判下表是否为这个数的倍数
[cpp] view plain copy
print?
  1. #include <iostream>  
  2. #include <cstdio>  
  3. #include <cstring>  
  4. #include <map>  
  5. #include <set>  
  6. #include <string>  
  7. #include <cmath>  
  8. #include <algorithm>  
  9. #include <vector>  
  10. #include <bitset>  
  11. #include <stack>  
  12. #include <queue>  
  13. #include <unordered_map>  
  14. #include <functional>  
  15.   
  16. using namespace std;  
  17.   
  18. struct node{  
  19. int id,v;  
  20. }a[100005];  
  21.   
  22. bool cmp(node x,node y)  
  23. {  
  24.     return x.v>y.v;  
  25. }  
  26.   
  27. int main()  
  28. {  
  29.     int T,n;  
  30.     for(scanf("%d",&T);T--;)  
  31.     {  
  32.         scanf("%d",&n);  
  33.         for(int i=1;i<=n;i++)  
  34.             scanf("%d",&a[i].v),a[i].id=i;  
  35.         sort(a+1,a+1+n,cmp);  
  36.         int q=0;  
  37.         for(int i=2;i<=n;i++)  
  38.         {  
  39.             int k=1;  
  40.             while(a[k].id%i==0)  
  41.             {  
  42.                k++;  
  43.             }  
  44.             if(q++)  
  45.                 printf(" ");  
  46.             printf("%d",a[k].v);  
  47.         }  
  48.         printf("\n");  
  49.   
  50.     }  
  51.     return 0;  
  52. }