0507周赛E题题解
public
May 09, 2025
Never
21
1 #include<bits/stdc++.h> 2 using namespace std; 3 priority_queue<int,vector<int>,greater<int> > q;//优先队列。 4 int main(){ 5 ios::sync_with_stdio(NULL); 6 cin.tie(nullptr);cout.tie(nullptr); 7 int n;cin>>n; 8 for(int i=1;i<=n;++i){ 9 int r;cin>>r; 10 q.push(r); 11 } 12 int diff=0; 13 bool now=false; 14 int in=q.top(); 15 for(int i=1;i<=n;++i){ 16 if(in!=q.top()){ 17 diff+=now; 18 now=false;//一定初始化。。。 19 in=q.top(); 20 } 21 now^=1;//异或1等于取反各位。 22 q.pop(); 23 } 24 cout<<diff+now<<endl; 25 return 0; 26 }