fork download
  1. // MOHIT KUMAR
  2. #pragma GCC optimize ("O3")
  3. #pragma GCC target ("sse4")
  4.  
  5. #include <bits/stdc++.h>
  6.  
  7. using namespace std;
  8.  
  9. typedef long long ll;
  10. typedef long double ld;
  11. typedef complex<ld> cd;
  12.  
  13. typedef pair<int, int> pin;
  14. typedef pair<ll, ll> pl;
  15. typedef pair<ld, ld> pd;
  16.  
  17. #define ff(i, a, b) for ( ll i=a; i<(b); i++)
  18. #define ffd(i, a, b) for ( ll i=a; i<= b; i++)
  19. #define fr(i, a, b) for ( ll i = (b)-1; i >= a; i--)
  20. #define ffr(i, a, b) for ( ll i = b ; i >= a; i--)
  21. #define vl vector < ll >
  22. #define vp vector < pl >
  23. #define endl "\n"
  24. #define sz(x) (ll)(x).size()
  25. #define mp make_pair
  26. #define pb push_back
  27. #define f first
  28. #define s second
  29. #define lb lower_bound
  30. #define ub upper_bound
  31. #define all(x) x.begin(), x.end()
  32. #define rall(x) x.rbegin(), x.rend()
  33.  
  34. const ld pi = acos(-1) ;
  35. const ll maxn = 3e5 + 5 ;
  36. const int mod = 998244353 ;
  37. const ll INF = 1e18 ;
  38. const int MX = 2000000001 ; // check the limits, dummy
  39.  
  40. vl lps(maxn, 0) ; // longest prefix array which is also a suffix
  41.  
  42. void KMP( string s) {
  43. ll l = 0, r = 1 ;
  44. while (r < s.size()) {
  45. if (s[l] == s[r]) {
  46. lps[r++] = ++l ;
  47. }
  48. else {
  49. l = 0 ;
  50. lps[r++] = 0;
  51. }
  52. }
  53. ff(i, 0, sz(s)) cout << lps[i] << " " ;
  54. }
  55.  
  56. void find_sub(string s, string t) {
  57. ll i = 0, j = 0, ans = 0 ;
  58. bool ch = false ;
  59. while (i < s.size()) {
  60. if (s[i] == t[j]) {
  61. j++ ;
  62. i++ ;
  63. if (j == t.size()) {
  64. ans++ ;
  65. cout << "Substring found at " << i - j << " index" << endl ;
  66. // return true ;
  67. j = lps[j - 1] ;
  68. ch = true ;
  69. }
  70. }
  71. else {
  72. if (j) j = lps[j - 1] ;
  73. else i++ ;
  74. }
  75. }
  76. if (!ch) cout << "Substring not found\n" ;
  77. cout << "NUMBER OD OCC" << ans << endl ;
  78. // return false ;
  79. }
  80.  
  81. ll max_gold_mine() {
  82. ll v[3][1] = {{1}, {2}, {3}};
  83. ll m = 3, n = 1 ;
  84. ll ans = 0 ;
  85. for ( int j = n - 2; j >= 0; j--) {
  86. for ( int i = 0; i < m; i++) {
  87. if (!i) v[i][j] += max(v[i][j + 1], v[i + 1][j + 1]) ;
  88. else if (i == m - 1)v[i][j] += max(v[i][j + 1], v[i - 1][j + 1]) ;
  89. else v[i][j] += max({v[i + 1][j + 1], v[i - 1][j + 1], v[i][j + 1]}) ;
  90. }
  91. }
  92. for ( int i = 0; i < m; i++) ans = max(ans, v[i][0]) ;
  93. return ans ;
  94.  
  95. }
  96.  
  97. int optimal_merge( vector < int > v) {
  98. int ans = 0 ;
  99. priority_queue < int , vector < int > , greater < int >> pq;
  100. for (auto x : v) pq.push(x) ;
  101. while (pq.size() != 1) {
  102. int a = pq.top() ;
  103. pq.pop() ;
  104. int b = pq.top() ;
  105. pq.pop() ;
  106. ans += a + b ;
  107. pq.push(a + b) ;
  108. }
  109. return ans ;
  110. }
  111.  
  112. vl vis(maxn, 0), top, adj[maxn] ;
  113.  
  114. void dfs( ll u) {
  115. vis[u] = 1 ;
  116. for (auto x : adj[u]) {
  117. if (!vis[x]) dfs(x) ;
  118. }
  119. top.pb(u) ;
  120. }
  121. void topo_sort(vl adj[], ll n) {
  122. ffr(i, 1, n) {
  123. if (!vis[i]) dfs(i) ;
  124. }
  125. reverse(all(top)) ;
  126. cout << "TOPOLOGICAL SORTING OF GRAPH IS\n " ;
  127. for (auto x : top) cout << x << " ";
  128. }
  129.  
  130. vl v[maxn] ;
  131. vector <double > prob(maxn, 0) ;
  132.  
  133. void dfs (ll n, ll par) {
  134. ll res = sz(v[n]) ;
  135. if (par != -1) --res ;
  136. for (auto x : v[n]) {
  137. if ( x != par ) {
  138. prob[x] = prob[n] / res ;
  139. dfs(x, n) ;
  140. }
  141. }
  142. }
  143.  
  144. int main() {
  145. ios_base::sync_with_stdio(0) , cin.tie(0);
  146. ll t, q, n, a, b, c, d, k, l, m, r, x = 0, y = 0, z = 0 , sum = 0, ans = 0, temp = 0, res = 0 ;
  147. cin >> t ;
  148. while (t--) {
  149. cin >> n ;
  150. if (n < 4) cout << "-1\n" ;
  151. vl v ;
  152. ll i ;
  153. if (n & 1) {
  154. i = 1 ;
  155. while (i <= n ) v.pb(i), i += 2 ;
  156. i = n - 1 ;
  157. while (i > 1) v.pb(i), i -= 2 ;
  158. x = 1 + (n + 1) / 2 ;
  159. swap(v[x], v[x - 1]) ;
  160. }
  161. else {
  162. i = 2 ;
  163. while (i <= n) v.pb(i), i += 2 ;
  164. i = n - 1 ;
  165. while (i > 0 ) v.pb(i), i -= 2 ;
  166. x = 1 + n / 2 ;
  167. swap(v[x], v[x - 1]) ;
  168. }
  169. for (auto x : v) cout << x << " ";
  170. cout << endl ;
  171. }
  172. }
  173.  
  174.  
Success #stdin #stdout 0.01s 24116KB
stdin
6
10
2
4
6
7
13
stdout
2 4 6 8 10 7 9 5 3 1 
-1
2 0 
2 4 1 3 
2 4 6 3 5 1 
1 3 5 7 4 6 2 
1 3 5 7 9 11 13 10 12 8 6 4 2