QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#720863#9563. 人间应又雪chenxinyang2006100 ✓866ms70308kbC++203.5kb2024-11-07 14:30:492024-11-07 14:30:49

Judging History

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

  • [2024-11-07 14:30:49]
  • 评测
  • 测评结果:100
  • 用时:866ms
  • 内存:70308kb
  • [2024-11-07 14:30:49]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;

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

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

inline int popcnt(int x){
	return __builtin_popcount(x);
}

inline int ctz(int x){
	return __builtin_ctz(x);
}


/*ll power(ll p,int k = mod - 2){
	ll ans = 1;
	while(k){
		if(k % 2 == 1) ans = ans * p % mod;
		p = p * p % mod;
		k /= 2;	
	}
	return ans;
}*/
int T,testid;
int n,m,c;
int a[500005];

struct fenwick{
	#define lowbit(x) (x & (-x))
	int tree[500005],bas;
	void init(){
		bas = 0;
		rep(i,1,m) tree[i] = lowbit(i);
	}
	void upd(int pos,int C){
		while(pos <= m){
			tree[pos] += C;
			pos += lowbit(pos);
		}
	}
	int qry(int pos){
		int ret = 0;
		while(pos){
			ret += tree[pos];
			pos -= lowbit(pos);
		}
		return ret;
	}
	int kth(int k){
		int pos = 0;
		per(_k,__lg(m),0){
			if(pos + (1 << _k) <= m && k > tree[pos + (1 << _k)]){
				pos += 1 << _k;
				k -= tree[pos];
			}
		}
		return pos + 1;
	}
	void rmv(int pos){
		upd(pos,-1);
		bas++;
	}
	int del(int k){
		if(bas >= k) return 0;
		int pos = kth(k - bas);
		rmv(pos);
		return pos;
	}
	int eval(int p){
		return bas + qry(p);
	}
}SS;

struct ds{
	int occ[500005],answer,pos;
	void init(){
		fill(occ,occ + m + 1,-1);
		answer = m;
		pos = m;
	}
	void rmv(int p){//[1,p) prefix add
		occ[p - 1]++;
		if(pos < p) answer++;
	}
	int eval(){
		if(pos >= 0) return answer;
		return -inf;
	}
	void dec(){
		pos--;
		if(pos >= 0) answer += occ[pos];
	}
}pst,nxt;

vector <int> S[2][500005];
void prepare(int op){
	SS.init();
	rep(i,1,n){
		int cur = a[i];
		while(1){
			int pos = SS.del(cur);
			if(!pos) break;
			S[op][i].eb(pos);
			cur -= c;
		}
	}
}

void eval(int V,int op,int *idx,int *res){
	fill(idx,idx + V + 1,n + 1);
	fill(res,res + V + 1,0);
	pst.init();nxt.init();
	int pos = m;
	rep(i,1,n){
		for(int p:S[op][i]) nxt.rmv(p);
		while(nxt.eval() > V){
			idx[pos] = i;
			res[pos] = V - pst.eval();
			pos--;nxt.dec();pst.dec();
		}
		for(int p:S[op][i]) pst.rmv(p);
	}
}

int idx[2][500005],res[2][500005];
int check(int V){
	eval(V,0,idx[0],res[0]);
	reverse(a + 1,a + n + 1);
	eval(V,1,idx[1],res[1]);
	rep(i,0,V) idx[1][i] = n + 1 - idx[1][i];
	reverse(a + 1,a + n + 1);

	rep(i,0,V){
		if(idx[0][i] > idx[1][V - i]) return 1;
		assert(idx[0][i] >= 1 && idx[0][i] <= n + 1);
		assert(idx[1][i] >= 0 && idx[1][i] <= n);
		if(idx[0][i] == idx[1][V - i] && 1ll * c * (res[0][i] + res[1][V - i]) + V >= a[idx[0][i]]) return 1;
	}
	return 0;
}

void solve(){
	scanf("%d%d%d",&n,&m,&c);
	rep(i,1,n){
		scanf("%d",&a[i]);
		S[0][i].clear();S[1][i].clear();
	}
	prepare(0);
	reverse(a + 1,a + n + 1);
	prepare(1);
	reverse(a + 1,a + n + 1);

	int answer = m;
	per(k,20,0) if(answer >= (1 << k) && check(answer - (1 << k))) answer -= 1 << k;
	printf("%d\n",answer);
//	check(2);
}

int main(){
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	scanf("%d%d",&T,&testid);
	while(T--) solve();
	return 0;
}

详细

Subtask #1:

score: 2
Accepted

Test #1:

score: 2
Accepted
time: 0ms
memory: 18220kb

input:

1000 1
9 8 0
8 5 2 1 6 4 5 1 5
9 8 0
1 7 3 2 0 8 5 1 0
8 9 0
3 8 7 3 2 4 9 9
8 9 0
8 3 9 3 9 8 3 4
9 10 0
0 9 5 5 4 3 6 10 5
8 8 0
3 5 1 6 8 4 2 5
8 9 0
5 2 3 8 1 4 2 9
10 8 0
2 8 2 3 1 7 0 1 5 1
8 9 0
1 0 4 9 9 5 7 2
9 10 0
3 4 0 10 0 9 6 7 0
8 9 0
4 8 4 4 0 4 2 3
9 8 0
0 5 2 3 1 0 4 0 0
10 10 0
3 ...

