QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#262527#7678. The GamejeanWA 22ms24124kbC++143.4kb2023-11-23 20:11:062023-11-23 20:11:07

Judging History

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

  • [2023-11-23 20:11:07]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:24124kb
  • [2023-11-23 20:11:06]
  • 提交

answer

#include"bits/stdc++.h"

#define mid (l + ((r - l) >> 1))

using namespace std;

const long long N = 1e6 + 10;

long long sum[N << 3], ls[N << 3], rs[N << 3], root, cnt, a[N << 3];

void push_up(long long i) {
	sum[i] = sum[ls[i]] + sum[rs[i]];
	a[i] = a[ls[i]] + a[rs[i]];
}

void add(long long &i, long long l, long long r, long long pos, long long vol) {
	if(!i) i = ++cnt;
	if(l == r) {
		sum[i] += l * vol;
		a[i] += vol;
		return ;
	}
	else if(pos <= mid) add(ls[i], l, mid, pos, vol);
	else add(rs[i], mid + 1, r, pos, vol);
	push_up(i);
}

long long query1(long long i, long long l, long long r, long long vol) {
	//cout << l << " " << r << " " << mid << " " << a[i] << " " << vol << "\n";
	//cout << a[ls[i]] << " " << a[rs[i]] << "\n";
	//cout << sum[ls[i]] << " " << sum[rs[i]] << "\n";
	if(l == r) return vol * l;
	else if(vol <= a[rs[i]]) return query1(rs[i], mid + 1, r, vol);
	else return query1(ls[i], l, mid, vol - a[rs[i]]) + sum[rs[i]];
}

long long query2(long long i, long long l, long long r) {
	if(l == r) return l;
	else if(a[ls[i]]) return query2(ls[i], l, mid);
	else return query2(rs[i], mid + 1, r);
}

long long query3(long long i, long long l, long long r, long long k) {
	// cout << l << " " << r << " " << mid << " " << a[i] << " " << k << "\n";
	// cout << a[ls[i]] << " " << a[rs[i]] << "\n";
	// cout << sum[ls[i]] << " " << sum[rs[i]] << "\n";
	if(l == r) return l;
	else if(k <= a[ls[i]]) return query3(ls[i], l, mid, k);
	else return query3(rs[i], mid + 1, r, k - a[ls[i]]);
}

long long b[N];

