QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#644064#8577. 평균 최대화user1008651 2690ms181688kbC++238.0kb2024-10-16 10:35:232024-10-16 10:35:29

Judging History

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

  • [2024-10-16 10:35:29]
  • 评测
  • 测评结果:51
  • 用时:2690ms
  • 内存:181688kb
  • [2024-10-16 10:35:23]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 3e5 + 10;

int n, idx, l[N], r[N], a[N], s[N], rx[N], rs[N];

// #define __int128 int

struct F
{
	__int128 i, j;
	
	F()
	{
		i = j = 0;
	}
	
	F(__int128 a, __int128 b)
	{
		__int128 d = __gcd(a, b);
		i = a / d, j = b / d;
	}
	
	bool operator> (const F& f2) const
	{
		return i * f2.j > j * f2.i;
	}
	
	bool operator< (const F& f2) const
	{
		return i * f2.j < j * f2.i;
	}
	
	F operator + (const F& f2) const
	{
		__int128 a = i * f2.j + j * f2.i, b = j * f2.j;
		return {a, b};
	}
	
	void reduce()
	{
		auto d = __gcd(i, j);
		i /= d, j /= d;
	}
	
}ans[N];



int pc;
mt19937 rng(20241015);
namespace Tree
{
	const int R = 2;
	int idx;
	int ls[N * R], rs[N * R], sz[N * R];
	F tass[N * R];
	F val[N * R], sum[N * R];
	
	void init()
	{
		val[0] = sum[0] = {0, 1};
	}
	
	int newnode(F v)
	{
		idx++;
		assert(idx < N * R);
		ls[idx] = rs[idx] = 0, sz[idx] = 1, tass[idx] = {0, 1};
		val[idx] = sum[idx] = v;
		return idx;
	}
	
	inline void pushup(int u)
	{
		if (!u) return;
	    pc++;
		sum[u] = sum[ls[u]] + val[u] + sum[rs[u]];
		sz[u] = sz[ls[u]] + 1 + sz[rs[u]];
	}
	
	inline void apply(int u, const F& dass)
	{
		if (!u) return;
		sum[u] = {dass.i * sz[u], dass.j}, val[u] = dass;
		tass[u] = dass;
	}
	
	inline void pushdown(int u)
	{
		if (!u) return;
		if (tass[u].i == 0) return;
	    pc++;
		apply(ls[u], tass[u]), apply(rs[u], tass[u]);
		tass[u] = {0, 1};
	}
	
	array<int, 2> splitr(int u, int k)
	{
		// [1, k], [k+1, inf)
//		printf("splitr(%lld, %lld)\n", u, k);
		if (!u) return {0, 0};
		pushdown(u);
		if (sz[ls[u]] >= k)
		{
			auto res = splitr(ls[u], k);
			ls[u] = res[1];
			pushup(u);
			return {res[0], u};
		}
		else
		{
			auto res = splitr(rs[u], k - sz[ls[u]] - 1);
			rs[u] = res[0];
			pushup(u);
//			printf("&&&");
			return {u, res[1]};
		}
	}
	
	array<int, 2> splitv(int u, const F& v)
	{
		// [1, v] [v, inf)
		if (!u) return {0, 0};
		pushdown(u);
		if (v > val[u])
		{
			auto res = splitv(ls[u], v);
			ls[u] = res[1];
			pushup(u);
			return {res[0], u};
		}
		else
		{
			auto res = splitv(rs[u], v);
			rs[u] = res[0];
			pushup(u);
			return {u, res[1]};
		}
	}
	
	int merge(int l, int r)
	{
//		printf("merge(%lld, %lld)\n", l, r);
		if (!l) swap(l, r);
		if (!r) return l;
		
		pushdown(l), pushdown(r);
		if (rng() % (sz[l] + sz[r]) < sz[l])
		{
			rs[l] = merge(rs[l], r);
			pushup(l);
			return l;
		}
		else
		{
			ls[r] = merge(l, ls[r]);
			pushup(r);
			return r;
		}
	}
	
	inline void insert(int& rt, const F& v)
	{
		auto res = splitv(rt, v);
		int c = newnode(v);
		rt = merge(merge(res[0], c), res[1]);
	}
	
	inline void assign(int& rt, int pos, const F& v)
	{
		auto res = splitr(rt, pos);
		apply(res[0], v);
		rt = merge(res[0], res[1]);
	}
	
	inline F qsum(int rt, int pos)
	{
	    if (!rt) return {0, 1};
	    pushdown(rt);
	    if (pos <= sz[ls[rt]]) return qsum(ls[rt], pos);
	    else return sum[ls[rt]] + val[rt] + qsum(rs[rt], pos - sz[ls[rt]] - 1);
// 		auto res = splitr(rt, pos);
//		printf("qsum(%lld, %lld)\n", rt, pos);
// 		F ret = sum[res[0]];
// 		rt = merge(res[0], res[1]);
// 		return ret;
	}
	
	F kth(int &rt, int k)
	{
	    int p = sz[ls[rt]];
	    pushdown(rt);
	    if (k <= p) return kth(ls[rt], k);
	    else if (k > p + 1) return kth(rs[rt], k - sz[ls[rt]] - 1);
	    else return val[rt];
// 		auto res = splitr(rt, k);
// 		auto res2 = splitr(res[0], k - 1);
// 		F ret = val[res2[1]];
// 		rt = merge(merge(res2[0], res2[1]), res[1]);
// 		return ret;	
	}
	