output:

8
8
9
9
10
8
9
8
9
10
8
5
10
9
8
8
7
10
8
10
8
10
9
8
10
6
10
8
8
6
7
8
9
7
9
8
8
8
5
8
9
10
5
8
10
8
10
7
9
9
9
8
8
7
9
9
8
9
8
8
7
8
8
7
10
9
10
9
9
8
8
9
7
8
9
7
7
9
6
10
8
7
8
8
9
9
9
9
9
8
8
5
7
8
8
9
6
8
8
9
8
9
8
9
9
10
8
9
8
8
7
8
7
8
7
7
7
10
9
10
9
9
8
9
8
10
10
8
7
10
8
10
8
8
8
7
10
10
8...

result:

ok 1000 lines

Test #2:

score: 2
Accepted
time: 503ms
memory: 25348kb

input:

2 1
499998 499999 0
301138 174092 254294 217002 447568 498904 49075 373725 308244 252462 370947 392908 319430 488362 86682 68848 435192 169516 29640 369208 128139 213960 159766 44498 322235 240582 283451 176399 270410 120552 173820 121114 197080 354767 283489 398040 13031 432699 251631 352577 264788...

output:

499999
499997

result:

ok 2 lines

Subtask #2:

score: 3
Accepted

Test #3:

score: 3
Accepted
time: 3ms
memory: 18296kb

input:

1000 2
10 2 3
1 2 1 2 1 2 2 1 0 1
10 2 0
0 0 0 0 0 0 0 0 0 0
10 2 3
0 0 1 1 0 1 0 0 0 1
10 2 3
0 0 0 0 0 0 0 0 0 0
10 2 1
1 0 2 2 0 0 1 0 1 1
10 2 3
0 1 1 0 2 0 1 2 2 2
10 2 0
0 0 0 0 0 0 0 0 0 0
10 2 0
0 0 0 1 1 1 0 0 0 1
10 2 1
1 1 0 2 0 0 0 0 0 0
10 2 1
1 1 2 0 0 2 0 2 1 0
10 2 1
0 0 0 0 0 0 0 0 ...

output:

2
0
1
0
2
2
0
1
1
2
0
1
0
1
0
0
2
2
0
0
2
0
1
2
1
1
2
0
2
1
0
0
2
1
0
1
2
1
0
1
2
2
2
0
1
2
1
2
2
2
1
2
2
2
1
0
1
2
2
1
0
1
0
1
0
2
2
2
2
2
0
1
2
2
2
2
1
2
2
1
2
0
0
1
2
2
1
2
2
1
0
2
2
2
1
0
0
0
1
2
0
2
2
0
0
2
2
0
2
2
0
1
1
2
0
0
1
2
1
2
1
2
2
2
1
1
2
0
0
2
2
0
2
2
2
0
2
1
1
0
2
2
2
2
0
0
1
0
0
1
...

result:

ok 1000 lines

Test #4:

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

input:

100 2
1000 2 2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

0
1
1
2
1
0
1
1
2
0
0
0
0
0
0
1
0
2
2
2
1
2
1
1
1
2
2
2
0
2
1
1
2
0
0
1
2
0
0
0
0
2
2
2
1
1
2
2
0
0
2
1
2
1
2
2
0
2
0
0
0
2
2
0
2
0
0
2
1
2
1
2
0
1
0
2
1
1
2
2
2
2
2
2
0
2
2
1
2
2
0
1
2
1
1
0
0
0
0
2

result:

ok 100 lines

Test #5:

score: 3
Accepted
time: 53ms
memory: 15892kb

input:

2 2
500000 2 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

1
2

result:

ok 2 lines

Subtask #3:

score: 5
Accepted

Test #6:

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

input:

10 3
5 5 3
4 1 5 1 4
4 5 4
2 2 3 4
5 5 0
1 1 5 3 4
4 4 2
2 1 0 1
3 5 3
0 2 3
5 4 2
3 2 4 1 4
3 4 4
3 2 2
3 4 5
4 0 2
3 5 3
1 0 5
5 4 0
2 0 4 1 3

output:

3
2
5
1
2
3
2
2
2
4

result:

ok 10 lines

Test #7:

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

input:

10 3
5 5 4
2 2 1 0 0
5 5 5
5 3 1 0 1
5 5 5
0 3 2 0 0
5 5 1
1 5 2 5 2
5 5 3
4 5 0 1 5
5 5 5
2 3 3 4 3
5 5 4
5 4 5 2 5
5 5 1
3 0 2 2 3
5 5 5
1 3 1 1 4
5 5 3
1 3 4 5 1

output:

2
2
2
4
3
3
4
2
2
3

result:

ok 10 lines

Test #8:

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

input:

10 3
5 5 4
1 5 2 2 1
5 5 5
0 1 1 1 4
5 5 2
1 1 2 3 4
5 5 3
1 3 5 4 2
5 5 5
1 1 5 4 3
5 5 5
0 3 4 4 5
5 5 1
0 0 1 2 5
5 5 3
0 0 1 2 4
5 5 3
3 5 3 3 3
5 5 4
2 5 5 4 3

output:

2
1
3
3
3
3
3
2
3
4

result:

ok 10 lines

Test #9:

score: 5
Accepted
time: 5ms
memory: 16184kb

input:

