Salty Fish
Support or Not
Three Investigators
Milk Candy
Ridiculous Netizens
Stay Real
#include <bits/stdc++.h> using namespace std; const int maxn=100010; typedef long long ll; struct node { ll val,id; node(int _val,int _id):val(_val),id(_id) {}; bool operator < (const node &b)const { return val<b.val; } }; ll h[maxn],vis[maxn*2],n,suma,sumb,flag,fa; priority_queue<node>q; int main() { int T; scanf("%d",&T); while (T--) { scanf("%lld",&n); for (int i=1; i<=n; i++) { vis[i]=1; } for (int i=1; i<=n; i++) { scanf("%lld",&h[i]); if (vis[i<<1]==0&&vis[i<<1|1]==0) { q.push(node(h[i],i)); } } suma=sumb=0; flag=1; while (!q.empty()) { node tmp=q.top(); q.pop(); if (flag) { suma+=tmp.val; } else { sumb+=tmp.val; } vis[tmp.id]=0; flag^=1; fa=tmp.id>>1; if (vis[fa<<1]==0&&vis[fa<<1|1]==0&&fa!=0) { q.push(node(h[fa],fa)); } } printf("%lld %lld\n",suma,sumb); } return 0; }TDL
Snowy Smile
Faraway
Nonsense Time
Speed Dog
11 Dimensions
原文地址:https://www.cnblogs.com/Accpted/p/11316849.html
时间: 2024-11-06 09:45:22