	void print(int rt)
	{
		if (!rt) return;
		print(ls[rt]), printf("node %lld: sum = %lld/%lld, val = %lld/%lld, tass = %lld/%lld, ls = %lld, rs = %lld\n", rt, sum[rt].i, sum[rt].j, val[rt].i, val[rt].j, tass[rt].i, tass[rt].j, ls[rt], rs[rt]), print(rs[rt]);
	}
}

// int pc;
int dp[N];
vector<int> son[N];
vector<int> rg[N];
map<array<int, 2>, int> mp;

int build(int l, int r)
{
	idx++, ::l[idx] = l, ::r[idx] = r, mp[{l, r}] = idx;
	int x = idx; rx[x] = r - l + 1, rs[x] = s[r] - s[l - 1];
	for (int i = l; i <= r; i++)
	{
		if (rg[i].empty()) continue;
		int j = rg[i].back(); rg[i].pop_back();
		int y = build(i, j);
		son[x].push_back(y);
		rx[x] -= (j - i + 1), rs[x] -= (s[j] - s[i - 1]);
		i = j;
	}
	return x;
}

template<class T>
void chkmax(T &x, T y)
{
	if (y > x) x = y;
}

int merge(int a, int b)
{
	if (!a) swap(a, b);
	if (!b) return a;
//	printf("merge(%lld, %lld)\n", a, b);
	if (Tree::sz[a] > Tree::sz[b]) swap(a, b);
	Tree::pushdown(a);
	F v = Tree::val[a];
	auto res = Tree::splitv(b, v);
	Tree::ls[a] = merge(Tree::ls[a], res[0]), Tree::rs[a] = merge(Tree::rs[a], res[1]);
	Tree::pushup(a);
	return a;
}

pair<int, F> getp(int& rt, int a, int b)
{
	// max (y - b) / (x - a)
	int l = 0, r = Tree::sz[rt];
	auto getres = [&](int x)
	{
		F y1 = Tree::qsum(rt, x);
		y1.i -= b * y1.j, y1.j *= (x - a);
//		y1.reduce();
		return y1;
	};
	while (l < r)
	{
//		int mid1 = (l + r) >> 1, mid2 = mid1 + 1;
		int mid = (l + r) >> 1;
		F f = Tree::qsum(rt, mid), d = Tree::kth(rt, mid + 1);
		f.i -= b * f.j, f.j *= (mid - a);
		if (f > d) r = mid;
		else l = mid + 1;
	}
//	printf(")))"), Tree::print(rt);
//	printf("res(l) = (%lld, %lld/%lld), res(r) = (%lld, %lld/%lld)\n", l, getres(l).i, getres(l).j, r, getres(r).i, getres(r).j);
	pc++;
	auto resl = getres(l);
	return {l, resl};
}

void dfs(int x)
{
//	printf("dfs(%lld)\n", x);
	dp[x] = 0;
	if (son[x].empty()) for (int i = 1; i <= rx[x]; i++) Tree::insert(dp[x], {rs[x], rx[x]});
	else 
	{
		for (int y : son[x]) dfs(y), dp[x] = merge(dp[x], dp[y]);
//		Tree::print(dp[x]);
//		 (-rx[x], -rs[x])
		auto res = getp(dp[x], -rx[x], -rs[x]);
//		printf("proc: res = {%lld, %lld/%lld}\n", res.first, res.second.i, res.second.j);
		int p = res.first;
		F v = res.second;
		Tree::assign(dp[x], p, v);
		for (int i = 1; i <= rx[x]; i++) Tree::insert(dp[x], v);
	}
//	Tree::print(dp[x]);
//	cout << "***";
	auto res = getp(dp[x], -2, -(a[l[x] - 1] + a[r[x] + 1]));
	ans[x] = res.second;
//	printf("%lld: (%lld, %lld/%lld)\n", x, res.first, ans[x].i, ans[x].j);
}

void initialize(vector<signed> A)
{
    n = (int)(A.size());
    for (int i = 1; i <= n; i++) a[i] = A[i - 1];
	for (int i = 1; i <= n; i++) s[i] = a[i] + s[i - 1];
    vector<int> s;
    for (int i = n; i >= 1; i--)
    {
    	while (!s.empty() && a[s.back()] > a[i])
    	{
    		int x = s.back(); s.pop_back();
    		if (x != i + 1) rg[i + 1].push_back(x - 1);
    	}
    	if (!s.empty() && s.back() != i + 1) rg[i + 1].push_back(s.back() - 1); 
    	if (!s.empty() && a[s.back()] >= a[i]) s.pop_back();
    	s.push_back(i);
    }
//	for (int i = 1; i <= n; i++)
//		for (int j : rg[i]) printf("[%lld, %lld]\n", i, j);
    
    build(2, n - 1);
//    for (int i = 1; i <= n; i++)
//    	printf("rx[%lld] = %lld, rs[%lld] = %lld\n", i, rx[i], i, rs[i]);
    Tree::init();
    dfs(1);
    
//    for (int i = 1; i <= n; i++)
//    	for (int j = 0; j <= sz[i]; j++)
//    		printf("dp[%lld][%lld] = %lld\n", i, j, dp[i][j]);
    
//    for (int i = 1; i <= n; i++)
//    	for (int j : son[i]) printf("[%lld, %lld] -> [%lld, %lld]\n", l[i], r[i], l[j], r[j]);
}

