题目
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
struct Point{
int x, y;
bool operator < (const Point &u) const{
if(x != u.x) return x < u.x;
return y < u.y;
}
Point operator + (Point u){
return Point{x + u.x, y + u.y};
}
};
Point point[maxn];//按原指令移动会经过哪些点
//vector<int> vec[maxn];
map<Point, vector<int>> mp;//mp[{x, y}]存走到(x, y)需要移动几步
Point change(char ch){
if(ch == 'U') return {0, 1};
else if(ch == 'D') return {0, -1};
else if(ch == 'L') return {-1, 0};
else return {1, 0};
}
bool search(Point goal, int x, int y, int l, int r){
l--;//l--后,reverse对point[l, r]这些点没影响,
//reverse后,point[l + 1, r - 1]这些点会变成关于point[l]和point[r]连线的中点 中心对称的点
auto it = lower_bound(mp[goal].begin(), mp[goal].end(), r);
if(it != mp[goal].end()) return 1;
it = upper_bound(mp[goal].begin(), mp[goal].end(), l);
if(mp[goal].size() && it != mp[goal].begin()) return 1;
int x1 = point[l].x, y1 = point[l].y;
int x2 = point[r].x, y2 = point[r].y;
goal = {x1 + x2 - x, y1 + y2 - y};
it = upper_bound(mp[goal].begin(), mp[goal].end(), l);
if(it == mp[goal].end()) return 0;
return (*it) < r;
}
void solve(){
int n, i, j, q;
cin >> n >> q;
// for(i = 1; i <= n; i++){
// cin >> a[i];
// }
string s;
cin >> s;
s = " " + s;
Point cur = {0, 0};
int m = 0;
point[0] = cur;
mp[cur].push_back(0);
for(i = 1; i <= n; i++){
Point d = change(s[i]);
cur = cur + d;
point[++m] = cur;
mp[{cur}].push_back(i);
}
while(q--){
int x, y, l, r;
cin >> x >> y >> l >> r;
Point goal = {x, y};
int flag = search(goal, x, y, l, r);
if(flag) cout << "YES\n";
else cout << "NO\n";
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
//cin >> T;
while(T--){
solve();
}
return 0;
}