A:

eng kam bolishi mumkin bolgan puli \(n\), eng kattasi esa \(2n\), shuning deb \(2n - n + 1\) ta turli javob chiqadi

print(int(input()) + 1)

B:

Hamma oralikni korib chiqsak boladi, ketadigan vaqti \(O(n^2)\)

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
	ans1 = 0
	for j in range(i,n):
		ans1 |= a[j]
		if ans1 <= k:
			ans = max(j-i+1,ans)
		else:
			break
print(ans)

C:

bunda har bir element juft marta uchirashishi kerak. Shuning dek, bir amalda \(A_i\) ga 1 ni qoshamiz deb hisoblasak boladi. Shartni o'rinlash uchun sort qilib, har juftlikni bir hil qilsa boladi. Ketadigan vaqt \(O(n log n)\).

n = int(input())
a = list(map(int,input().split()))
ans = 0
if n % 2:
	print(-1)
else:
	a.sort()
	for i in range(0, n, 2):
		ans += a[i+1] - a[i]
	print(ans)

D:

Yechishning turli yollari bo'r, two-pointer, segtree, sparse table, binary search.

Bu yerda two-pointer javobini koraylik. Har interval surganda bir nechta bit yoki kopayadi, yoki kamayadi. Har bir bit uchun agar kamida 1 tasi bo'r bolsa, shu bitni hisobga olamiz. \(O(n)\)

void solve() {
    int n, k, mx = 0;
    cin >> n >> k;
    vector<int> a(n), bit(20);
    cin >> a;
    for (int i = 0, j = 0, x, m, w; i < n; ++i) {
        x = a[i], m = 0, w = 0;
        while (x) bit[m++] += x % 2, x /= 2;
        for (int l = 19; l >= 0; --l) w *= 2, w += bool(bit[l]);
        while (w > k) {
            x = a[j++], m = 0, w = 0;
            while (x) bit[m++] -= x % 2, x /= 2;
            for (int l = 19; l >= 0; --l) w *= 2, w += bool(bit[l]);
        }
        cmax(mx, i - j + 1);
    }
    cout << mx;
}
// Jahonali ning kodi, e'tibor bermang

E:

Bunda har bir \((X_1, Y_1, X_2, Y_2)\) ni korib chiqsak boladi.

Agar qaysidir oralikda qora katak bolsa, uni hisoblamaymiz, \((X_1 \le X_{qora} \le X_2)\) va \((Y_1 \le Y_{qora} \le Y_2)\) shartlari o'rinli bolsa. \(O(n^2m^2)\)

N, M = map(int, input().split())
X1, Y1 = map(int, input().split())
X2, Y2 = map(int, input().split())
l = [(X1, Y1), (X2, Y2)]
t = (N * (N + 1) * M * (M + 1)) // 4
s = 0

for x1 in range(1, N + 1):
    for y1 in range(1, M + 1):
        for x2 in range(x1, N + 1):
            for y2 in range(y1, M + 1):
                f = False
                for (bx, by) in l:
                    if x1 <= bx <= x2 and y1 <= by <= y2:
                        f = True
                        break
                if f:
                    s=s+1

print(t - s)

F:

Bunda javobi: (umuman to'rburchaklar soni) - (1inchi qora katakni ichida oladigan tortburchaklar soni) - (2inchi qora katakni ichida oladigan tortburchaklar soni) + (ikkala qora katakni ichida oladigan tortburchaklar soni). Ketadigan vaqt \(O(1)\) yoki \(O(n \cdot m)\)
Avtor (python):

total = 0
n, m = map(int, input().split())
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
mod = 1_000_000_007
for i in range(1, n + 1):
	for j in range(1, m + 1):
		total += (n - i + 1) * (m - j + 1)
		total %= mod
total -= x1 * y1 * (n - x1 + 1) * (m - y1 + 1)
total -= x2 * y2 * (n - x2 + 1) * (m - y2 + 1)
total += min(x1, x2) * min(y1, y2) * (n - max(x1, x2) + 1) * (m - max(y1, y2) + 1)
print(total % mod)

Jahonali (cpp):

void solve() {
    int n, m, x, y, xx, yy, k;
    cin >> n >> m >> x >> y >> xx >> yy, k = n * (n + 1) / 2 * m * (m + 1) / 2;
    k -= (x) * (n - x + 1) * (y) * (m - y + 1);
    k -= (xx) * (n - xx + 1) * (yy) * (m - yy + 1);
    if (x > xx) swap(x, xx);
    if (y > yy) swap(y, yy);
    k += (x) * (n - xx + 1) * (y) * (m - yy + 1);
    cout << k % mod;
}