voidsolve() { scanf("%d", &n); for (int i = 1; i <= n; ++ i) scanf("%d", a + i); int i = 1; while (i <= n && a[i]) i ++; if (i > n) { puts("0"); return; } int j = n; while (j && a[j]) j --; printf("%d\n", j - i + 2); }
voidsolve() { scanf("%d", &n); for (int i = 1; i <= n; ++ i) scanf("%d", a + i); bool flag = 0; for (int i = 1; i <= n; ++ i) flag |= !!a[i]; if (!flag) { puts("0"); return; } LL sum = 0; for (int i = 1; i <= n; ++ i) sum += a[i]; if ((LL(*std::max_element(a + 1, a + n + 1)) << 1) <= sum) { puts("1"); return; } printf("%lld\n", 2LL * (*std::max_element(a + 1, a + n + 1)) - sum); }
C.
题意:给出 $n\times m$ 的矩形,每个点有一个颜色,求所有颜色相同的点两两之间的曼哈顿距离和。$n\times m \leq 10^5,c_{i, j}\leq 10^5$。
voidsolve() { for (int i = 1; i <= c; ++ i) h[i] += h[i - 1]; for (int i = 1; i <= c; ++ i) { for (int l = i, r, j = 0; l <= c; l = r + 1) { if (h[i] == h[i - 1]) break; r = std::min(c, l + i - 1), j ++; if (h[r] == h[l - 1]) continue; if (h[j] == h[j - 1]) { puts("No"); return; } } } puts("Yes"); }
intmain() { int len = std::min(n, m); LL res = 0, now = fact[n]; for (int i = 1; i <= n; ++ i) cnt[a[i]] ++; for (int i = 1; i < N; ++ i) now = now * infact[cnt[i]] % Mod; for (int i = 1; i < N; ++ i) bt.add(i, cnt[i]); bool flag = 1; for (int i = 1; i <= len; ++ i) { res = (res + bt.ask(b[i] - 1) * now % Mod * inv[n - i + 1]) % Mod; if (!cnt[b[i]]) { flag = 0; break; } bt.add(b[i], -1), now = now * inv[n - i + 1] % Mod * (cnt[b[i]] --) % Mod; } printf("%lld\n", (res + ((n < m) && flag)) % Mod); }