10 3
5 5 5
5 3 2 1 1
5 5 4
3 3 1 2 2
5 5 4
5 5 4 0 1
5 5 4
5 4 4 0 0
5 5 4
5 3 3 1 0
5 5 1
4 2 2 3 4
5 5 2
4 3 3 2 1
5 5 3
5 2 2 1 1
5 5 3
5 4 3 3 0
5 5 4
5 1 1 2 4

output:

2
2
3
3
3
3
3
2
3
2

result:

ok 10 lines

Test #10:

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

input:

10 3
5 5 2
4 2 4 4 5
5 5 1
2 0 2 3 4
5 5 2
2 5 4 1 1
5 5 3
1 5 5 5 5
5 5 5
5 1 1 5 3
5 5 5
3 3 5 1 5
5 5 1
3 4 1 3 2
5 5 5
5 5 5 2 2
5 5 4
5 5 1 1 5
5 5 5
5 5 2 2 5

output:

4
3
3
4
3
3
3
3
3
3

result:

ok 10 lines

Test #11:

score: 5
Accepted
time: 2ms
memory: 18292kb

input:

10 3
5 5 1
5 5 3 5 1
5 5 3
0 0 4 1 1
5 5 5
5 1 1 1 1
5 5 4
5 1 1 5 0
5 5 1
0 2 1 5 5
5 5 5
1 1 5 1 1
5 5 3
2 5 0 0 0
5 5 1
3 3 5 0 0
5 5 3
2 2 5 4 0
5 5 5
0 5 1 1 1

output:

4
1
1
2
4
2
2
3
2
1

result:

ok 10 lines

Test #12:

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

input:

10 3
5 5 2
5 5 4 5 4
5 5 1
5 5 5 5 4
5 5 3
4 4 4 5 5
5 5 5
4 4 5 5 4
5 5 5
5 4 5 4 4
5 5 1
5 4 4 5 4
5 5 4
4 4 5 5 5
5 5 3
4 5 5 5 4
5 5 2
5 5 5 4 5
5 5 4
4 4 4 5 5

output:

4
5
4
4
4
4
4
4
5
4

result:

ok 10 lines

Subtask #4:

score: 10
Accepted

Dependency #3:

100%
Accepted

Test #13:

score: 10
Accepted
time: 3ms
memory: 18296kb

input:

20 4
9 10 9
10 4 9 10 0 4 9 10 8
9 9 1
8 7 3 6 1 8 6 3 9
10 8 4
3 3 4 4 8 4 7 0 0 0
9 8 9
5 1 3 6 6 2 2 6 3
8 8 5
6 0 4 1 4 0 4 4
8 10 8
5 7 6 5 6 1 8 7
10 10 1
5 4 5 4 0 4 10 9 7 8
8 9 9
2 3 0 5 2 1 5 1
8 10 5
10 8 9 9 2 10 1 10
9 10 3
3 4 3 6 7 3 5 1 5
8 8 10
1 0 2 0 0 0 7 5
9 8 9
2 4 8 6 4 4 5 1 ...

output:

6
7
4
5
4
6
8
3
7
5
2
5
5
6
4
5
5
6
4
5

result:

ok 20 lines

Test #14:

score: 10
Accepted
time: 0ms
memory: 16168kb

input:

4 4
50 50 2
27 29 4 40 18 13 32 22 48 50 46 38 9 45 3 22 41 35 24 33 23 15 11 1 39 2 33 44 20 22 35 17 26 31 35 49 21 22 13 46 30 3 44 21 40 1 28 3 50 5
50 50 1
6 15 26 15 20 9 43 13 17 17 44 19 10 44 48 15 20 32 22 6 38 5 33 37 26 23 50 17 19 15 18 35 39 32 12 36 50 0 1 39 23 46 43 12 8 0 48 28 46 ...

output:

45
48
45
46

result:

ok 4 lines

Test #15:

score: 10
Accepted
time: 0ms
memory: 16252kb

input:

4 4
50 50 27
0 2 2 3 3 5 6 6 6 6 6 7 7 7 10 12 13 14 16 19 21 21 22 23 24 25 26 49 49 49 49 48 48 45 42 41 40 39 38 37 36 36 36 35 34 34 33 33 33 32
50 50 8
1 3 4 4 5 7 7 7 8 9 10 10 11 12 12 13 14 15 15 16 18 19 20 22 23 25 25 26 27 28 29 30 30 30 32 32 34 36 36 36 37 41 41 41 42 43 43 43 45 47
50 ...

output:

26
34
41
32

result:

ok 4 lines

Test #16:

score: 10
Accepted
time: 0ms
memory: 16164kb

input:

4 4
50 50 16
49 47 45 45 42 41 40 40 39 39 0 1 1 1 2 2 4 5 6 10 12 13 14 16 16 18 18 18 19 20 24 26 26 26 27 27 30 31 32 32 33 34 34 35 35 36 36 38 38 38
50 50 10
49 48 47 44 42 42 42 41 41 40 40 38 36 34 34 33 32 31 31 29 28 28 27 27 26 26 25 25 23 21 19 18 16 16 16 15 14 14 0 2 4 4 6 6 7 7 7 8 11 ...

output:

31
34
35
31

result:

ok 4 lines

Test #17:

score: 10
Accepted
time: 5ms
memory: 18212kb

input:

