标签:define vector 个数 第k大 class panel priority col lse
5 2 1
1 2
1 3
2
1 3
2
2
1
#include<iostream> #include<algorithm> #include<map> #include<string> #include <math.h> #include<memory.h> #include<cstring> #include<bits/stdc++.h> using namespace std; typedef long long ll; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } const int INF=0x3f3f3f3f; const int maxn=5e5+10; priority_queue<int> q1; //大根堆大到小 priority_queue<int, vector<int>, greater<int>> q2; //小根堆小到大 int n,k,p; //void insert11(int x){ // if(!q2.size()||x>q2.top()){ // q2.push(x); // } // else{ // q1.push(x); // } // if(q2.size()>=k){ // q1.push(q2.top()); // q2.pop(); // } // while(q2.size()<k&&q1.size()!=0){ // q2.push(q1.top()); // q1.pop(); // } //} void insert11(int x){ q2.push(x); if(q2.size()==k){ q1.push(q2.top()); q2.pop(); } } int main(){ cin>>n>>k>>p; int z=0; int x,y; while(n--){ scanf("%d",&x); if(x==1){ scanf("%d",&y); if(p==1){ y=y^z; } insert11(y); } else if(x==2){ z=q1.top(); printf("%d\n",z); q1.pop(); } } }
#include <map> #include <queue> #include <string> #include<iostream> #include<stdio.h> #include<string.h> #include <algorithm> #include <math.h> typedef long long ll; using namespace std; const int maxn=2e5+1010; #define inf 0x3f3f3f3f #define sf scanf #define pf printf const int mod=998244353; const int MOD=10007; inline int read() { int x=0; bool t=false; char ch=getchar(); while((ch<‘0‘||ch>‘9‘)&&ch!=‘-‘)ch=getchar(); if(ch==‘-‘)t=true,ch=getchar(); while(ch<=‘9‘&&ch>=‘0‘)x=x*10+ch-48,ch=getchar(); return t?-x:x; } priority_queue<ll , vector<ll> , greater<ll> > mn;//上 小根堆 小到大 priority_queue<ll , vector<ll> , less<ll> > mx;//下 大根堆 大到小 //map<ll,ll>mp; ll n,m,t,l,r,p; ll sum,ans,res,cnt,flag; int main() { sf("%lld%lld%lld",&n,&m,&p); if(p==0) { while(n--) { ll opt,x; sf("%lld",&opt); if(opt==1){ sf("%lld",&x); mn.push(x); if(mn.size()==m){ mx.push(mn.top()); mn.pop(); } }else { printf("%lld\n",mx.top()); mx.pop(); } } } else { ll y=0; while(n--) { ll opt,x; sf("%lld",&opt); if(opt==1){ sf("%lld",&x); x=x^y; // cout<<" "<<x<<endl; mn.push(x); if(mn.size()==m){ mx.push(mn.top()); mn.pop(); } }else { y=mx.top(); printf("%lld\n",mx.top()); //cout<<mx.top()<<endl; mx.pop(); } } } return 0; }
标签:define vector 个数 第k大 class panel priority col lse
原文地址:https://www.cnblogs.com/lipu123/p/12926789.html