CF1691B Shoe Shuffling
题目大意
求出每一个大小相同的“块”,如果有块的大小为 \(1\) 则无解。
否则,我们对于每个“块”,设组成此“块”的每个元素的下标为 \([i,i+1,\cdots,i+k]\),则答案排列为 \([i+k,i,i+1,\cdots,i+k-1]\)。
注意求无解和输出要分开操作。
代码
#include <iostream>
#include <cstdio>
#include <climits>//need "INT_MAX","INT_MIN"
#include <cstring>//need "memset"
#include <numeric>
#include <algorithm>
#include <cmath>
#include <map>
#define enter putchar(10)
#define debug(c,que) std::cerr << #c << " = " << c << que
#define cek(c) puts(c)
#define blow(arr,st,ed,w) for(register int i = (st);i <= (ed); ++ i) std::cout << arr[i] << w;
#define speed_up() std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0)
#define mst(a,k) memset(a,k,sizeof(a))
#define stop return(0)
const int mod = 1e9 + 7;
inline int MOD(int x) {
if(x < 0) x += mod;
return x % mod;
}
namespace Newstd {
inline int read() {
int ret = 0,f = 0;char ch = getchar();
while (!isdigit(ch)) {
if(ch == '-') f = 1;
ch = getchar();
}
while (isdigit(ch)) {
ret = (ret << 3) + (ret << 1) + ch - 48;
ch = getchar();
}
return f ? -ret : ret;
}
inline double double_read() {
long long ret = 0,w = 1,aft = 0,dot = 0,num = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') w = -1;
ch = getchar();
}
while (isdigit(ch) || ch == '.') {
if (ch == '.') {
dot = 1;
} else if (dot == 0) {
ret = (ret << 3) + (ret << 1) + ch - 48;
} else {
aft = (aft << 3) + (aft << 1) + ch - '0';
num ++;
}
ch = getchar();
}
return (pow(0.1,num) * aft + ret) * w;
}
inline void write(int x) {
if(x < 0) {
putchar('-');
x = -x;
}
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
}
}
using namespace Newstd;
const int N = 1e5 + 5;
int a[N];
int n;
inline void solve() {
mst(a,0);
n = read();
bool mark = true;
for (register int i = 1;i <= n; ++ i) {
a[i] = read();
}
int L = 1,R = 1;
while (R <= n) {
while (R + 1 <= n && a[L] == a[R + 1]) R ++;
if (L == R) {
puts("-1");
return;
}
L = R + 1;
R ++;
}
L = R = 1;
while (R <= n) {
while (R + 1 <= n && a[L] == a[R + 1]) R ++;
if (L == R) {
puts("-1");
return;
}
printf("%d ",R);
for (register int i = L;i < R; ++ i) printf("%d ",i);
L = R + 1;
R ++;
}
puts("");
}
int main(void) {
int T = read();
while (T --) {
solve();
}
return 0;
}