4 4
50 50 18
16 34 15 50 15 34 16 16 16 16 35 17 35 16 16 16 50 36 18 18 18 36 36 18 50 35 17 50 16 34 15 15 15 15 15 34 34 15 15 15 15 15 50 34 35 35 50 32 32 14
50 50 2
6 6 8 5 5 5 5 5 5 5 5 5 5 5 5 5 8 6 6 6 6 6 6 9 7 7 7 7 7 7 11 8 6 6 6 8 7 4 4 4 4 4 4 4 4 4 4 6 3 3
50 50 6
0 0 0 0 0 0 0 0 7 1 ...

output:

29
9
1
38

result:

ok 4 lines

Test #18:

score: 10
Accepted
time: 0ms
memory: 18220kb

input:

4 4
50 50 2
6 6 6 12 8 8 8 8 8 8 8 8 8 13 8 8 8 18 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
50 50 18
5 5 5 5 5 5 5 5 5 5 50 23 23 23 23 23 23 23 23 23 23 23 23 23 23 50 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26
50 50 1
14 14 14 14 14 14 14 14 14 1...

output:

9
26
17
30

result:

ok 4 lines

Test #19:

score: 10
Accepted
time: 0ms
memory: 16172kb

input:

4 4
50 50 46
49 50 49 50 50 50 49 50 49 50 49 49 49 50 49 50 49 50 49 50 50 50 50 50 49 50 50 50 49 49 49 50 49 49 49 50 49 49 50 49 49 50 50 50 50 49 50 49 50 49
50 50 11
50 50 49 50 50 49 49 49 50 49 50 49 50 49 50 50 49 50 50 49 50 50 49 49 50 50 50 49 49 49 49 49 49 49 49 49 49 49 50 49 49 50 49...

output:

49
50
49
49

result:

ok 4 lines

Subtask #5:

score: 10
Accepted

Dependency #4:

100%
Accepted

Test #20:

score: 10
Accepted
time: 2ms
memory: 18212kb

input:

30 5
20 18 2
11 1 4 8 18 16 15 13 13 10 3 4 5 9 10 11 2 4 4 8
19 20 0
6 17 17 15 3 16 2 8 7 11 0 14 14 6 12 15 19 2 9
19 20 10
19 10 0 7 14 8 5 7 20 4 10 16 9 3 5 10 12 4 3
18 20 4
8 9 17 0 1 15 15 4 12 13 10 12 8 17 17 16 18 6
19 18 10
17 1 17 10 0 5 13 5 16 12 8 18 0 8 12 12 5 3 9
20 19 3
16 6 17 ...

output:

13
19
10
13
11
15
15
14
15
13
10
11
18
20
13
11
12
10
11
20
10
12
14
12
18
15
13
14
11
11

result:

ok 30 lines

Test #21:

score: 10
Accepted
time: 0ms
memory: 18228kb

input:

3 5
200 200 18
76 132 130 37 139 121 171 152 22 23 194 5 181 174 96 3 71 109 143 20 144 114 157 195 109 99 120 132 110 50 101 103 37 186 71 193 157 22 65 136 84 96 123 13 154 26 66 161 200 60 93 45 48 137 18 81 77 45 37 145 100 57 130 54 20 38 28 135 16 132 85 6 18 117 26 129 57 172 10 7 198 152 26 ...

output:

157
135
131

result:

ok 3 lines

Test #22:

score: 10
Accepted
time: 0ms
memory: 16076kb

input:

2 5
300 300 52
0 1 2 2 4 6 7 7 9 10 10 11 12 12 12 13 14 14 17 18 21 21 23 24 24 24 24 24 24 26 26 26 27 29 32 32 33 33 36 37 37 39 39 40 40 40 41 42 43 44 45 46 46 47 47 47 50 50 51 53 54 54 57 57 57 60 65 65 66 71 72 72 74 74 74 74 75 75 75 78 80 81 81 81 82 82 83 83 84 85 86 91 91 93 93 94 94 94 ...

output:

217
189

result:

ok 2 lines

Test #23:

score: 10
Accepted
time: 2ms
memory: 18240kb

input:

2 5
300 300 2
300 299 299 299 299 298 298 297 289 289 288 288 286 286 286 286 285 284 283 282 280 279 279 278 278 278 276 275 275 275 275 274 274 273 273 272 271 270 270 270 266 265 264 262 261 260 259 257 257 256 256 254 254 251 249 249 245 244 244 244 240 236 236 236 234 233 233 227 227 227 226 22...

output:

289
204

result:

ok 2 lines

Test #24:

score: 10
Accepted
time: 0ms
memory: 16208kb

input:

2 5
300 300 12
46 34 34 34 34 47 35 35 48 49 37 61 35 35 35 35 35 35 47 34 47 35 35 48 36 36 36 36 36 36 36 36 49 37 50 38 38 38 38 38 38 38 38 38 38 38 38 38 38 51 39 39 39 39 39 39 52 40 40 40 40 40 40 40 53 41 41 41 41 41 41 41 41 66 41 54 42 42 42 54 41 41 53 40 40 40 40 53 54 55 55 42 42 42 42 ...

output:

59
172

result:

ok 2 lines

Test #25:

score: 10
Accepted
time: 0ms
memory: 18224kb

input:

2 5
300 300 39
13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 132 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14...

output:

15
2

result:

