QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625791#9349. Exchanging GiftsGodwang#WA 231ms34368kbC++141.5kb2024-10-09 21:02:412024-10-09 21:02:43

Judging History

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

  • [2024-10-09 21:02:43]
  • 评测
  • 测评结果:WA
  • 用时:231ms
  • 内存:34368kb
  • [2024-10-09 21:02:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n, T, t;
struct Node {
	int op, x, y;
} ask[N];
vector<int> a[N];
int len[N];
long long tot[N];
bool vis[N];
priority_queue<int> q;
map<int, long long> mp;
inline int read() {
	int s = 0;
	char c = getchar();
	while (c < '0' || c > '9') {
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		s = s * 10 + c - '0';
		c = getchar();
	}
	return s;
}
int main()
{
	ios::sync_with_stdio(false);cin.tie();cout.tie();
	cin>>T;
	while (T--) {
		cin>>n;
		for (int i = 1; i <= n; i++) {
			cin>>ask[i].op;
			if (ask[i].op == 1) {
				a[i].clear();
				cin>>len[i];
				for (int j = 1; j <= len[i]; j++) {
					cin>>t;
					a[i].push_back(t);
				}
			}
			else {
				cin>>ask[i].x>>ask[i].y;
			}
		}
		q.push(n); vis[n] = 1;
		tot[n] = 1;
		while (!q.empty()) {
			int tp = q.top(); 
			q.pop();
			if (ask[tp].op == 1) continue;
			if (!vis[ask[tp].x]) q.push(ask[tp].x), vis[ask[tp].x] = 1;
			if (!vis[ask[tp].y]) q.push(ask[tp].y), vis[ask[tp].y] = 1;
			tot[ask[tp].x] += tot[tp];
			tot[ask[tp].y] += tot[tp];
		}
		for (int i = 1; i <= n; i++) {
			if (ask[i].op == 2) continue;
			for (int j = 0; j < len[i]; j++) {
				mp[a[i][j]] += tot[i];
			}
		}
		long long t=0,ans=0;
		for (map<int,long long>::iterator it=mp.begin();it!=mp.end();it++) {
			if (it->second >= n / 2)t=it->second;
			ans+=it->second;
		}
		if(!t)cout<<ans<<endl;
		else cout<<ans*2-t*2<<endl;
		mp.clear();
		for(int i=1;i<=n;i++)tot[i]=vis[i]=0;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 34368kb

input:

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

output:

4
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 231ms
memory: 34364kb

input:

10000
100
1 30 371028678 371028678 371028678 716418076 398221499 591504380 398221499 398221499 591504380 777141390 398221499 591504380 591504380 777141390 287847807 716418076 777141390 716418076 777141390 287847807 287847807 287847807 371028678 371028678 398221499 777141390 371028678 6827702 6827702...

output:

1196
68
488
338
131
1774
194
1232
804
0
580
252
35
436
1832
238
1594
398
666
974
5924
488
1856
199
780
272
0
69
1116
738
247
1640
138
2788
91
5360
4426
2376
788
964
686
520
520
5296
0
866
1994
53
0
712
1154
652
41
18
91
782
1358
1024
278
1288
1634
3008
176
187
984
2740
798
482
238
236
1390
0
978
302...

result:

wrong answer 1st lines differ - expected: '700', found: '1196'