abc D求调
  • 板块学术版
  • 楼主HZHDCM
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/12/21 21:46
  • 上次更新2024/12/22 09:59:31
查看原帖
abc D求调
817681
HZHDCM楼主2024/12/21 21:46
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5;
map <int, set <int>> s1, s2;
int n,m,nowx,nowy,sx,sy,ans;
signed main(){
	cin>>n>>m>>sx>>sy;
	nowx=sy;nowy=sx;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		if(x==sx&&y==sy)
			ans++;
		else{
			s1[y].insert(x);
			s2[x].insert(y);
		}
	}

	while(m--){
		char opt;int pos;
		cin>>opt>>pos;
		if(opt == 'L'){
			int ky=nowy-pos;
			auto i=s1[nowx].lower_bound(nowy);
			vector<int> v;
			while(i!=s1[nowx].begin()&&ky<=(*i))v.push_back(*(--i));
			ans+=v.size();
//			cout<<ans<<endl;
			for(auto j:v)s1[nowx].erase(j),s2[j].erase(nowx);
			nowy-=pos;
		}
		if(opt == 'R'){
			int ky=nowy+pos;
			auto i=s1[nowx].lower_bound(nowy);
			vector<int> v;
			while(i!=s1[nowx].end()&&ky>=(*i))v.push_back(*i),i++;
			ans+=v.size();
//			cout<<ans<<endl;
			for(auto j:v)s1[nowx].erase(j),s2[j].erase(nowx);
			nowy+=pos;
		}
		if(opt == 'D'){
			int kx=nowx-pos;
			auto i=s2[nowy].lower_bound(nowx);
			vector<int> v;
			while(i!=s2[nowy].begin()&&kx<=(*i))v.push_back(*(--i));
			ans+=v.size();
//			cout<<ans<<endl;
			for(auto j:v)s2[nowy].erase(j),s1[j].erase(nowy);
			nowx-=pos;
		}
		if(opt == 'U'){
			int kx=nowx+pos;
			auto i=s2[nowy].lower_bound(nowx);
			vector<int> v;
			while(i!=s2[nowy].end()&&(*i)<=kx)v.push_back(*i),i++;
			ans+=v.size();
//			cout<<ans<<endl;
			for(auto j:v)s2[nowy].erase(j),s1[j].erase(nowy);
			nowx+=pos;
		}
	}
	cout<<nowy<<" "<<nowx<<" "<<ans<<endl;
	return 0;
}
2024/12/21 21:46
加载中...