ok 2 lines

Test #26:

score: 10
Accepted
time: 0ms
memory: 18244kb

input:

2 5
300 300 82
300 299 300 299 299 299 300 299 300 299 300 299 299 299 300 299 299 300 299 299 300 300 300 300 300 299 300 299 300 299 299 300 299 299 300 300 300 299 300 299 300 300 300 300 299 300 299 300 299 300 300 299 299 300 300 299 300 300 300 299 299 300 299 300 299 300 299 300 300 300 299 2...

output:

300
299

result:

ok 2 lines

Subtask #6:

score: 10
Accepted

Dependency #5:

100%
Accepted

Test #27:

score: 10
Accepted
time: 6ms
memory: 16068kb

input:

40 6
100 100 55
21 89 57 40 63 86 81 67 27 21 93 86 92 67 55 18 98 31 76 24 54 92 84 57 40 19 65 57 8 54 3 11 77 72 43 23 41 77 28 49 95 77 92 11 53 34 7 47 48 96 14 35 46 92 14 28 14 11 79 29 15 45 84 22 39 24 83 58 36 16 69 45 25 60 95 79 72 85 69 50 28 43 10 80 70 73 69 22 20 87 30 25 45 4 81 0 2...

output:

55
68
55
60
51
77
62
88
66
59
67
58
55
55
54
75
71
69
68
88
55
55
56
56
53
60
57
57
54
58
61
53
71
70
56
51
86
69
56
52

result:

ok 40 lines

Test #28:

score: 10
Accepted
time: 3ms
memory: 16348kb

input:

2 6
2000 2000 62
2 2 4 4 5 7 7 8 8 9 11 11 13 13 13 14 14 18 19 19 20 21 22 24 25 25 27 27 27 28 29 30 30 31 32 33 34 34 37 37 40 40 42 44 45 46 47 48 49 52 58 59 60 61 61 62 62 64 65 65 65 65 65 66 66 67 67 69 70 71 72 72 73 74 74 75 75 78 80 80 81 81 83 84 84 84 88 89 90 90 91 94 94 96 96 98 98 98...

output:

1837
1609

result:

ok 2 lines

Test #29:

score: 10
Accepted
time: 0ms
memory: 18360kb

input:

2 6
2000 2000 471
2000 1997 1997 1996 1996 1992 1992 1992 1990 1989 1988 1988 1987 1985 1984 1981 1979 1978 1977 1977 1977 1976 1976 1973 1973 1972 1972 1971 1970 1968 1968 1967 1966 1963 1962 1961 1958 1957 1956 1955 1954 1953 1953 1952 1951 1951 1949 1949 1946 1945 1944 1944 1944 1942 1941 1939 19...

output:

1390
1559

result:

ok 2 lines

Test #30:

score: 10
Accepted
time: 3ms
memory: 16392kb

input:

2 6
2000 2000 169
955 1805 1130 1301 1132 1131 1131 962 962 962 1301 1132 1302 1132 1131 961 1130 1468 959 1297 957 1296 1126 956 1126 1127 1128 959 1299 1130 1129 1469 1132 1302 1302 963 963 963 1132 1131 1130 1636 1296 958 958 958 1128 959 1297 1297 1129 1129 1298 959 1129 1130 1299 959 959 959 95...

output:

1312
890

result:

ok 2 lines

Test #31:

score: 10
Accepted
time: 0ms
memory: 18236kb

input:

2 6
2000 2000 153
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 ...

output:

12
1488

result:

ok 2 lines

Test #32:

score: 10
Accepted
time: 2ms
memory: 18424kb

input:

2 6
2000 2000 1865
1999 1999 1999 1999 1999 1999 2000 1999 2000 1999 2000 1999 1999 1999 1999 1999 1999 1999 1999 1999 1999 1999 2000 1999 2000 2000 2000 1999 2000 1999 1999 1999 1999 1999 1999 2000 2000 2000 1999 2000 1999 2000 1999 2000 1999 2000 1999 2000 2000 2000 2000 1999 2000 1999 1999 2000 2...

output:

1999
1999

result:

ok 2 lines

Subtask #7:

score: 20
Accepted

Test #33:

score: 20
Accepted
time: 26ms
memory: 16080kb

input:

5000 7
19 19 16
4 12 5 15 12 11 9 0 3 1 8 4 17 2 19 3 5 4 1
18 20 19
18 14 12 16 7 14 2 3 13 4 4 6 8 1 16 19 10 20
20 19 3
15 7 5 16 19 0 1 19 10 19 13 17 18 5 1 13 9 4 8 15
19 20 6
8 3 0 12 4 13 19 2 6 4 11 8 17 6 8 13 11 8 20
18 19 19
3 15 19 12 17 11 11 2 4 4 16 13 10 12 15 14 3 10
19 20 20
12 15...

output:

9
10
16
11
11
12
13
12
14
12
10
19
10
9
12
18
10
15
11
9
9
11
9
11
9
11
10
9
18
12
16
11
10
18
9
10
9
14
12
17
9
13
15
11
10
13
11
11
13
11
13
10
9
9
14
10
10
11
12
10
14
12
11
13
10
12
9
13
18
13
11
16
13
15
10
10
13
10
11
12
9
11
11
11
11
18
12
10
10
11
19
11
9
16
11
10
10
10
17
9
16
10
12
10
12
1...