array<long long, 2> maximum_average(signed i, signed j)
{
	i++, j++;
	if (j == i + 1) return {a[i] + a[j], 2};
	assert(mp.find({i + 1, j - 1}) != mp.end());
	int id = mp[{i + 1, j - 1}];
	return {ans[id].i, ans[id].j};
}

//signed main()
//{
//	cin.tie(0)->sync_with_stdio(0);
//	
//	int n; cin >> n;
//	vector<signed> A;
//	for (int i = 1, ai; i <= n; i++) cin >> ai, A.push_back(ai); 
////	for (int i = 1, ai; i <= n; i++) A.push_back(rng() % 10000000 + 1);
//	initialize(A);
//	printf("idx = %lld, pc = %lld, time = %lld\n", idx, pc, (int)clock());
//	int l, r;
//	while (cin >> l >> r)
//	{
//		auto res = maximum_average(l, r);
//		cout << res[0] << ' ' << res[1] << '\n';
//	}
//}

详细

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 3ms
memory: 89848kb

input:

10
2 4 3 9 9 9 9 9 9 1
2
0 2
0 9

output:

9 3
60 9

result:

ok correct!

Test #2:

score: 5
Accepted
time: 7ms
memory: 87764kb

input:

15
4596730 8340349 4612555 5692442 3914918 5213545 5248236 1276073 3844119 2943960 9231647 5091649 2239006 9139001 4735414
100
7 8
5 6
2 4
0 4
8 9
10 11
3 4
0 1
10 11
10 11
3 4
4 5
12 13
0 2
2 4
11 12
12 14
2 3
7 8
12 14
6 7
4 5
11 12
10 11
7 12
8 9
8 9
0 2
2 3
12 14
7 9
7 9
12 13
10 11
9 11
13 14
8...

output:

5120192 2
10461781 2
14219915 3
27156994 5
6788079 2
14323296 2
9607360 2
12937079 2
14323296 2
14323296 2
9607360 2
9128463 2
11378007 2
17549634 3
14219915 3
7330655 2
16113421 3
10304997 2
5120192 2
16113421 3
6524309 2
9128463 2
7330655 2
14323296 2
20782335 5
6788079 2
6788079 2
17549634 3
1030...

result:

ok correct!

Test #3:

score: 5
Accepted
time: 103ms
memory: 85828kb

input:

15
962724 8815662 7612372 5708998 125165 5107756 9366378 9514244 2381600 4299006 9423670 8225791 7458292 2315903 7210561
600000
7 8
0 4
6 8
9 10
11 12
4 5
13 14
8 13
9 11
2 3
7 8
9 12
6 8
0 4
0 2
12 13
1 2
8 13
0 3
9 10
4 5
6 7
6 8
6 7
0 2
4 13
3 4
6 7
8 9
6 7
11 12
5 8
0 3
9 13
4 8
4 8
8 9
8 13
4 1...

output:

11895844 2
23224921 5
21262222 3
13722676 2
15684083 2
5232921 2
9526464 2
34104262 6
21948467 3
13321370 2
11895844 2
29406759 4
21262222 3
23224921 5
17390758 3
9774195 2
16428034 2
34104262 6
23099756 4
13722676 2
5232921 2
18880622 2
21262222 3
18880622 2
17390758 3
58217805 10
5834163 2
1888062...

result:

ok correct!

Test #4:

score: 5
Accepted
time: 0ms
memory: 87800kb

input:

15
1 8446287 2 999999 3000000 5533975 3000000 3816891 3000000 7671276 3000000 999999 5836790 8574548 1
23
0 14
1 2
0 1
2 14
0 2
3 11
2 3
4 6
3 4
5 6
4 5
6 8
7 8
6 7
8 10
9 10
8 9
10 11
11 14
12 14
11 12
13 14
12 13

output:

53879769 15
8446289 2
8446288 2
45433481 13
8446290 3
31022140 9
1000001 2
11533975 3
3999999 2
8533975 2
8533975 2
9816891 3
6816891 2
6816891 2
13671276 3
10671276 2
10671276 2
3999999 2
15411338 4
14411339 3
6836789 2
8574549 2
14411338 2

result:

ok correct!

Test #5:

score: 5
Accepted
time: 0ms
memory: 87832kb

input:

15
1 15 16 14 18 13 20 12 22 11 24 10 26 9 1
27
0 14
1 3
0 1
2 3
1 2
3 5
0 3
4 5
3 4
5 7
0 5
6 7
5 6
7 9
0 7
8 9
7 8
9 11
0 9
10 11
9 10
11 13
0 11
12 13
11 12
13 14
0 13

output:

212 15
45 3
16 2
30 2
31 2
45 3
46 4
31 2
32 2
45 3
77 6
32 2
33 2
45 3
109 8
33 2
34 2
45 3
142 10
34 2
35 2
45 3
176 12
35 2
36 2
10 2
211 14

result:

ok correct!

Subtask #2:

score: 6
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 6
Accepted
time: 0ms
memory: 88112kb

input:

48
225555 4046145 5839635 7194994 4703765 1253415 2526352 3198926 6313532 2368195 5024833 9436074 1792945 7650559 3393464 2402026 7697170 5205463 9830460 5392966 1687150 9984223 3014343 8856776 1412298 9773499 6469768 5802450 758943 2748325 7110370 4498454 2674137 8596714 8823659 9855644 6654297 367...

output:

24413198 4
16509941 2
17738394 3
45052203 9
17031286 4
24413198 4
11608824 2
45052203 9
17738394 3
13283417 3
9885780 2
23458015 4
14460907 2
5795490 2
25333600 3
11880653 3
7923098 2
23037954 5
131217114 26
22841241 3
10545933 2
17738394 3
13283417 3
18983962 3
17655565 3
11270851 2
8261027 2
13121...

result:

ok correct!

Test #7:

score: 6
Accepted
time: 113ms
memory: 87864kb

input:

50
7121308 7345583 6899063 282017 6341784 3680369 5436234 9663519 633330 6333746 7783999 6482701 567072 4276742 8011254 1944632 5712778 8002712 306241 4160326 5728910 1328677 6357927 2565549 4232827 255999 3544802 2039097 494486 2383883 9963617 175242 2913048 5502915 9123911 4881811 2516781 8926134 ...

output:

5394962 2
12522742 3
14466891 2
12347500 2
4567430 2
14631630 3
6947205 2
14631630 3
15966363 4
75715129 17
15966363 4
12522742 3
6967076 2
3800801 2
6334384 4
2533583 2
69914912 15
4488826 2
75459130 16
14626826 2
2533583 2
15733083 3
15099753 2
10138859 2
75459130 16
8415963 2
4567430 2
10252153 3...

result:

ok correct!

Test #8:

score: 6
Accepted
time: 0ms
memory: 87752kb

input:

50
1 3859136 7745573 6119170 3863010 2 3 4 3498508 5 6608915 6662164 999999 3000000 7880751 3000000 4473437 3000000 7609368 3000000 4750778 3000000 8554401 3000000 5166495 3000000 4156171 3000000 9941061 3000000 7323881 3000000 3334344 3000000 3959127 3000000 999999 6 5 5322820 9189056 4 8127987 797...

output:

185663885 48
21586891 5
3859137 2
13864743 2
11604709 2
9982180 2
17723879 3
3863012 2
21586889 4
164076994 42
21586892 6
145705920 37
5 2
129598447 33
7 2
3498513 2
3498512 2
111127436 28
3498517 3
14271078 3
6608920 2
7662163 2
13271079 2
93700170 22
14271083 4
13880751 3
3999999 2
10880751 2
1088...

result:

ok correct!

Test #9:

score: 6
Accepted
time: 11ms
memory: 87808kb

input:

50
1 50 51 49 53 48 55 47 57 46 59 45 61 44 63 43 65 42 67 41 69 40 71 39 73 38 75 37 77 36 79 35 81 34 83 33 85 32 87 31 89 30 91 29 93 28 95 27 97 1
97
0 49
1 3
0 1
2 3
1 2
3 5
0 3
4 5
3 4
5 7
0 5
6 7
5 6
7 9
0 7
8 9
7 8
9 11
0 9
10 11
9 10
11 13
0 11
12 13
11 12
13 15
0 13
14 15
13 14
15 17
0 15
...

output:

1757 32
150 3
51 2
100 2
101 2
150 3
151 4
101 2
102 2
150 3
252 6
102 2
103 2
150 3
354 8
103 2
104 2
150 3
457 10
104 2
105 2
150 3
561 12
105 2
106 2
150 3
666 14
106 2
107 2
150 3
772 16
107 2
108 2
150 3
879 18
108 2
109 2
150 3
987 20
109 2
110 2
150 3
1096 22
110 2
111 2
150 3
1206 24
111 2
1...

result:

ok correct!

Subtask #3:

score: 13
Accepted

Dependency #2:

100%
Accepted

Test #10:

score: 13
Accepted
time: 116ms
memory: 89832kb

input:

240
6858784 4989917 9746109 9800650 9356541 6503323 7401498 4493451 2801567 3386165 2481047 9837911 8949606 8663384 5535990 833163 922389 2217653 4643612 8798924 859732 616449 7786902 4457600 9298353 6097782 1517199 1575123 3272602 8273488 8507227 5716403 4182244 3701458 1150320 7526997 7126600 8466...

output:

16368254 2
7471044 2
11386428 3
3195008 2
9658656 2
15523880 2
3140042 2
57491667 9
9688346 3
3267230 2
10959355 2
11038795 2
9761526 2
7883702 2
14605972 2
15088697 2
17640709 2
4918214 2
36301101 6
14887508 5
6296185 2
876017 2
6164558 2
13307829 3
19546759 2
8377911 2
14987510 3
20631197 3
183982...

result:

ok correct!

Test #11:

score: 13
Accepted
time: 127ms
memory: 89880kb

input:

250
9162966 9250357 6273148 7600740 9150271 3440942 4849415 2773878 7306022 1849591 6777991 6901659 4064680 3770893 2377669 3403916 1041109 5311874 292665 7289044 3159603 8135675 2072980 3799891 6274489 6899891 9079095 2442557 7502677 3860726 6264634 6932504 7576167 5899943 684774 526401 3720387 478...

output:

13245794 2
11742785 2
6031433 2
74730005 14
6162102 2
20191953 3
6228058 2
9328707 2
21410916 4
19593921 4
15150407 2
9772981 2
13298615 3
11521652 2
19258320 3
12591217 2
11742785 2
39810154 7
34160076 7
10272681 3
10818508 2
16260670 4
16893087 2
96998646 18
15978986 2
21633918 3
10682015 2
312230...

result:

ok correct!

Test #12:

score: 13
Accepted
time: 0ms
memory: 88136kb

input:

250
1 2 3 4 3023964 5 6 9869160 7 8 9359655 9 10 11 5236313 12 6350687 9627762 13 8024104 6527059 3760432 14 15 8480107 16 5445579 7101107 17 18 19 20 7945165 8246903 21 22 23 5152223 24 25 5367561 5181329 9262413 8141382 9514495 26 27 7821178 28 7804811 4208465 6461584 3421272 6286889 4843702 31961...

output:

218222325 47
193204775 42
3 2
183143121 38
5 2
109375705 21
7 2
3023969 2
3023968 2
109375697 19
3023973 3
898221189 203
11 2
9869167 2
9869166 2
864311896 196
9869173 3
824453783 188
15 2
9359664 2
9359663 2
802051218 183
9359672 3
802051200 181
19 2
788141559 177
21 2
5236325 2
5236324 2
108235172...

result:

ok correct!

Test #13:

score: 13
Accepted
time: 0ms
memory: 87940kb

input:

250
1 250 251 249 253 248 255 247 257 246 259 245 261 244 263 243 265 242 267 241 269 240 271 239 273 238 275 237 277 236 279 235 281 234 283 233 285 232 287 231 289 230 291 229 293 228 295 227 297 226 299 225 301 224 303 223 305 222 307 221 309 220 311 219 313 218 315 217 317 216 319 215 321 214 32...

output:

20657 70
750 3
251 2
500 2
501 2
750 3
751 4
501 2
502 2
750 3
1252 6
502 2
503 2
750 3
1754 8
503 2
504 2
750 3
2257 10
504 2
505 2
750 3
2761 12
505 2
506 2
750 3
3266 14
506 2
507 2
750 3
3772 16
507 2
508 2
750 3
4279 18
508 2
509 2
750 3
4787 20
509 2
510 2
750 3
5296 22
510 2
511 2
750 3
5806 ...

result:

ok correct!

Test #14:

score: 13
Accepted
time: 8ms
memory: 89832kb

input:

127
1 25 6 44 6 25 5 83 5 25 6 44 6 25 4 162 4 25 6 44 6 25 5 83 5 25 6 44 6 25 3 321 3 25 6 44 6 25 5 83 5 25 6 44 6 25 4 162 4 25 6 44 6 25 5 83 5 25 6 44 6 25 2 640 2 25 6 44 6 25 5 83 5 25 6 44 6 25 4 162 4 25 6 44 6 25 5 83 5 25 6 44 6 25 3 321 3 25 6 44 6 25 5 83 5 25 6 44 6 25 4 162 4 25 6 44...

output:

646 5
31 2
26 2
56 3
32 3
50 2
50 2
36 3
30 2
31 2
93 3
112 7
88 2
88 2
115 7
31 2
30 2
56 3
36 3
50 2
50 2
35 3
29 2
31 2
170 3
310 15
166 2
166 2
312 15
31 2
29 2
56 3
35 3
50 2
50 2
36 3
30 2
31 2
93 3
115 7
88 2
88 2
114 7
31 2
30 2
56 3
36 3
50 2
50 2
34 3
28 2
31 2
327 3
174 5
324 2
324 2
175 ...

result:

ok correct!

Subtask #4:

score: 7
Accepted

Test #15:

score: 7
Accepted
time: 1293ms
memory: 112916kb

input:

300000
1 2 4 4 4 4 3 2 4 4 3 4 4 4 4 4 4 4 4 4 3 4 3 4 4 4 4 4 4 4 4 3 3 4 4 4 3 4 3 4 4 4 4 4 4 4 4 4 4 3 3 4 4 4 3 4 4 3 4 4 4 4 4 4 4 3 2 4 4 4 4 4 4 4 4 4 4 4 4 4 3 4 4 4 4 4 4 4 4 4 4 4 2 4 4 2 4 4 3 4 4 4 2 3 4 4 4 4 4 4 3 2 4 4 4 2 4 4 4 4 4 4 4 4 4 4 4 2 4 4 4 4 4 4 3 4 4 3 4 4 4 4 4 4 4 4 4...

output:

1041675 278497
23 7
3 2
8 2
6 2
8 2
8 2
7 2
5 2
21 6
224 60
8 2
6 2
7 2
42 11
13 4
8 2
7 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
7 2
10 3
7 2
7 2
38 10
8 2
7 2
8 2
8 2
8 2
8 2
8 2
8 2
7 2
6 2
18 5
8 2
7 2
8 2
7 2
10 3
7 2
7 2
46 12
8 2
7 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
8 2
7 2
6 2
18 5
8 2
7 2
8 2
7 2
14 4
8 2
...

result:

ok correct!

Subtask #5:

score: 12
Accepted

Dependency #3:

100%
Accepted

Test #16:

score: 12
Accepted
time: 176ms
memory: 88752kb

input:

