QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#876045#4407. 回zlt100 ✓4786ms260332kbC++1415.1kb2025-01-30 16:29:482025-01-30 16:29:48

Judging History

你现在查看的是最新测评结果

  • [2025-01-30 16:29:48]
  • 评测
  • 测评结果:100
  • 用时:4786ms
  • 内存:260332kb
  • [2025-01-30 16:29:48]
  • 提交

answer

// Problem: P8335 [Ynoi2004] tars2
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P8335
// Memory Limit: 512 MB
// Time Limit: 10000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define uint unsigned
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;

namespace IO {
	const int maxn = 1 << 20;
	
    char ibuf[maxn], *iS, *iT, obuf[maxn], *oS = obuf;

	inline char gc() {
		return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin), (iS == iT ? EOF : *iS++) : *iS++);
	}

	template<typename T = int>
	inline T read() {
		char c = gc();
		T x = 0;
		bool f = 0;
		while (c < '0' || c > '9') {
			f |= (c == '-');
			c = gc();
		}
		while (c >= '0' && c <= '9') {
			x = (x << 1) + (x << 3) + (c ^ 48);
			c = gc();
		}
		return f ? ~(x - 1) : x;
	}

	inline void flush() {
		fwrite(obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	
	struct Flusher {
		~Flusher() {
			flush();
		}
	} AutoFlush;

	inline void pc(char ch) {
		if (oS == obuf + maxn) {
			flush();
		}
		*oS++ = ch;
	}

	template<typename T>
	inline void write(T x) {
		static char stk[64], *tp = stk;
		if (x < 0) {
			x = ~(x - 1);
			pc('-');
		}
		do {
			*tp++ = x % 10;
			x /= 10;
		} while (x);
		while (tp != stk) {
			pc((*--tp) | 48);
		}
	}
	
	template<typename T>
	inline void writesp(T x) {
		write(x);
		pc(' ');
	}
	
	template<typename T>
	inline void writeln(T x) {
		write(x);
		pc('\n');
	}
}

using IO::read;
using IO::write;
using IO::pc;
using IO::writesp;
using IO::writeln;

const int maxn = 1000100;
const uint inv3 = 2863311531U;

int m, nt, qt, lsh[maxn], tot;
uint ans[maxn];

struct node {
	int o, a, b, c, d;
} a[maxn];

struct tri {
	int i, x, y, d, w;
	tri(int _i = 0, int _x = 0, int _y = 0, int _d = 0, int _w = 0) : i(_i), x(_x), y(_y), d(_d), w(_w) {}
} b[maxn];

struct que {
	int i, a, b, w;
	que(int _i = 0, int _a = 0, int _b = 0, int _w = 0) : i(_i), a(_a), b(_b), w(_w) {}
} c[maxn];

struct info1 {
	uint a1, a2, a3, a4;
	info1(uint a = 0, uint b = 0, uint c = 0, uint d = 0) : a1(a), a2(b), a3(c), a4(d) {}
	
	inline void add(const info1 &a) {
		a1 += a.a1;
		a2 += a.a2;
		a3 += a.a3;
		a4 += a.a4;
	}
	
	inline void clear() {
		a1 = a2 = a3 = a4 = 0;
	}
};

inline uint operator * (const info1 &a, const info1 &b) {
	return a.a1 * b.a1 + a.a2 * b.a2 + a.a3 * b.a3 + a.a4 * b.a4;
}

inline info1 operator * (const info1 &a, const uint &b) {
	return info1(a.a1 * b, a.a2 * b, a.a3 * b, a.a4 * b);
}

struct BIT1 {
	info1 c[maxn];
	
	inline void update(int x, info1 d) {
		for (int i = x; i; i -= (i & (-i))) {
			c[i].add(d);
		}
	}
	
	inline info1 query(int x) {
		info1 res;
		for (int i = x; i <= tot; i += (i & (-i))) {
			res.add(c[i]);
		}
		return res;
	}
	
	inline void clear(int x) {
		for (int i = x; i; i -= (i & (-i))) {
			c[i].clear();
		}
	}
} T1;

struct info2 {
	uint a1, a2, a3, a4, a5, a6, a7;
	info2(uint a = 0, uint b = 0, uint c = 0, uint d = 0, uint e = 0, uint f = 0, uint g = 0) : a1(a), a2(b), a3(c), a4(d), a5(e), a6(f), a7(g) {}
	
	inline void add(const info2 &a) {
		a1 += a.a1;
		a2 += a.a2;
		a3 += a.a3;
		a4 += a.a4;
		a5 += a.a5;
		a6 += a.a6;
		a7 += a.a7;
	}
	
	inline void clear() {
		a1 = a2 = a3 = a4 = a5 = a6 = a7 = 0;
	}
};

inline uint operator * (const info2 &a, const info2 &b) {
	return a.a1 * b.a1 + a.a2 * b.a2 + a.a3 * b.a3 + a.a4 * b.a4 + a.a5 * b.a5 + a.a6 * b.a6 + a.a7 * b.a7;
}

inline info2 operator * (const info2 &a, const uint &b) {
	return info2(a.a1 * b, a.a2 * b, a.a3 * b, a.a4 * b, a.a5 * b, a.a6 * b, a.a7 * b);
}

struct BIT2 {
	info2 c[maxn];
	
	inline void update(int x, info2 d) {
		for (int i = x; i; i -= (i & (-i))) {
			c[i].add(d);
		}
	}
	
	inline info2 query(int x) {
		info2 res;
		for (int i = x; i <= tot; i += (i & (-i))) {
			res.add(c[i]);
		}
		return res;
	}
	
	inline void clear(int x) {
		for (int i = x; i; i -= (i & (-i))) {
			c[i].clear();
		}
	}
} T2;

struct node1 {
	int x, y, z, i;
	uint w;
	info1 t;
	node1(int a = 0, int b = 0, int c = 0, int d = 0, uint e = 0, info1 f = info1()) : x(a), y(b), z(c), i(d), w(e), t(f) {}
} f1[maxn], g1[maxn];

struct node2 {
	int x, y, z, i;
	uint w;
	info2 t;
	node2(int a = 0, int b = 0, int c = 0, int d = 0, uint e = 0, info2 f = info2()) : x(a), y(b), z(c), i(d), w(e), t(f) {}
} f2[maxn], g2[maxn];

void cdq1(int l, int r) {
	if (l == r) {
		return;
	}
	int mid = (l + r) >> 1;
	cdq1(l, mid);
	cdq1(mid + 1, r);
	int i = l, j = mid + 1, k = 0;
	while (i <= mid && j <= r) {
		if (f1[i].y >= f1[j].y) {
			if (!f1[i].i) {
				T1.update(f1[i].z, f1[i].t * f1[i].w);
			}
			g1[++k] = f1[i++];
		} else {
			if (f1[j].i) {
				ans[f1[j].i] += T1.query(f1[j].z) * f1[j].t * f1[j].w;
			}
			g1[++k] = f1[j++];
		}
	}
	while (i <= mid) {
		if (!f1[i].i) {
			T1.update(f1[i].z, f1[i].t * f1[i].w);
		}
		g1[++k] = f1[i++];
	}
	while (j <= r) {
		if (f1[j].i) {
			ans[f1[j].i] += T1.query(f1[j].z) * f1[j].t * f1[j].w;
		}
		g1[++k] = f1[j++];
	}
	for (int i = l; i <= mid; ++i) {
		if (!f1[i].i) {
			T1.clear(f1[i].z);
		}
	}
	for (int i = 1; i <= k; ++i) {
		f1[l + i - 1] = g1[i];
	}
}

void cdq2(int l, int r) {
	if (l == r) {
		return;
	}
	int mid = (l + r) >> 1;
	cdq2(l, mid);
	cdq2(mid + 1, r);
	int i = l, j = mid + 1, k = 0;
	while (i <= mid && j <= r) {
		if (f2[i].y >= f2[j].y) {
			if (!f2[i].i) {
				T2.update(f2[i].z, f2[i].t * f2[i].w);
			}
			g2[++k] = f2[i++];
		} else {
			if (f2[j].i) {
				ans[f2[j].i] += T2.query(f2[j].z) * f2[j].t * f2[j].w;
			}
			g2[++k] = f2[j++];
		}
	}
	while (i <= mid) {
		if (!f2[i].i) {
			T2.update(f2[i].z, f2[i].t * f2[i].w);
		}
		g2[++k] = f2[i++];
	}
	while (j <= r) {
		if (f2[j].i) {
			ans[f2[j].i] += T2.query(f2[j].z) * f2[j].t * f2[j].w;
		}
		g2[++k] = f2[j++];
	}
	for (int i = l; i <= mid; ++i) {
		if (!f2[i].i) {
			T2.clear(f2[i].z);
		}
	}
	for (int i = 1; i <= k; ++i) {
		f2[l + i - 1] = g2[i];
	}
}

inline void work() {
	int n = 0;
	for (int i = 1; i <= nt; ++i) {
		if (b[i].d <= 0) {
			continue;
		}
		int x = b[i].x + b[i].d - 1, y = b[i].y, z = 0;
		uint w = b[i].w;
		f1[++n] = node1(b[i].i, x, y, 0, w, info1(-1, (x * 3U + z + 5) * 3U - (x * 6U + 9), -3U * (3U * x * x + 2U * x * z + 10U * x + 3U * z + 8) + 2U * (x + 1) * (x + 2) + 1U * (x + 1) * (x * 2 + 3) + 1U * (x + 2) * (x * 2 + 3), 3U * (1U * x * x + 3U * x + 2) * (x + z + 2) - 1U * (x + 1) * (x + 2) * (x * 2 + 3)));
		x = b[i].x - 1;
		y = b[i].y + b[i].d;
		z = b[i].d;
		w = b[i].w;
		f1[++n] = node1(b[i].i, x, y, 0, -w, info1(-1, (x * 3U + z + 5) * 3U - (x * 6U + 9), -3U * (3U * x * x + 2U * x * z + 10U * x + 3U * z + 8) + 2U * (x + 1) * (x + 2) + 1U * (x + 1) * (x * 2 + 3) + 1U * (x + 2) * (x * 2 + 3), 3U * (1U * x * x + 3U * x + 2) * (x + z + 2) - 1U * (x + 1) * (x + 2) * (x * 2 + 3)));
	}
	for (int i = 1; i <= qt; ++i) {
		f1[++n] = node1(c[i].i, c[i].a, c[i].b, c[i].i, c[i].w, info1(1U * c[i].a * c[i].a * c[i].a, 1U * c[i].a * c[i].a, c[i].a, 1));
	}
	tot = 0;
	for (int i = 1; i <= n; ++i) {
		lsh[++tot] = f1[i].z;
	}
	sort(lsh + 1, lsh + tot + 1);
	tot = unique(lsh + 1, lsh + tot + 1) - lsh - 1;
	for (int i = 1; i <= n; ++i) {
		f1[i].z = lower_bound(lsh + 1, lsh + tot + 1, f1[i].z) - lsh;
	}
	sort(f1 + 1, f1 + n + 1, [&](const node1 &a, const node1 &b) {
		if (a.x != b.x) {
			return a.x < b.x;
		} else if (a.y != b.y) {
			return a.y > b.y;
		} else if (a.z != b.z) {
			return a.z > b.z;
		} else {
			return a.i < b.i;
		}
	});
	cdq1(1, n);
	n = tot = 0;
	for (int i = 1; i <= nt; ++i) {
		if (b[i].d <= 0) {
			continue;
		}
		int x = b[i].x + b[i].d - 1, y = b[i].y, z = 0;
		uint w = b[i].w;
		f2[++n] = node2(b[i].i, x + y, -y, 0, w, info2(-1, 3, 6U * (z - y) + 3U * (x * 3U + y * 4U - z + 5) - (x * 6U + y * 6U + 9), -3U * (x * 2U + y * 2U + 3), 6U * (y - z) * (x * 2U + y * 2U + 3) - 3U * (x + y + 1) * (x + y + 2) - 3U * (x + y * 2U - z + 2) * (x + y + 2) - 3U * (x + y * 2U - z + 2) * (x + y + 1) + 2U * (x + y + 1) * (x + y + 2) + 1U * (x + y + 1) * (x * 2U + y * 2U + 3) + 1U * (x + y + 2) * (x * 2U + y * 2U + 3), 3U * (x + y + 2) * (x + y + 1), 6U * (z - y) * (x + y + 2) * (x + y + 1) + 3U * (x + y * 2U - z + 2) * (x + y + 1) * (x + y + 2) - 1U * (x + y + 1) * (x + y + 2) * (x * 2U + y * 2U + 3)));
		x = b[i].x - 1;
		y = b[i].y + b[i].d;
		z = b[i].d;
		w = b[i].w;
		f2[++n] = node2(b[i].i, x + y, -y, 0, -w, info2(-1, 3, 6U * (z - y) + 3U * (x * 3U + y * 4U - z + 5) - (x * 6U + y * 6U + 9), -3U * (x * 2U + y * 2U + 3), 6U * (y - z) * (x * 2U + y * 2U + 3) - 3U * (x + y + 1) * (x + y + 2) - 3U * (x + y * 2U - z + 2) * (x + y + 2) - 3U * (x + y * 2U - z + 2) * (x + y + 1) + 2U * (x + y + 1) * (x + y + 2) + 1U * (x + y + 1) * (x * 2U + y * 2U + 3) + 1U * (x + y + 2) * (x * 2U + y * 2U + 3), 3U * (x + y + 2) * (x + y + 1), 6U * (z - y) * (x + y + 2) * (x + y + 1) + 3U * (x + y * 2U - z + 2) * (x + y + 1) * (x + y + 2) - 1U * (x + y + 1) * (x + y + 2) * (x * 2U + y * 2U + 3)));
	}
	for (int i = 1; i <= qt; ++i) {
		uint p = c[i].a + c[i].b;
		f2[++n] = node2(c[i].i, c[i].a + c[i].b, -c[i].b + 1, c[i].i, c[i].w, info2(p * p * p, p * p * c[i].b, p * p, p * c[i].b, p, c[i].b, 1));
	}
	for (int i = 1; i <= n; ++i) {
		lsh[++tot] = f2[i].z;
	}
	sort(lsh + 1, lsh + tot + 1);
	tot = unique(lsh + 1, lsh + tot + 1) - lsh - 1;
	for (int i = 1; i <= n; ++i) {
		f2[i].z = lower_bound(lsh + 1, lsh + tot + 1, f2[i].z) - lsh;
	}
	sort(f2 + 1, f2 + n + 1, [&](const node2 &a, const node2 &b) {
		if (a.x != b.x) {
			return a.x < b.x;
		} else if (a.y != b.y) {
			return a.y > b.y;
		} else if (a.z != b.z) {
			return a.z > b.z;
		} else {
			return a.i < b.i;
		}
	});
	cdq2(1, n);
	n = tot = 0;
	for (int i = 1; i <= nt; ++i) {
		if (b[i].d <= 0) {
			continue;
		}
		int x = b[i].x - 1, y = b[i].y + b[i].d - 1, z = b[i].d;
		uint w = b[i].w;
		f2[++n] = node2(b[i].i, x, y, 0, -w, info2(3, -3U * x - 3, -6U * y - 3 + 6U * z, 3U * y * (y + 1) - 6U * z * (y + 1), 3U * (x + 1) * (y * 2 + 1) - 6U * z * (x + 1), -3U * (x + 1) * y * (y + 1) + 6U * z * (x + 1) * (y + 1)));
		x = b[i].x - 1;
		y = b[i].y - 1;
		z = 0;
		w = b[i].w;
		f2[++n] = node2(b[i].i, x, y, 0, w, info2(3, -3U * x - 3, -6U * y - 3 + 6U * z, 3U * y * (y + 1) - 6U * z * (y + 1), 3U * (x + 1) * (y * 2 + 1) - 6U * z * (x + 1), -3U * (x + 1) * y * (y + 1) + 6U * z * (x + 1) * (y + 1)));
	}
	for (int i = 1; i <= qt; ++i) {
		f2[++n] = node2(c[i].i, c[i].a, c[i].b, c[i].i, c[i].w, info2(1U * c[i].a * c[i].b * c[i].b, 1U * c[i].b * c[i].b, 1U * c[i].a * c[i].b, c[i].a, c[i].b, 1));
	}
	for (int i = 1; i <= n; ++i) {
		lsh[++tot] = f2[i].z;
	}
	sort(lsh + 1, lsh + tot + 1);
	tot = unique(lsh + 1, lsh + tot + 1) - lsh - 1;
	for (int i = 1; i <= n; ++i) {
		f2[i].z = lower_bound(lsh + 1, lsh + tot + 1, f2[i].z) - lsh;
	}
	sort(f2 + 1, f2 + n + 1, [&](const node2 &a, const node2 &b) {
		if (a.x != b.x) {
			return a.x < b.x;
		} else if (a.y != b.y) {
			return a.y > b.y;
		} else if (a.z != b.z) {
			return a.z > b.z;
		} else {
			return a.i < b.i;
		}
	});
	cdq2(1, n);
}

void solve() {
	m = read();
	// 1. (x, y) -> (y, x)
	for (int i = 1; i <= m; ++i) {
		a[i].o = read();
		a[i].a = read();
		a[i].b = read();
		a[i].c = read();
		a[i].d = read();
		if (a[i].o == 1) {
			int x = a[i].a, y = a[i].b, d = a[i].c, w = a[i].d;
			b[++nt] = tri(i, y, x - d + 1, d, w);
		} else {
			int xl = a[i].c, xr = a[i].d, yl = a[i].a, yr = a[i].b;
			c[++qt] = que(i, xl, yl, 1);
			c[++qt] = que(i, xl, yr + 1, -1);
			c[++qt] = que(i, xr + 1, yl, -1);
			c[++qt] = que(i, xr + 1, yr + 1, 1);
		}
	}
	work();
	// 2. (x, y) -> (-x, -y)
	nt = qt = 0;
	for (int i = 1; i <= m; ++i) {
		if (a[i].o == 1) {
			int x = a[i].a, y = a[i].b, d = a[i].c, w = a[i].d;
			b[++nt] = tri(i, -x, -(y + d - 1), d - 1, w);
		} else {
			int xl = -a[i].b, xr = -a[i].a, yl = -a[i].d, yr = -a[i].c;
			c[++qt] = que(i, xl, yl, 1);
			c[++qt] = que(i, xl, yr + 1, -1);
			c[++qt] = que(i, xr + 1, yl, -1);
			c[++qt] = que(i, xr + 1, yr + 1, 1);
		}
	}
	work();
	// 3. (x, y) -> (x, -y)
	nt = qt = 0;
	for (int i = 1; i <= m; ++i) {
		if (a[i].o == 1) {
			int x = a[i].a, y = a[i].b, d = a[i].c, w = a[i].d;
			b[++nt] = tri(i, x + 1, -(y + d - 1), d - 1, w);
		} else {
			int xl = a[i].a, xr = a[i].b, yl = -a[i].d, yr = -a[i].c;
			c[++qt] = que(i, xl, yl, 1);
			c[++qt] = que(i, xl, yr + 1, -1);
			c[++qt] = que(i, xr + 1, yl, -1);
			c[++qt] = que(i, xr + 1, yr + 1, 1);
		}
	}
	work();
	// 4. (x, y) -> (y, -x)
	nt = qt = 0;
	for (int i = 1; i <= m; ++i) {
		if (a[i].o == 1) {
			int x = a[i].a, y = a[i].b, d = a[i].c, w = a[i].d;
			b[++nt] = tri(i, y, -(x + d - 1), d - 1, w);
		} else {
			int xl = a[i].c, xr = a[i].d, yl = -a[i].b, yr = -a[i].a;
			c[++qt] = que(i, xl, yl, 1);
			c[++qt] = que(i, xl, yr + 1, -1);
			c[++qt] = que(i, xr + 1, yl, -1);
			c[++qt] = que(i, xr + 1, yr + 1, 1);
		}
	}
	work();
	// 5. (x, y) -> (-y, -x)
	nt = qt = 0;
	for (int i = 1; i <= m; ++i) {
		if (a[i].o == 1) {
			int x = a[i].a, y = a[i].b, d = a[i].c, w = a[i].d;
			b[++nt] = tri(i, -(y - 1), -(x + d - 1), d - 1, w);
		} else {
			int xl = -a[i].d, xr = -a[i].c, yl = -a[i].b, yr = -a[i].a;
			c[++qt] = que(i, xl, yl, 1);
			c[++qt] = que(i, xl, yr + 1, -1);
			c[++qt] = que(i, xr + 1, yl, -1);
			c[++qt] = que(i, xr + 1, yr + 1, 1);
		}
	}
	work();
	// 6. (x, y) -> (x, y)
	nt = qt = 0;
	for (int i = 1; i <= m; ++i) {
		if (a[i].o == 1) {
			int x = a[i].a, y = a[i].b, d = a[i].c, w = a[i].d;
			b[++nt] = tri(i, x, y - d + 1, d - 1, w);
		} else {
			int xl = a[i].a, xr = a[i].b, yl = a[i].c, yr = a[i].d;
			c[++qt] = que(i, xl, yl, 1);
			c[++qt] = que(i, xl, yr + 1, -1);
			c[++qt] = que(i, xr + 1, yl, -1);
			c[++qt] = que(i, xr + 1, yr + 1, 1);
		}
	}
	work();
	// 7. (x, y) -> (-x, y)
	nt = qt = 0;
	for (int i = 1; i <= m; ++i) {
		if (a[i].o == 1) {
			int x = a[i].a, y = a[i].b, d = a[i].c, w = a[i].d;
			b[++nt] = tri(i, -(x - 1), y - d + 1, d - 2, w);
		} else {
			int xl = -a[i].b, xr = -a[i].a, yl = a[i].c, yr = a[i].d;
			c[++qt] = que(i, xl, yl, 1);
			c[++qt] = que(i, xl, yr + 1, -1);
			c[++qt] = que(i, xr + 1, yl, -1);
			c[++qt] = que(i, xr + 1, yr + 1, 1);
		}
	}
	work();
	// 8. (x, y) -> (-y, x)
	nt = qt = 0;
	for (int i = 1; i <= m; ++i) {
		if (a[i].o == 1) {
			int x = a[i].a, y = a[i].b, d = a[i].c, w = a[i].d;
			b[++nt] = tri(i, -(y - 1), x - d + 1, d - 1, w);
		} else {
			int xl = -a[i].d, xr = -a[i].c, yl = a[i].a, yr = a[i].b;
			c[++qt] = que(i, xl, yl, 1);
			c[++qt] = que(i, xl, yr + 1, -1);
			c[++qt] = que(i, xr + 1, yl, -1);
			c[++qt] = que(i, xr + 1, yr + 1, 1);
		}
	}
	work();
	for (int i = 1; i <= m; ++i) {
		if (a[i].o == 2) {
			writeln(((ans[i] * inv3) >> 1) & ((1U << 30) - 1));
		}
	}
}

int main() {
	int T = 1;
	// scanf("%d", &T);
	while (T--) {
		solve();
	}
	return 0;
}

Details

Subtask #1:

score: 23
Accepted

Test #1:

score: 23
Accepted
time: 30ms
memory: 253160kb

Test #2:

score: 23
Accepted
time: 37ms
memory: 253392kb

Subtask #2:

score: 8
Accepted

Test #3:

score: 8
Accepted
time: 707ms
memory: 252620kb

Test #4:

score: 8
Accepted
time: 764ms
memory: 254108kb

Subtask #3:

score: 8
Accepted

Test #5:

score: 8
Accepted
time: 1508ms
memory: 253416kb

Test #6:

score: 8
Accepted
time: 1677ms
memory: 254756kb

Subtask #4:

score: 8
Accepted

Test #7:

score: 8
Accepted
time: 2404ms
memory: 253136kb

Test #8:

score: 8
Accepted
time: 2632ms
memory: 256472kb

Subtask #5:

score: 8
Accepted

Test #9:

score: 8
Accepted
time: 3335ms
memory: 260332kb

Test #10:

score: 8
Accepted
time: 3693ms
memory: 256808kb

Subtask #6:

score: 15
Accepted

Test #11:

score: 15
Accepted
time: 3768ms
memory: 258700kb

Test #12:

score: 15
Accepted
time: 3795ms
memory: 258628kb

Subtask #7:

score: 10
Accepted

Test #13:

score: 10
Accepted
time: 3742ms
memory: 258780kb

Test #14:

score: 10
Accepted
time: 4005ms
memory: 253272kb

Subtask #8:

score: 10
Accepted

Test #15:

score: 10
Accepted
time: 4043ms
memory: 258852kb

Test #16:

score: 10
Accepted
time: 4457ms
memory: 258844kb

Subtask #9:

score: 10
Accepted

Test #17:

score: 10
Accepted
time: 4227ms
memory: 253732kb

Test #18:

score: 10
Accepted
time: 4786ms
memory: 258804kb