result:

ok 5000 lines

Test #34:

score: 20
Accepted
time: 27ms
memory: 18224kb

input:

5000 7
20 20 17
8 13 3 20 11 14 0 16 9 4 6 12 10 19 17 18 6 12 10 4
20 20 13
20 20 0 8 18 19 0 6 12 12 11 12 6 9 20 13 16 20 16 18
20 20 15
6 16 1 6 2 9 15 4 14 1 14 18 14 13 1 4 19 16 5 16
20 20 14
6 16 0 9 18 16 11 16 2 9 2 9 0 15 10 5 14 18 19 12
20 20 16
11 16 20 15 20 4 18 12 20 1 20 11 13 15 1...

output:

12
12
11
11
14
10
14
13
12
11
15
11
11
12
11
11
10
13
10
12
13
13
12
12
8
14
14
11
14
11
12
18
14
10
12
12
11
12
12
11
13
11
10
12
13
10
14
9
10
10
12
17
10
13
12
15
11
11
12
10
11
11
11
10
10
17
12
13
10
14
14
8
10
12
16
12
16
9
11
14
10
11
12
14
13
11
12
10
11
18
10
12
12
9
10
9
11
15
10
11
9
14
1...

result:

ok 5000 lines

Test #35:

score: 20
Accepted
time: 47ms
memory: 20408kb

input:

2 7
50000 50000 13
14372 18626 2882 156 873 21151 14082 1047 948 5262 23982 17851 3525 45524 36586 13870 5948 12786 22417 48991 16686 3022 26756 27407 35381 1439 1732 31854 48953 2459 28941 6550 19617 8044 43294 42701 20930 33877 11580 1246 1164 30125 6870 9257 20119 28306 13881 7577 5889 4194 5365 ...

output:

49950
49953

result:

ok 2 lines

Test #36:

score: 20
Accepted
time: 41ms
memory: 20404kb

input:

2 7
50000 50000 4
1 2 2 4 5 5 5 10 11 12 12 14 16 18 18 20 20 21 22 22 22 22 23 24 24 26 26 26 27 27 27 28 29 29 31 32 32 33 33 33 34 35 37 39 42 45 46 47 48 50 50 51 52 55 55 56 57 60 63 67 68 69 69 69 69 71 71 73 77 77 78 84 85 86 86 86 87 88 89 89 90 91 91 92 92 93 94 95 96 96 97 97 98 99 100 100...

output:

49964
49950

result:

ok 2 lines

Test #37:

score: 20
Accepted
time: 48ms
memory: 20332kb

input:

2 7
50000 50000 7
50000 49993 49993 49993 49992 49991 49991 49991 49990 49990 49988 49987 49987 49986 49985 49984 49983 49981 49980 49980 49979 49978 49978 49977 49977 49974 49973 49972 49971 49970 49969 49967 49966 49966 49966 49964 49963 49963 49962 49962 49960 49960 49960 49958 49957 49957 49957 ...

output:

49943
49862

result:

ok 2 lines

Test #38:

score: 20
Accepted
time: 28ms
memory: 18920kb

input:

5 7
20000 20000 8
6344 6335 6335 6352 6344 6336 6344 6335 6335 6335 6343 6334 6334 6334 6334 6334 6334 6352 6353 6345 6337 6337 6337 6337 6337 6345 6353 6353 6336 6336 6344 6335 6344 6336 6336 6336 6345 6337 6355 6339 6339 6339 6357 6357 6339 6339 6339 6339 6339 6339 6348 6340 6349 6357 6339 6339 63...

output:

6422
5411
650
7030
2477

result:

ok 5 lines

Test #39:

score: 20
Accepted
time: 25ms
memory: 16664kb

input:

5 7
20000 20000 2
1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 1251 12...

output:

9888
2710
14936
603
7797

result:

ok 5 lines

Test #40:

score: 20
Accepted
time: 45ms
memory: 17008kb

input:

2 7
50000 50000 8
50000 49999 49999 50000 50000 49999 50000 49999 50000 50000 49999 49999 49999 50000 50000 49999 50000 49999 49999 49999 50000 49999 49999 49999 50000 49999 49999 50000 50000 49999 49999 49999 49999 49999 49999 49999 49999 50000 50000 50000 50000 50000 50000 50000 50000 50000 49999 ...

output:

50000
50000

result:

ok 2 lines

Subtask #8:

score: 15
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Test #41:

score: 15
Accepted
time: 69ms
memory: 22588kb

input:

2 8
50000 50000 6673
19554 35986 42705 21899 31473 7560 39294 35870 541 16472 47245 23432 15909 47691 24301 46822 20982 2334 36820 13274 44584 26614 17600 27283 16933 25520 10643 30510 12571 332 11818 20945 12015 34688 39814 12779 38464 4671 33555 44413 3733 13075 16886 29885 435 9753 37882 40230 26...

output:

38283
38191

result:

ok 2 lines

Test #42:

score: 15
Accepted
time: 44ms
memory: 21960kb

input:

2 8
50000 50000 5694
0 0 1 3 5 7 9 9 9 12 15 15 17 20 21 21 23 24 28 30 33 35 38 39 39 40 41 42 43 44 45 46 47 47 49 49 49 49 51 52 52 53 54 55 56 56 56 57 59 62 62 64 65 65 66 66 67 68 69 69 70 70 72 73 76 78 79 80 81 81 82 82 82 83 87 88 88 91 91 91 92 92 94 94 95 95 97 98 98 98 100 102 102 103 10...

