QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#530036 | #9221. Missing Boundaries | ucup-team635# | RE | 0ms | 2072kb | Rust | 4.1kb | 2024-08-24 14:42:27 | 2024-08-24 14:42:27 |
Judging History
answer
// ---------- begin scannner ----------
#[allow(dead_code)]
mod scanner {
use std::str::FromStr;
pub struct Scanner<'a> {
it: std::str::SplitWhitespace<'a>,
}
impl<'a> Scanner<'a> {
pub fn new(s: &'a String) -> Scanner<'a> {
Scanner {
it: s.split_whitespace(),
}
}
pub fn next<T: FromStr>(&mut self) -> T {
self.it.next().unwrap().parse::<T>().ok().unwrap()
}
pub fn next_bytes(&mut self) -> Vec<u8> {
self.it.next().unwrap().bytes().collect()
}
pub fn next_chars(&mut self) -> Vec<char> {
self.it.next().unwrap().chars().collect()
}
pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
(0..len).map(|_| self.next()).collect()
}
}
}
// ---------- end scannner ----------
use std::collections::*;
use std::io::Write;
type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;
fn main() {
use std::io::Read;
let mut s = String::new();
std::io::stdin().read_to_string(&mut s).unwrap();
let mut sc = scanner::Scanner::new(&s);
let out = std::io::stdout();
let mut out = std::io::BufWriter::new(out.lock());
run(&mut sc, &mut out);
}
fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) {
let t: u32 = sc.next();
for _ in 0..t {
let n: usize = sc.next();
let l: i64 = sc.next();
let mut p = vec![(0i64, 0i64); n];
for p in p.iter_mut() {
p.0 = sc.next();
p.1 = sc.next();
}
let ans = if solve(p, l) { "TAK" } else { "NIE" };
writeln!(out, "{}", ans).ok();
}
}
fn solve(mut p: Vec<(i64, i64)>, l: i64) -> bool {
let n = p.len();
p.retain(|p| *p != (-1, -1));
let free = (n - p.len()) as i64;
if p.is_empty() {
return free <= l;
}
let mut map = Map::<i64, i64>::new();
for &(l, r) in p.iter() {
if l != -1 && r != -1 {
if let Some((k, v)) = map.range(..=l).next_back() {
if l <= *v {
return false;
}
}
if let Some((k, v)) = map.range(l..).next() {
if *k <= r {
return false;
}
}
map.insert(l, r);
}
}
for &(l, r) in p.iter() {
if l != -1 && r != -1 {
continue;
}
if l != -1 {
if let Some((k, v)) = map.range(..=l).next_back() {
if l <= *v {
return false;
}
}
}
if r != -1 {
if let Some((k, v)) = map.range(..=r).next_back() {
if r <= *v {
return false;
}
}
}
}
let mut z = vec![];
for (i, &(l, r)) in p.iter().enumerate() {
if l != -1 && r != -1 {
z.push((l, true, i));
z.push((r, false, i));
} else if l != -1 {
z.push((l, true, i));
} else {
z.push((r, false, i));
}
}
z.sort();
let mut range = (0, 0);
for z in z.windows(2) {
let l = z[0];
let r = z[1];
if l.2 == r.2 {
assert!(l.1 && !r.1);
continue;
}
let d = r.0 - l.0 - 1;
if !l.1 && r.1 {
if d > 0 {
range.0 += 1;
range.1 += d;
}
} else {
range.1 += d;
}
}
let f = z[0];
if f.0 == 1 {
} else {
let d = f.0 - 1;
if f.1 {
range.0 += 1;
range.1 += d;
} else {
range.1 += d;
}
}
let t = z[z.len() - 1];
if t.0 == l {
} else {
let d = l - t.0;
if !t.1 {
range.0 += 1;
range.1 += d;
} else {
range.1 += d;
}
}
range.0 <= free && free <= range.1
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 2072kb
input:
3 4 51 1 -1 11 50 -1 -1 -1 10 3 2 -1 -1 -1 -1 -1 -1 2 3 1 2 2 3
output:
TAK NIE NIE
result:
ok 3 lines
Test #2:
score: -100
Runtime Error
input:
1 200000 1000000000 490669427 -1 224278942 224287156 821104480 -1 861696576 861702036 807438935 807440055 574078002 574083717 465630141 -1 195378188 -1 -1 13500961 -1 977536179 92893115 -1 -1 661145418 -1 215804863 -1 685338515 544348999 -1 465532902 -1 130346949 -1 -1 526666304 635604584 635605404 ...