vector,20分,求调
  • 板块P2073 送花
  • 楼主YZren
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/1/15 15:20
  • 上次更新2025/1/15 19:30:08
查看原帖
vector,20分,求调
1218495
YZren楼主2025/1/15 15:20
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
const int maxn=5e6;
int n,sum,ans,w,c,pos[maxn],vis[maxn];
vector<int> vec;
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-48;ch=getchar();}
	return x*f;
}
inline void work1(){
	w=read(); c=read();
	if(vis[c]) return ;
	vec.insert(lower_bound(vec.begin(),vec.end(),c),c);
	pos[c]=w; vis[c]=1; n++;
}
inline void work2(){
	if(n==0) return;
	vis[n-1]=0;
	vec.erase(vec.begin()+n-1);
	n--;
}
inline void work3(){
	if(n==0) return;
	vis[vec[0]]=0;
	vec.erase(vec.begin());
	n--;
}
inline void work(){
	while(1){
		int opt=read();
		if(opt==-1) break;
		else if(opt==1) work1();
		else if(opt==2) work2();
		else work3();
	}
	for(int i=0;i<n;i++){
		sum+=pos[vec[i]];
		ans+=vec[i];
	}
	cout<<sum<<" "<<ans<<endl;
}
signed main(){work();return 0;}
2025/1/15 15:20
加载中...