output:

39836
41092

result:

ok 2 lines

Test #43:

score: 15
Accepted
time: 44ms
memory: 19292kb

input:

2 8
50000 50000 8333
50000 49997 49996 49995 49995 49993 49992 49991 49991 49988 49982 49981 49981 49980 49979 49978 49978 49976 49976 49975 49971 49971 49970 49967 49967 49966 49964 49963 49963 49963 49962 49960 49960 49960 49959 49959 49957 49956 49956 49956 49956 49955 49955 49953 49952 49950 499...

output:

36762
39631

result:

ok 2 lines

Test #44:

score: 15
Accepted
time: 32ms
memory: 19864kb

input:

5 8
20000 20000 68
2416 2416 2416 2416 2484 2415 2483 2414 2414 2414 2483 2415 2484 2416 2485 2417 2485 2416 2485 2555 2419 2419 2487 2418 2418 2418 2418 2418 2418 2418 2418 2418 2486 2417 2417 2485 2484 2415 2415 2484 2553 2416 2416 2416 2484 2415 2415 2415 2415 2483 2414 2414 2414 2550 2412 2412 2...

output:

2594
8074
9162
8784
1723

result:

ok 5 lines

Test #45:

score: 15
Accepted
time: 27ms
memory: 17284kb

input:

5 8
20000 20000 1821
12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 12473 124...

output:

12444
5
16336
26
3404

result:

ok 5 lines

Test #46:

score: 15
Accepted
time: 51ms
memory: 22508kb

input:

2 8
50000 50000 816
49999 50000 50000 49999 50000 49999 49999 49999 50000 49999 50000 49999 49999 49999 50000 50000 50000 50000 49999 50000 49999 49999 49999 50000 49999 49999 49999 50000 50000 49999 49999 49999 50000 50000 49999 49999 49999 49999 49999 49999 49999 50000 50000 50000 50000 49999 4999...

output:

50000
50000

result:

ok 2 lines

Subtask #9:

score: 10
Accepted

Dependency #1:

100%
Accepted

Dependency #7:

100%
Accepted

Test #47:

score: 10
Accepted
time: 232ms
memory: 18296kb

input:

100000 9
10 10 9
10 2 2 8 6 10 4 10 9 7
10 10 6
5 5 9 3 6 1 6 5 9 2
10 10 1
10 3 2 2 7 10 2 5 3 7
10 10 6
0 10 1 3 7 4 4 9 7 5
10 10 5
3 3 4 3 2 9 0 2 10 10
10 10 5
8 7 1 10 5 1 2 4 9 8
10 10 5
9 9 4 8 2 6 6 7 8 3
10 10 7
1 0 2 1 10 7 9 6 0 4
10 10 2
1 3 7 1 6 6 9 4 10 2
10 10 4
2 4 0 3 7 5 0 0 0 1
...

output:

6
6
8
5
5
5
6
5
7
3
4
7
4
3
5
6
6
5
6
7
6
5
5
7
5
6
6
5
5
5
6
6
5
7
5
5
3
6
4
7
4
6
7
6
6
4
6
6
5
4
7
8
7
4
6
3
5
6
5
7
6
6
5
7
4
5
6
6
4
8
6
6
7
6
6
4
9
6
8
5
7
7
5
4
5
5
6
5
7
6
5
6
5
8
5
8
5
9
4
5
8
5
6
8
6
4
4
6
5
6
8
6
5
7
8
6
6
5
7
6
6
6
5
5
9
6
9
7
6
6
6
6
6
5
3
9
9
7
6
5
7
5
6
4
5
5
5
6
8
5
...

result:

ok 100000 lines

Test #48:

score: 10
Accepted
time: 711ms
memory: 28924kb

input:

2 9
500000 500000 18
41261 430172 195520 156650 355283 458369 480245 42876 191405 33350 238393 62275 347902 223912 202392 269274 134544 147085 38323 295100 365049 138397 324229 310866 141549 468237 84007 334290 454951 451932 22576 481019 60870 337809 489626 30633 155666 405866 258805 250747 174503 2...

output:

499939
499953

result:

ok 2 lines

Test #49:

score: 10
Accepted
time: 635ms
memory: 56052kb

input:

2 9
500000 500000 4
0 0 3 3 3 3 3 6 6 7 7 7 8 9 9 11 11 12 15 16 16 17 20 22 22 23 24 25 25 25 27 28 29 30 31 31 32 33 33 37 38 40 42 43 46 47 47 47 48 52 52 54 55 56 56 56 58 58 59 62 65 65 65 66 67 67 69 69 70 70 71 72 74 75 76 76 79 80 81 81 85 86 87 87 92 92 93 93 96 96 97 97 97 98 99 99 100 102...

output:

499961
499979

result:

ok 2 lines

Test #50:

score: 10
Accepted
time: 687ms
memory: 25548kb

input:

2 9
500000 500000 12
500000 499999 499999 499999 499999 499998 499996 499994 499994 499992 499990 499990 499988 499987 499986 499986 499986 499985 499985 499984 499982 499982 499980 499979 499978 499978 499978 499978 499976 499976 499975 499974 499974 499970 499969 499969 499969 499966 499966 499964...