void solve() {
	root = 0;
	long long n, m;
	cin >> n >> m;
	vector<long long> ans;
	for(long long i = 1; i <= n; i++) {
		long long x;
		cin >> x;
		add(root, 1, 1e9 + 10, x, 1);
	}
	long long sum = 0;
	int f = 1;
	for(long long i = 1; i <= m; i++) {
		cin >> b[i];
		sum += b[i];
		if(query3(root, 1, 1e9 + 10, n - m + i) > b[i]) {
			f = 0;
		}
	}
	if(!f) {
		cout << -1 << "\n";
		return ;
	}
	if(sum - query1(root, 1, 1e9 + 10, m) > a[root] - m) {
		cout << "-1" << "\n";
		return ;
	}
	long long kk = 0;
	sort(b + 1, b + 1 + m);
	while(kk < n - m && sum - query1(root, 1, 1e9 + 10, m) != a[root] - m) {
		long long now = query2(root, 1, 1e9 + 10);
		ans.push_back(now);
		add(root, 1, 1e9 + 10, now, -1);
		add(root, 1, 1e9 + 10, now + 1, 1);
		add(root, 1, 1e9 + 10, query2(root, 1, 1e9 + 10), -1);
		kk++;
	}
	//cout << kk << "\n";
	for(long long i = m; i >= 1 && kk < n - m; i--) {
		//cout << "$$$$$" << a[root] - m + i << "\n";
 		long long ai = query3(root, 1, 1e9 + 10, a[root] - m + i);
		//cout << i << " " << ai << " " << b[i] << "\n";
		if(ai > b[i]) {
			cout << -1 << "\n";
			return ;
		}
		while(ai < b[i]) {
			ans.push_back(ai);
			add(root, 1, 1e9 + 10, ai, -1);
			add(root, 1, 1e9 + 10, ai + 1, 1);
			//cout << "###" << query2(root, 1, 1e9 + 10) << "\n";
			add(root, 1, 1e9 + 10, query2(root, 1, 1e9 + 10), -1);
			ai++;
			kk++;
		}
	}
	for(long long i = 1; i <= m; i++) {
		//cout << query3(root, 1, 1e9 + 10, a[root] - m + i) << " " << b[i] << "\n";
		if(query3(root, 1, 1e9 + 10, a[root] - m + i) != b[i]) {
			cout << "-1" << "\n";
			return ;
		}
	}
	cout << n - m << "\n";
	for(auto i : ans) cout << i << " ";
	cout << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	long long t;
	cin >> t;
	while(t--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9964kb

input:

6
5 3
1 2 2 3 3
2 3 4
4 2
1 2 2 4
2 4
5 2
2 3 3 4 4
5 5
6 1
1 1 1 1 1 1
4
4 2
1 1 1 2
2 2
4 1
1 1 1 1
2

output:

2
1 3 
-1
3
2 4 4 
5
1 1 1 2 3 
2
1 1 
-1

result:

ok ok (6 test cases)

Test #2:

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

input:

7056
4 3
1 1 1 1
1 1 1
4 3
1 1 1 1
1 1 2
4 3
1 1 1 1
1 1 3
4 3
1 1 1 1
1 1 4
4 3
1 1 1 1
1 1 5
4 3
1 1 1 1
1 1 6
4 3
1 1 1 1
1 2 2
4 3
1 1 1 1
1 2 3
4 3
1 1 1 1
1 2 4
4 3
1 1 1 1
1 2 5
4 3
1 1 1 1
1 2 6
4 3
1 1 1 1
1 3 3
4 3
1 1 1 1
1 3 4
4 3
1 1 1 1
1 3 5
4 3
1 1 1 1
1 3 6
4 3
1 1 1 1
1 4 4
4 3
1 1...

output:

-1
1
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
2 
-1
-1
-1
1
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok ok (7056 test cases)

Test #3:

score: 0
Accepted
time: 11ms
memory: 13428kb

input:

5880
4 2
1 1 1 1
1 1
4 2
1 1 1 1
1 2
4 2
1 1 1 1
1 3
4 2
1 1 1 1
1 4
4 2
1 1 1 1
1 5
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1 4 
3
1 4 5 
3
4 5 6 
-1
-1
-1
-1
-1
3
1 1 2 
3
1 1 5 
3
1 5 6 
3
5 6 7 
-1
-1
-1
-1
-1
3
1 1 2 
3
1 1 6 
3
1 6 7 
-1
-1
-1
-1
-1
-1
3
1 1 2 
3
1 1 7 
...

result:

ok ok (2640 test cases)

Test #5:

score: 0
Accepted
time: 22ms
memory: 24124kb

input:

14112
5 3
1 1 1 1 1
1 1 1
5 3
1 1 1 1 1
1 1 2
5 3
1 1 1 1 1
1 1 3
5 3
1 1 1 1 1
1 1 4
5 3
1 1 1 1 1
1 1 5
5 3
1 1 1 1 1
1 1 6
5 3
1 1 1 1 1
1 2 2
5 3
1 1 1 1 1
1 2 3
5 3
1 1 1 1 1
1 2 4
5 3
1 1 1 1 1
1 2 5
5 3
1 1 1 1 1
1 2 6
5 3
1 1 1 1 1
1 3 3
5 3
1 1 1 1 1
1 3 4
5 3
1 1 1 1 1
1 3 5
5 3
1 1 1 1 1
...

output:

-1
-1
2
1 2 
-1
-1
-1
2
1 1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
2 3 
-1
-1
-1
2
2 1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
1 1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

ok ok (14112 test cases)

Test #6:

score: -100
Wrong Answer
time: 13ms
memory: 15692kb

input:

5292
5 2
1 1 1 1 1
1 1
5 2
1 1 1 1 1
1 2
5 2
1 1 1 1 1
1 3
5 2
1 1 1 1 1
1 4
5 2
1 1 1 1 1
1 5
5 2
1 1 1 1 1
1 6
5 2
1 1 1 1 1
2 2
5 2
1 1 1 1 1
2 3
5 2
1 1 1 1 1
2 4
5 2
1 1 1 1 1
2 5
5 2
1 1 1 1 1
2 6
5 2
1 1 1 1 1
3 3
5 2
1 1 1 1 1
3 4
5 2
1 1 1 1 1
3 5
5 2
1 1 1 1 1
3 6
5 2
1 1 1 1 1
4 4
5 2
1 1...

output:

-1
-1
-1
3
1 2 3 
-1
-1
3
1 1 1 
3
1 2 1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
3
1 1 2 3 
3
2 3 4 
-1
-1
3
1 1 2 
3
2 3 1 
-1
-1
3
2 1 2 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
3
1 1 3 4 
3
3 4 5 
-1
-1
3
1 1 3 
3
3 4 1 
-1
3
1 1 2 
3
3 1 2 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
3
1 1 4 ...

result:

wrong answer Wrong answer, the final sequence does not equal to B (test case 25)