//Problem - M - Codeforces #include <bits/stdc++.h> using namespace std; typedef long long ll; #define PII pair<int, int> const int N = 1e6 + 10; int n, a, b, f;//-1则为偶数 ll ans, tt, uu = 0, x[N], cnt = 0; int main() { cin >> n >> a >> b; if (n % 2) f = 1; else f = 0; ans = (1ll * n * (n + 2) * (2 * n + 1) - f) / 8; // cout << ans << endl; if (b == 1 || b == a) { if (2 * a <= n) ans -= 2 * a; else ans -= n; } else { if (a % 2 == 0) { for (int i = 1, j = a; i <= j; i++, j--) {//边1~a(偶数)的三角形 if (i == j) { tt += min(b, i), x[i] = min(b, i), cnt++; } else { if (b <= a / 2) { tt += 2 * min(b, i), x[i] = min(b, i), cnt++; } else if (b >= a / 2) { tt += 2 * min(a - b + 1, i), x[i] = min(a - b + 1, i), cnt++; } } } for (int i = 1; i <= cnt; i++) x[cnt + i] = x[cnt - i + 1]; for (int i = 1; i <= min(n - a, 2 * a); i++) {//边1~(n-a)的三角形 uu += x[i]; } } else { for (int i = 1, j = a; i <= j; i++, j--) {//边1~a(奇数)的三角形 if (b <= a / 2 + 1) { if (i == j) { tt += min(b, i), x[i] = min(b, i), cnt++; } else { tt += 2 * min(b, i), x[i] = min(b, i), cnt++; } } else if (b > a / 2 + 1) { if (i == j) { tt += min(a - b + 1, i), x[i] = min(a - b + 1, i), cnt++; } else { tt += 2 * min(a - b + 1, i), x[i] = min(a - b + 1, i), cnt++; } } } for (int i = 1; i <= cnt; i++) x[cnt + i] = x[cnt - i]; for (int i = 1; i <= min(n - a, 2 * a); i++) {//边1~(n-a)的三角形 uu += x[i]; } } } cout << ans - tt - uu << endl; return 0; }
MMMMM
于 2024-04-27 12:26:56 首次发布