output:

499884
499846

result:

ok 2 lines

Test #51:

score: 10
Accepted
time: 326ms
memory: 25256kb

input:

2 9
500000 500000 1
57526 57526 57526 57526 57526 57526 57526 57526 57526 57528 57527 57528 57526 57527 57527 57523 57523 57525 57524 57525 57523 57525 57524 57524 57524 57524 57526 57525 57525 57525 57525 57525 57529 57527 57527 57528 57526 57526 57526 57526 57526 57526 57526 57526 57526 57526 5752...

output:

57600
188621

result:

ok 2 lines

Test #52:

score: 10
Accepted
time: 267ms
memory: 21008kb

input:

100 9
10000 10000 4
3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 3396 ...

output:

3905
1037
2139
4577
6625
247
7709
7998
492
8263
7321
74
4243
9010
9218
6278
1033
733
7122
170
3857
5016
2792
4599
1460
1110
10000
427
6594
256
866
8044
3303
125
5637
663
7019
1105
846
6163
1767
383
267
1558
1508
8423
7132
1319
625
641
3012
3588
2410
3577
56
4853
1723
1184
3638
1112
6176
5337
855
221...

result:

ok 100 lines

Test #53:

score: 10
Accepted
time: 404ms
memory: 23188kb

input:

2 9
500000 500000 11
32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 32002 320...

output:

35537
393027

result:

ok 2 lines

Test #54:

score: 10
Accepted
time: 695ms
memory: 23912kb

input:

2 9
500000 500000 12
500000 499999 500000 500000 499999 500000 499999 499999 500000 500000 500000 499999 499999 500000 500000 500000 499999 500000 500000 500000 499999 500000 500000 500000 499999 500000 500000 499999 500000 500000 500000 500000 499999 500000 499999 499999 500000 500000 499999 499999...

output:

500000
500000

result:

ok 2 lines

Subtask #10:

score: 15
Accepted

Dependency #2:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Test #55:

score: 15
Accepted
time: 866ms
memory: 38612kb

input:

5 10
200000 200000 34996
149807 114538 102466 91885 93913 56295 190852 159208 91575 181035 172405 12906 20377 198780 78309 56111 95848 72590 20870 8269 144477 8400 3121 92664 131089 39718 97994 157342 57689 31609 23976 138755 139592 17657 18418 159274 194790 117461 156383 168496 154809 175283 35979 ...

output:

145822
113022
121383
113011
121895

result:

ok 5 lines

Test #56:

score: 15
Accepted
time: 545ms
memory: 55376kb

input:

2 10
500000 500000 4565
0 0 0 2 4 6 7 8 9 9 11 11 12 13 13 14 14 14 15 15 17 17 18 18 18 18 21 23 24 24 25 25 26 26 26 29 30 31 32 32 37 38 38 41 44 47 49 49 50 50 52 53 54 55 56 56 56 58 59 61 62 62 65 66 66 67 68 68 70 70 72 72 74 75 75 76 78 78 78 79 80 81 82 83 83 83 84 84 86 86 87 87 87 87 88 8...

output:

481134
390120

result:

ok 2 lines

Test #57:

score: 15
Accepted
time: 543ms
memory: 53064kb

input:

2 10
500000 500000 80206
500000 499999 499999 499998 499997 499996 499996 499995 499995 499994 499993 499992 499991 499991 499991 499990 499988 499983 499983 499980 499979 499979 499978 499973 499973 499972 499972 499971 499971 499968 499967 499965 499965 499964 499962 499962 499962 499962 499961 49...

output:

370216
431552

result:

ok 2 lines

Test #58:

score: 15
Accepted
time: 302ms
memory: 43844kb

input:

2 10
500000 500000 6268
5996 5996 5996 5996 5996 5996 5996 12265 5997 5997 5997 5997 5997 5997 5997 5997 5997 5997 5997 5997 5997 12265 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996 5996...

output:

11931
98285

result:

ok 2 lines

Test #59:

score: 15
Accepted
time: 191ms
memory: 17380kb

input:

100 10
10000 10000 6211
2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2173 2...

output:

3970
970
2272
988
7077
2
64
4183
2
4739
7058
6554
5678
5679
5907
2
7815
5533
4
17
4887
6905
1
2183
3
1
4
2
5692
1
20
2587
2927
2
4510
3214
1965
3
12
5009
2
2
2
2349
7
2
2
3998
3474
2070
5163
3
27
3947
2307
2191
1
7
1
1
3674
12
532
1
1
2
1
1243
1
2351
4373
33
742
2
3174
2
1
3396
1
155
1
5596
2133
6
4...

result:

ok 100 lines

Test #60:

score: 15
Accepted
time: 410ms
memory: 39120kb

input:

2 10
500000 500000 9705
361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361001 361...

output:

361001
162724

result:

ok 2 lines

Test #61:

score: 15
Accepted
time: 611ms
memory: 70308kb

input:

2 10
500000 500000 430421
499999 499999 499999 499999 499999 499999 499999 500000 499999 500000 500000 500000 500000 500000 500000 500000 499999 500000 500000 499999 499999 499999 499999 499999 499999 499999 500000 500000 500000 500000 499999 500000 500000 499999 499999 500000 499999 499999 499999 4...

output:

499999
499999

result:

ok 2 lines