4000
4344032 9677834 5779172 78801 469320 1789966 1779748 3147679 5049607 6295414 6292231 5874387 8807832 5984181 3228577 3529357 528332 6386101 1795741 5602976 8304581 9750737 24760 627728 7325309 4243675 8356932 6633243 445885 1321623 2252967 181037 8074790 4491070 2320473 8159338 7402667 7485053 ...

output:

22764270 4
19014468 5
2589999 2
14894720 2
20540618 3
6556703 2
10536626 2
18763865 3
12480768 3
5265577 2
33745074 5
19392021 6
18380111 4
5961475 2
3185139 2
15747508 2
28358687 4
10867326 3
16924002 2
36799829 10
15816520 2
10606278 2
23916599 3
38151559 7
3124773 2
11841580 2
7572240 2
6991940 2...

result:

ok correct!

Test #17:

score: 12
Accepted
time: 166ms
memory: 88660kb

input:

5000
5790446 4508837 9162136 7149900 6430421 1083368 7398254 672635 6289758 2685219 3248824 7705887 2673096 4210193 980601 8521989 5854838 7771569 4286354 9314430 2298604 7164231 5788878 8584031 101973 3153368 4450775 689282 512512 1525682 5373630 9650756 2076382 8232162 6919671 9574533 1484038 1977...

output:

8509384 2
28428602 5
11860325 2
44963154 11
6131415 3
16158237 2
13912744 4
4721965 2
67286440 11
13896336 2
13929234 3
23806767 5
13519895 2
407215453 71
56564231 10
15190255 4
11860325 2
13307255 2
22668102 5
12072576 2
29196150 4
11828186 2
112029242 19
5989987 2
32620442 6
4932732 2
11374206 2
2...

result:

ok correct!

Test #18:

score: 12
Accepted
time: 76ms
memory: 90556kb

input:

5000
1 4607944 9209259 5347502 4531540 2 4631148 5114154 5933715 8958872 9999015 7211944 8879151 6894166 3723688 3 3340071 4 8339511 5 5412818 3698545 5920965 6 7 4632316 7761575 6047136 8780729 4902685 8 4052029 4707285 9 9106150 8490532 10 5614384 9995766 8159200 11 3778686 12 13 8637120 14 784611...

output:

119246943 24
23696245 4
4607945 2
14556761 2
13817203 2
9879042 2
19164705 3
4531542 2
23696246 5
61345863 13
23696248 6
61345853 9
4631150 2
56714705 8
9745302 2
51600551 7
11047869 2
26169831 3
14892587 2
17210959 2
18957887 2
22985261 3
32103546 4
15773317 2
16091095 2
10617854 2
47876863 6
37236...

result:

ok correct!

Test #19:

score: 12
Accepted
time: 24ms
memory: 89180kb

input:

5000
1 5000 5001 4999 5003 4998 5005 4997 5007 4996 5009 4995 5011 4994 5013 4993 5015 4992 5017 4991 5019 4990 5021 4989 5023 4988 5025 4987 5027 4986 5029 4985 5031 4984 5033 4983 5035 4982 5037 4981 5039 4980 5041 4979 5043 4978 5045 4977 5047 4976 5049 4975 5051 4974 5053 4973 5055 4972 5057 497...

output:

1950099 316
15000 3
5001 2
10000 2
10001 2
15000 3
15001 4
10001 2
10002 2
15000 3
25002 6
10002 2
10003 2
15000 3
35004 8
10003 2
10004 2
15000 3
45007 10
10004 2
10005 2
15000 3
55011 12
10005 2
10006 2
15000 3
65016 14
10006 2
10007 2
15000 3
75022 16
10007 2
10008 2
15000 3
85029 18
10008 2
1000...

result:

ok correct!

Test #20:

score: 12
Accepted
time: 4ms
memory: 87784kb

input:

255
1 26 7 45 7 26 6 84 6 26 7 45 7 26 5 163 5 26 7 45 7 26 6 84 6 26 7 45 7 26 4 322 4 26 7 45 7 26 6 84 6 26 7 45 7 26 5 163 5 26 7 45 7 26 6 84 6 26 7 45 7 26 3 641 3 26 7 45 7 26 6 84 6 26 7 45 7 26 5 163 5 26 7 45 7 26 6 84 6 26 7 45 7 26 4 322 4 26 7 45 7 26 6 84 6 26 7 45 7 26 5 163 5 26 7 45...

output:

1286 5
33 2
27 2
59 3
34 3
52 2
52 2
39 3
32 2
33 2
96 3
118 7
90 2
90 2
122 7
33 2
32 2
59 3
39 3
52 2
52 2
38 3
31 2
33 2
173 3
324 15
168 2
168 2
327 15
33 2
31 2
59 3
38 3
52 2
52 2
39 3
32 2
33 2
96 3
122 7
90 2
90 2
121 7
33 2
32 2
59 3
39 3
52 2
52 2
37 3
30 2
33 2
330 3
178 5
326 2
326 2
180...

result:

ok correct!

Test #21:

score: 12
Accepted
time: 3ms
memory: 90216kb

input:

