intmain(void) { while (~scanf("%s", s)) { int o = 0, _ = 0; int i, len = strlen(s); for (i = 0; i < len; ++i) { if (s[i] == 'o') ++o; else ++_; } if (o == 0) puts("YES"); else puts((_ % o == 0) ? "YES" : "NO"); } return0; }
voidinit() { for (int i = 0; i < M; ++i) sz[i] = 1, pre[i] = i; } intfd(int n) { return pre[n] == n ? n : pre[n] = fd(pre[n]); } voidmg(int a, int b) { a = fd(a), b = fd(b); if (a > b) swap(a, b); if (a != b) { sz[a] += sz[b]; sz[b] = 0; pre[b] = a; } } intmain(void) { int n, k, i; while (~scanf("%d%d", &n, &k)) { init(); for (i = 0; i < n; ++i) scanf("%d", a + i); for (i = 0; i < n; ++i) { if (fd(a[i]) != a[i]) continue; int ch = a[i]; int fc = fd(a[i]); for (int col = a[i]; col >= 0 && col >= a[i] - k + 1; --col) { int f = fd(col); if (f == col && sz[f] + sz[fc] <= k) ch = col; } for (int col = a[i]; col >= 0 && col >= ch; --col) mg(ch, col); } for (i = 0; i < n; ++i) printf("%d%c", fd(a[i]), " \n"[i == n - 1]); } return0; }
int a[N], ans[N], num[N]; unordered_map<int, int>st; bitset<N> cnt;
intG(int n) { int neg; n < 0 ? neg = -1, n = -n : neg = 1; int w = 1; for (int i = 2; i * i <= n; ++i) { if (n % i == 0) { int t = 0; while (n % i == 0) { n /= i; t ^= 1; } if (t) w *= i; } } return w * n * neg; } intmain(void) { registerint n, i, j; scanf("%d", &n); int id = 0; for (i = 1; i <= n; ++i) { scanf("%d", a + i); num[i] = a[i]; a[i] = G(a[i]); if (!st.count(a[i])) st.insert(pii(a[i], ++id)); a[i] = st[a[i]]; } for (i = 1; i <= n; ++i) { cnt.reset(); int sz = 0; for (j = i; j <= n; ++j) { if (num[j] == 0) { ++ans[max(sz, 1)]; continue; } elseif (!cnt[a[j]]) { cnt[a[j]] = 1; ++sz; } ++ans[sz]; } } for (i = 1; i <= n; ++i) printf("%d%c", ans[i], " \n"[i == n]); return0; }
#include<bits/stdc++.h> //#pragma GCC optimize(2) usingnamespacestd; #define all(a) (a).begin(),(a).end() #define pb(x) push_back(x) #define CLR(arr,val) memset(arr,val,sizeof(arr)) #define FAST_IO ios::sync_with_stdio(false);cin.tie(0); #define caseT int _T;scanf("%d",&_T);for (int q=1; q<=_T; ++q) constint N = 1e6 + 7; structedge { int to, nxt; edge() {} edge(int _to, int _nxt): to(_to), nxt(_nxt) {} } E[N << 1]; int head[N], tot; int dep[N], vis[N], fa[N][21];
voidinit() { CLR(head, -1); tot = 0; } voidadd(int s, int t) { E[tot] = edge(t, head[s]); head[s] = tot++; } voiddfs(int u, int f, int d) { fa[u][0] = f; dep[u] = d; for (int i = head[u]; ~i; i = E[i].nxt) { int v = E[i].to; if (v != f) dfs(v, u, d + 1); } } voiddel(int x) { if (vis[x] || !x) return ; vis[x] = 1; del(fa[x][0]); } intmain(void) { int n, k, i, a, b, j; init(); scanf("%d%d", &n, &k); for (i = 1; i < n; ++i) { scanf("%d%d", &a, &b); add(a, b); add(b, a); } dfs(n, 0, 0); for (j = 1; j <= 20; ++j) { for (i = 1; i <= n; ++i) fa[i][j] = fa[fa[i][j - 1]][j - 1]; } int res = n - k - 1; vector<int>v; vis[n] = 1; for (i = n - 1; i >= 1 && res > 0; --i) { if (vis[i]) continue; int x = i; for (j = 20; j >= 0; --j) { if (fa[x][j] && !vis[fa[x][j]]) x = fa[x][j]; } x = fa[x][0]; int kpcnt = dep[i] - dep[x]; if (res < kpcnt) continue; del(i); res -= kpcnt; } for (i = 1; i <= n; ++i) if (!vis[i]) printf("%d ", i); puts(""); return0; }