洛谷 2073 送花
1 #include<bits/stdc++.h> 2 #define DB double 3 #define ll long long 4 using namespace std; 5 struct node1{ 6 int w,c; 7 bool operator < (const node1 &x) const{ 8 return c>x.c; 9 } 10 };//小根堆 11 struct node2{ 12 int w,c; 13 bool operator < (const node2 &x) const{ 14 return c<x.c; 15 } 16 };//大根堆 17 priority_queue<node2>q2; 18 priority_queue<node1>q1; 19 int op,W,C; 20 bool v[10000000]; 21 ll ans1,ans2; 22 int main() 23 { 24 while(scanf("%d",&op)!=EOF) 25 { 26 if(op==-1) break; 27 if(op==1) 28 { 29 scanf("%d%d",&W,&C); 30 if(v[C]==0) 31 { 32 q1.push((node1){W,C}); 33 q2.push((node2){W,C}); 34 v[C]=1; 35 } 36 } 37 if(op==2) 38 { 39 while(!q2.empty()) 40 { 41 node2 ff=q2.top(); 42 if(v[ff.c]==0) q2.pop(); 43 else{ 44 q2.pop(); 45 v[ff.c]=0; 46 break; 47 } 48 } 49 } 50 if(op==3) 51 { 52 while(!q1.empty()) 53 { 54 node1 ff=q1.top(); 55 if(v[ff.c]==0) q1.pop(); 56 else{ 57 q1.pop(); 58 v[ff.c]=0; 59 break; 60 } 61 } 62 } 63 } 64 while(!q1.empty()) 65 { 66 node1 ff=q1.top(); 67 if(v[ff.c]==0) q1.pop(); 68 else{ 69 q1.pop(); 70 v[ff.c]=0; 71 ans1+=ff.w;ans2+=ff.c; 72 } 73 } 74 /* while(!q2.empty()) 75 { 76 node2 ff=q2.top(); 77 if(v[ff.c]==0) q2.pop(); 78 else{ 79 q2.pop(); 80 v[ff.c]=0; 81 ans1+=ff.w;ans2+=ff.c; 82 } 83 }*/ 84 printf("%lld %lld",ans1,ans2); 85 return 0; 86 }
=======