use std::collections::{HashMap, HashSet}; fn main() { let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let mut iter = input.split_whitespace(); let n: usize = iter.next().unwrap().parse().unwrap(); let q: usize = iter.next().unwrap().parse().unwrap(); let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); let mut s_chars = s.trim().chars().collect::<Vec<char>>(); s_chars.insert(0, ' '); let mut pref: Vec<(i32, i32)> = vec![(0, 0); n + 1]; let mut c: HashMap<(i32, i32), usize> = HashMap::new(); let mut d: HashMap<(i32, i32), usize> = HashMap::new(); for i in 1..=n { pref[i] = pref[i - 1]; match s_chars[i] { 'R' => pref[i].0 += 1, 'L' => pref[i].0 -= 1, 'D' => pref[i].1 -= 1, 'U' => pref[i].1 += 1, _ => (), } if d.get(&pref[i]).is_none() { d.insert(pref[i], i); } c.insert(pref[i], i); } d.insert(pref[0], usize::max_value()); s_chars.reverse(); let mut rpr: Vec<(i32, i32)> = vec![(0, 0); n + 1]; let mut e: HashMap<(i32, i32), HashSet<usize>> = HashMap::new(); e.entry((0, 0)).or_insert_with(HashSet::new); for i in 1..=n { rpr[i] = rpr[i - 1]; match s_chars[i] { 'R' => rpr[i].0 += 1, 'L' => rpr[i].0 -= 1, 'D' => rpr[i].1 -= 1, 'U' => rpr[i].1 += 1, _ => (), } e.entry(rpr[i]).or_insert_with(HashSet::new).insert(i); } for _ in 0..q { let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let mut iter = input.split_whitespace(); let x: i32 = iter.next().unwrap().parse().unwrap(); let y: i32 = iter.next().unwrap().parse().unwrap(); let l: usize = iter.next().unwrap().parse().unwrap(); let r: usize = iter.next().unwrap().parse().unwrap(); let mut ans = d[&(x, y)] < l && d[&(x, y)] != 0 || c[&(x, y)] > r; let offset_r = rpr[n - r].0; let offset_c = rpr[n - r].1; let pref_offset = pref[l - 1]; let mut x = x + offset_r - pref_offset.0; let mut y = y + offset_c - pref_offset.1; if let Some(set) = e.get(&(x, y)) { if let Some(last_elem) = set.iter().max() { if *last_elem >= n - r + 1 { if let Some(lower_bound) = set.range(n - r + 1..).next() { if *lower_bound <= n - l + 1 { ans = true; } } } } } println!("{}", if ans { "YES" } else { "NO" }); } }
Write, Run & Share Rust code online using OneCompiler’s Rust online compiler for free. It’s a fast, interactive, and powerful environment to learn and experiment with the Rust programming language. OneCompiler runs the latest stable version of Rust.
Rust is a systems programming language developed by Mozilla that focuses on performance, memory safety, and concurrency. It guarantees memory safety without a garbage collector and is widely used for system-level programming, web assembly, and command-line tools. Rust's compiler enforces strict compile-time checks, making code safer and more predictable.
The following is a simple Rust program that prints a greeting:
fn main() {
println!("Hello, OneCompiler!");
}
OneCompiler’s Rust editor supports stdin. Here’s a sample program that reads a line of input and prints it:
use std::io;
fn main() {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
println!("Hello, {}", input.trim());
}
let name = "OneCompiler"; // Immutable
let mut age = 25; // Mutable
Type | Description |
---|---|
i32, i64 | Signed integers |
f32, f64 | Floating-point numbers |
bool | true or false |
char | Single character |
String | Growable string |
let score = 85;
if score >= 50 {
println!("Pass");
} else {
println!("Fail");
}
for i in 1..=5 {
println!("{}", i);
}
let mut i = 1;
while i <= 5 {
println!("{}", i);
i += 1;
}
let mut count = 0;
loop {
if count == 3 {
break;
}
println!("{}", count);
count += 1;
}
fn add(a: i32, b: i32) -> i32 {
a + b
}
fn greet(name: &str) {
println!("Hello, {}!", name);
}
This guide provides a quick reference to Rust programming syntax and features. Start coding in Rust using OneCompiler’s Rust online compiler today!