2047
1 29 10 48 10 29 9 87 9 29 10 48 10 29 8 166 8 29 10 48 10 29 9 87 9 29 10 48 10 29 7 325 7 29 10 48 10 29 9 87 9 29 10 48 10 29 8 166 8 29 10 48 10 29 9 87 9 29 10 48 10 29 6 644 6 29 10 48 10 29 9 87 9 29 10 48 10 29 8 166 8 29 10 48 10 29 9 87 9 29 10 48 10 29 7 325 7 29 10 48 10 29 9 87 9 2...

output:

10246 5
39 2
30 2
68 3
40 3
58 2
58 2
48 3
38 2
39 2
105 3
136 7
96 2
96 2
143 7
39 2
38 2
68 3
48 3
58 2
58 2
47 3
37 2
39 2
182 3
366 15
174 2
174 2
372 15
39 2
37 2
68 3
47 3
58 2
58 2
48 3
38 2
39 2
105 3
143 7
96 2
96 2
142 7
39 2
38 2
68 3
48 3
58 2
58 2
46 3
36 2
39 2
339 3
190 5
332 2
332 2
...

result:

ok correct!

Test #22:

score: 12
Accepted
time: 7ms
memory: 90568kb

input:

4095
1 30 11 49 11 30 10 88 10 30 11 49 11 30 9 167 9 30 11 49 11 30 10 88 10 30 11 49 11 30 8 326 8 30 11 49 11 30 10 88 10 30 11 49 11 30 9 167 9 30 11 49 11 30 10 88 10 30 11 49 11 30 7 645 7 30 11 49 11 30 10 88 10 30 11 49 11 30 9 167 9 30 11 49 11 30 10 88 10 30 11 49 11 30 8 326 8 30 11 49 11...

output:

20486 5
41 2
31 2
71 3
42 3
60 2
60 2
51 3
40 2
41 2
108 3
142 7
98 2
98 2
150 7
41 2
40 2
71 3
51 3
60 2
60 2
50 3
39 2
41 2
185 3
380 15
176 2
176 2
387 15
41 2
39 2
71 3
50 3
60 2
60 2
51 3
40 2
41 2
108 3
150 7
98 2
98 2
149 7
41 2
40 2
71 3
51 3
60 2
60 2
49 3
38 2
41 2
342 3
194 5
334 2
334 2
...

result:

ok correct!

Test #23:

score: 12
Accepted
time: 20ms
memory: 90724kb

input:

5000
1 501 502 500 504 499 506 498 508 497 510 496 512 495 514 494 516 493 518 492 520 491 522 490 524 489 526 488 528 487 530 486 532 485 534 484 536 483 538 482 540 481 542 480 544 479 546 478 548 477 550 476 552 475 554 474 556 473 558 472 560 471 562 470 564 469 566 468 568 467 570 466 572 465 5...

output:

541652 896
1503 3
502 2
1002 2
1003 2
1503 3
1504 4
1003 2
1004 2
1503 3
2507 6
1004 2
1005 2
1503 3
3511 8
1005 2
1006 2
1503 3
4516 10
1006 2
1007 2
1503 3
5522 12
1007 2
1008 2
1503 3
6529 14
1008 2
1009 2
1503 3
7537 16
1009 2
1010 2
1503 3
8546 18
1010 2
1011 2
1503 3
9556 20
1011 2
1012 2
1503...

result:

ok correct!

Test #24:

score: 12
Accepted
time: 16ms
memory: 90760kb

input:

5000
1 501 502 500 504 499 506 498 508 497 510 496 512 495 514 494 516 493 518 492 520 491 522 490 524 489 526 488 528 487 530 486 532 485 534 484 536 483 538 482 540 481 542 480 544 479 546 478 548 477 550 476 552 475 554 474 556 473 558 472 560 471 562 470 564 469 566 468 568 467 570 466 572 465 5...

output:

541652 896
1503 3
502 2
1002 2
1003 2
1503 3
1504 4
1003 2
1004 2
1503 3
2507 6
1004 2
1005 2
1503 3
3511 8
1005 2
1006 2
1503 3
4516 10
1006 2
1007 2
1503 3
5522 12
1007 2
1008 2
1503 3
6529 14
1008 2
1009 2
1503 3
7537 16
1009 2
1010 2
1503 3
8546 18
1010 2
1011 2
1503 3
9556 20
1011 2
1012 2
1503...

result:

ok correct!

Test #25:

score: 12
Accepted
time: 22ms
memory: 90680kb

input:

5000
1 501 502 500 504 499 506 498 508 497 510 496 512 495 514 494 516 493 518 492 520 491 522 490 524 489 526 488 528 487 530 486 532 485 534 484 536 483 538 482 540 481 542 480 544 479 546 478 548 477 550 476 552 475 554 474 556 473 558 472 560 471 562 470 564 469 566 468 568 467 570 466 572 465 5...

output:

541652 896
1503 3
502 2
1002 2
1003 2
1503 3
1504 4
1003 2
1004 2
1503 3
2507 6
1004 2
1005 2
1503 3
3511 8
1005 2
1006 2
1503 3
4516 10
1006 2
1007 2
1503 3
5522 12
1007 2
1008 2
1503 3
6529 14
1008 2
1009 2
1503 3
7537 16
1009 2
1010 2
1503 3
8546 18
1010 2
1011 2
1503 3
9556 20
1011 2
1012 2
1503...

result:

ok correct!

Test #26:

score: 12
Accepted
time: 83ms
memory: 89264kb

input:

5000
1 13191 2 13117 3 14564 4 12841 5 11947 6 11195 7 12561 8 14392 9 14173 10 10705 11 14501 12 11566 13 13912 14 10713 15 13964 16 11257 17 10698 18 10278 19 11654 20 13867 21 10403 22 11762 23 13165 24 10962 25 14600 26 13037 27 14608 28 12205 29 11600 30 10477 31 12329 32 13661 33 11923 34 1229...

output:

17963317 2802
13193 2
13192 2
17939363 2798
13194 3
13120 2
13119 2
17914658 2794
13122 3
14568 2
14567 2
17887789 2790
14571 3
12846 2
12845 2
17862042 2786
12850 3
11953 2
11952 2
17839782 2782
11958 3
11202 2
11201 2
17817432 2778
11208 3
12569 2
12568 2
17794461 2774
12576 3
14401 2
14400 2
1776...

result:

ok correct!

Test #27:

score: 12
Accepted
time: 413ms
memory: 90720kb

input:

5000
1 7777312 2 8356143 3 7519179 4 8003378 5 8052587 6 7524993 7 5755654 8 4627963 9 7178310 10 4252506 11 5608873 12 8718358 13 7193653 14 9119083 15 7502105 16 6529929 17 7288953 18 6206075 19 8026664 20 9185515 21 7337300 22 8404763 23 9173143 24 5485785 25 9654686 26 6484484 27 7992103 28 7959...

output:

19240167547 4894
7777314 2
7777313 2
19228090056 4890
7777315 3
8356146 2
8356145 2
19211228705 4886
8356148 3
7519183 2
7519182 2
19194465804 4882
7519186 3
8003383 2
8003382 2
19176541160 4878
8003387 3
8052593 2
8052592 2
19160351020 4874
8052598 3
7525000 2
7524999 2
19148727264 4870
7525006 3
5...

result:

ok correct!

Subtask #6:

score: 0
Time Limit Exceeded

Test #28:

score: 17
Accepted
time: 2690ms
memory: 181688kb

input:

300000
1 300000 300001 299999 300003 299998 300005 299997 300007 299996 300009 299995 300011 299994 300013 299993 300015 299992 300017 299991 300019 299990 300021 299989 300023 299988 300025 299987 300027 299986 300029 299985 300031 299984 300033 299983 300035 299982 300037 299981 300039 299980 3000...

output:

917250302 2450

result:

ok correct!

Test #29:

score: 17
Accepted
time: 530ms
memory: 140788kb

input:

262143
1 36 17 55 17 36 16 94 16 36 17 55 17 36 15 173 15 36 17 55 17 36 16 94 16 36 17 55 17 36 14 332 14 36 17 55 17 36 16 94 16 36 17 55 17 36 15 173 15 36 17 55 17 36 16 94 16 36 17 55 17 36 13 651 13 36 17 55 17 36 16 94 16 36 17 55 17 36 15 173 15 36 17 55 17 36 16 94 16 36 17 55 17 36 14 332 ...

output:

1310726 5

result:

ok correct!

Test #30:

score: 17
Accepted
time: 2483ms
memory: 94048kb

input:

30000
1 8655519 5053769 2 3 4 5 6991720 3321347 8718018 4464302 8356978 6 7 8 8314637 5910310 3734266 7192139 9183941 9 4352483 6266035 4417558 10 6855725 6999520 4363735 11 12 3499845 8360666 13 14 15 16 9638440 7317746 17 9282787 18 7466678 7930596 9367029 9821794 19 9771448 5441062 6451096 328952...

output:

1506711094 313

result:

ok correct!

Test #31:

score: 0
Time Limit Exceeded

input:

290000
1 2 6720098 9810682 9668570 8703077 7145578 8284345 5251625 6142206 3 4 5 6 9581548 3001002 3225039 8794590 7 7045505 4451229 5589636 8 5839563 9 4221964 4476182 9093685 6987982 8939207 10 5185060 5575428 4771993 6420287 11 5731640 9062305 12 4033948 6267196 9720880 9696770 8607688 7778692 13...

output:

Unauthorized output

result:


Subtask #7:

score: 8
Accepted

Dependency #4:

100%
Accepted

Test #44:

score: 8
Accepted
time: 569ms
memory: 118020kb

input:

300000
1 18 20 20 20 18 20 19 19 20 20 20 20 20 20 20 20 20 20 20 20 20 13 20 18 20 20 20 20 20 20 20 16 20 20 20 20 20 20 19 18 20 20 20 20 20 18 20 20 20 20 19 20 20 20 20 20 20 20 20 20 20 14 19 20 20 19 20 20 20 19 19 20 18 18 12 20 19 20 20 20 20 20 20 20 11 20 20 14 20 19 19 20 20 20 20 20 20 ...

output:

398307 20360
96 5
19 2
40 2
38 2
40 2
38 2
349 18
39 2
38 2
38 2
57 3
292 15
40 2
39 2
40 2
40 2
40 2
40 2
40 2
40 2
40 2
40 2
40 2
40 2
40 2
33 2
1039 54
428 23
38 2
33 2
174 9
51 3
40 2
38 2
40 2
40 2
40 2
40 2
40 2
36 2
604 31
207 11
40 2
36 2
40 2
40 2
40 2
40 2
39 2
37 2
155 8
136 7
173 9
40 2
...

result:

ok correct!

Subtask #8:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

0%