标签:def cstring type lld class 颜色不同 ret math 存在
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const ll N = 1e6 + 9, mod = 1e9 + 7;
ll a[N];
ll ans[N];
ll b[N];
void solve() {
int n;scanf("%d", &n);
for (int i = 1; i <= n; i ++) scanf("%lld", &a[i]), a[i + n] = a[i];
for (int i = 2; i <= n; i ++) {
if (a[i] != a[i-1])break;
if (i ==n) {
cout << 1 << endl;
for (int i = 1; i <= n; i ++)cout << 1 << " ";
cout << endl;return;
}
}
ans[1] = 0;
ll d = 0;
for (int i = 1; i <= n; i ++) {
ans[i] = ans[i-1]^1;
}
int f = 0;
for (int i = 2; i <= n; i ++) {
if (a[i] == a[i-1]) {f = i;break;}
}
if(f && n%2) {
ans[f-1] = ans[f] = 0;
for (int i = f - 2; i >= 1; i--) {
ans[i] = ans[i + 1] ^ 1;
}
for (int i = f + 1; i <= n; i++) {
ans[i] = ans[i - 1] ^ 1;
}
} else if (n % 2){
if (a[1] != a[n] && a[n-1] != a[n]) {
ans[n] = 2;
}
}
cout << max(ans[n] + 1, (ll)2) << endl;
for (int i = 1; i <= n; i ++) {
cout << ans[i] + 1 << " ";
}
cout << endl;
}
signed main() {
int t;scanf("%d", &t);
while (t--) {
solve();
}
}
标签:def cstring type lld class 颜色不同 ret math 存在
原文地址:https://www.cnblogs.com/Xiao-yan/p/14669631.html