Submission #48926324


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll MOD=998244353;
// head 
const int N=2e5+5; 
vector<pair<int,int>> V;
int a[N],b[N],a1[N],b1[N];
bool cmp(pair<int,int> p,pair<int,int> q)
{
	if(p.second!=q.second) return p.second<q.second;
	return p.first<q.first;
}
signed main() 
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	int h,w;cin>>h>>w;
	int x,y;cin>>x>>y;
	int n;cin>>n;
	for(int i=0;i<n;i++){
		int X,Y;cin>>X>>Y;
		V.pb({X,Y});
	}	
	sort(all(V));
	for(int i=0;i<n;i++){
		a[i]=V[i].first;
		b[i]=V[i].second;
	}
	sort(all(V),cmp);
	for(int i=0;i<n;i++){
		a1[i]=V[i].first;
		b1[i]=V[i].second;
	}
	int q;cin>>q;
	while(q--)
	{
		char s;cin>>s;
		int step;cin>>step;
		if(s=='L'){
			int st=lower_bound(a,a+n,x)-a;
			int en=upper_bound(a,a+n,x)-a;
			int dir=lower_bound(b+st,b+en,y)-b-1;
			if(dir==st-1) y=max(1ll,y-step);
			else y=max(y-step,b[dir]+1);
		}
		else if(s=='R'){
			int st=lower_bound(a,a+n,x)-a;
			int en=upper_bound(a,a+n,x)-a;
			int dir=upper_bound(b+st,b+en,y)-b;
			if(dir==en) y=min(w,y+step);
			else y=min(y+step,b[dir]-1);
		}
		else if(s=='U'){
			int st=lower_bound(b1,b1+n,y)-b1;
			int en=upper_bound(b1,b1+n,y)-b1;
			int dir=lower_bound(a1+st,a1+en,x)-a1-1;
			if(dir==st-1) x=max(1ll,x-step);
			else x=max(x-step,a1[dir]+1);
		}
		else {
			int st=lower_bound(b1,b1+n,y)-b1;
			int en=upper_bound(b1,b1+n,y)-b1;
			int dir=upper_bound(a1+st,a1+en,x)-a1;
			if(dir==en) x=min(h,x+step);
			else x=min(x+step,a1[dir]-1);
		}
		cout<<x<<" "<<y<<endl;
	}
}

Submission Info

Submission Time
Task D - LRUD Instructions
User gangbengr
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1838 Byte
Status AC
Exec Time 309 ms
Memory 14012 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 29
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 215 ms 3516 KiB
001.txt AC 222 ms 3712 KiB
002.txt AC 220 ms 3424 KiB
003.txt AC 277 ms 14012 KiB
004.txt AC 276 ms 13328 KiB
005.txt AC 277 ms 13972 KiB
006.txt AC 277 ms 13292 KiB
007.txt AC 219 ms 4404 KiB
008.txt AC 286 ms 13996 KiB
009.txt AC 59 ms 5560 KiB
010.txt AC 154 ms 7756 KiB
011.txt AC 140 ms 9800 KiB
012.txt AC 245 ms 10988 KiB
013.txt AC 308 ms 13212 KiB
014.txt AC 309 ms 13244 KiB
015.txt AC 307 ms 13272 KiB
016.txt AC 308 ms 13228 KiB
017.txt AC 272 ms 12472 KiB
018.txt AC 279 ms 12436 KiB
019.txt AC 283 ms 12476 KiB
020.txt AC 287 ms 12584 KiB
021.txt AC 290 ms 12576 KiB
022.txt AC 292 ms 12580 KiB
023.txt AC 293 ms 12436 KiB
024.txt AC 295 ms 12516 KiB
025.txt AC 295 ms 12676 KiB
026.txt AC 296 ms 12672 KiB
example0.txt AC 1 ms 3516 KiB
example1.txt AC 1 ms 3520 KiB