結果

問題 No.3560 Giant Salamander
コンテスト
ユーザー かざり
提出日時 2026-06-12 23:12:23
言語 Crystal
(1.19.1)
コンパイル:
crystal build -Donline_judge -o a.out --release --no-debug _filename_
実行:
./a.out
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 6,353 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 15,924 ms
コンパイル使用メモリ 337,292 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-12 23:12:44
合計ジャッジ時間 19,547 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
部分点1 5 % AC * 5
部分点2 20 % AC * 6
部分点3 15 % AC * 11
部分点4 40 % AC * 22
満点 20 % AC * 35
合計 100 点
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

macro pt(s);pointerof({{s}});end
struct Time;def diff(other : Time);(self-other).abs.total_milliseconds;end;end
struct Bool;def to_i;self ? 1 : 0;end;end
macro vgen(*v);Array.new({{v[0]}}){ {% if v.size==2 %}{{v[1]}}{% else %}vgen({{v[1..].splat}}){% end %} };end
macro rvgen(type,*v);{% if v.size==2 %}Array({{type}}).new({{v[0]}}){{{v[1]}}}{% else %}Array.new({{v[0]}}){rvgen({{type}},{{v[1..].splat}})}{% end %};end
def max(a,b);a<b ? b : a;end
def min(a,b);a<b ? a : b;end
def max(*a);x=a[0];(1...a.size).each{|i|x=max(x,a[i])};x;end
def min(*a);x=a[0];(1...a.size).each{|i|x=min(x,a[i])};x;end
macro chmin(a,b);(%t={{b}};{{a}}>%t ? ({{a}}=%t;true) : false);end
macro chmax(a,b);(%t={{b}};{{a}}<%t ? ({{a}}=%t;true) : false);end
macro swap(a,b);{{a}},{{b}}={{b}},{{a}};end
def assert(cond : Bool, msg = "Assertion failed");raise msg unless cond;end
macro for(f, m, s);begin
	{{f}}
	%f = true
	loop do
		if %f;%f = false;else;{{s}};end
		break unless {{m}}
		{{yield}}
	end
end;end
struct Int
	def each_subset(&)
		s = self
		loop do
			yield s
			break if s == 0
			s = s - 1 & self
		end
	end
end
class IOset
	BUFS = 1 << 17
	@@buf = Bytes.new BUFS;@@size = 0;@@idx = 0;@@obuf = Bytes.new BUFS;@@oidx = 0;@@stk = uninitialized UInt8[20];@@precision = 8
	@@in_io = STDIN; @@out_io = STDOUT
	def self.set_io(input, output)
		@@in_io = input
		@@out_io = output
	end
	def initialize;end
	def self.fill;@@size = @@in_io.read @@buf;@@idx = 0;end
	def self.eof?;fill if @@size <= @@idx;@@size == 0;end
	def self.read_byte : UInt8?;fill if @@idx >= @@size;return nil if @@size == 0;b = @@buf[@@idx];@@idx += 1;b;end
	def self.trim;loop do;fill if @@idx >= @@size;return if @@size == 0;b = @@buf[@@idx];if b<=32;@@idx += 1;else return;end;end;end
	def self.getc : Char;c = read_byte;return 0.chr if !c;while c && c <= 32;c = read_byte;end;c ? c.not_nil!.chr : 0.chr;end
	def self.read_line : String;c = read_byte;return "" if !c;s = String.build do |i|;while c && c != 10;i.write_byte c;c = read_byte;end;end;s;end
	def self.gets : String;c = read_byte;return "" if !c;while c && c <= 32;c = read_byte;return "" if !c;end;s = String.build do |i|;while c && c > 32;i.write_byte c;c = read_byte;end;end;s;end
	macro geti_g(name, type)
		def self.{{name}} : {{type}}
			c = read_byte
			while c && c <= 32
				c = read_byte
			end
			sign = 1
			if c == 45
				sign = -1
				c = read_byte
			end
			n : {{type}} = 0
			while c && c >= 48 && c <= 57
				n = n * 10 + (c ^ 48)
				c = read_byte
			end
			n * sign
		end
	end
	geti_g(geti, Int32);geti_g(geti64, Int64);geti_g(getu, UInt32);geti_g(getu64,UInt64)
	# ---output---
	def self.write_byte(b : UInt8);flush if @@oidx == BUFS;@@obuf[@@oidx] = b;@@oidx += 1;end
	def self.write(s : String);s.each_byte { |b| write_byte b };end
	def self.write_int(n : UInt8 | UInt16 | UInt32 | UInt64 | UInt128);i = 0;loop do;@@stk[i] = (n % 10).to_u8;i += 1;break if (n //= 10) <= 0;end;while i > 0;write_byte @@stk[i-=1] | 48;end;end
	def self.write_int(x : Int8 | Int16 | Int32 | Int64 | Int128);i = 0;n = x < 0 ? -x : x;loop do;@@stk[i] = (n % 10).to_u8;i += 1;break if (n //= 10) <= 0;end;write_byte 45 if x < 0;while i > 0;write_byte @@stk[i-=1] | 48;end;end
	def self.setprecision(x);@@precision = x;end
	def self.write_float(x : Float);v = x.to_i64;f = ((x - v).abs * 10i64 ** @@precision).round.to_i64;write_int v;write_byte 46;i = 0;loop do;@@stk[i] = (f % 10).to_u8;i += 1;break if (f //= 10) <= 0;end;(@@precision - i).times { write_byte 48};while i > 0;write_byte @@stk[i-=1] | 48;end;end
	def self.flush;return if @@oidx == 0;@@out_io.write @@obuf[0, @@oidx];@@oidx = 0;end
	def self.putv(x : Array(Array(T))) forall T
		return if x.empty?
		putv x[0]
		(1...x.size).each { |i| write_byte 10;putv x[i] }
	end
	def self.putv(x)
		case x
		when Int then write_int x
		when Char then write_byte x.ord.to_u8
		when Float then write_float x
		when String then write x
		when Bool then write_byte x ? 49u8 : 48u8
		else
			return if x.empty?
			putv x[0]
			(1...x.size).each { |i| write_byte 32;putv x[i] }
		end
	end
	def self.print(*x)
		x.each { |v| putv v }
	end
	def self.outl(*x, sep = " ", endl = "\n")
		if f=x.first?
			putv f
			(1...x.size).each { |i|write sep;putv x[i]}
		end
		write endl
	end
end
macro ios;IOset;end
at_exit { ios.flush }
struct Range(B, E)
  # operator(|&^-)を離散値集合について定義する
  # 返り値は閉区間である
  def |(other : Range(B, E)) : Range(B, E) | {Range(B, E), Range(B, E)}
    b1, e1 = self.begin, self.exclusive? ? self.end - 1 : self.end
    b2, e2 = other.begin, other.exclusive? ? other.end - 1 : other.end
    if b1 <= e2.succ && b2 <= e1.succ
      (b1 < b2 ? b1 : b2)..(e1 > e2 ? e1 : e2)
    else
      r1, r2 = b1..e1, b2..e2
      b1 < b2 ? {r1, r2} : {r2, r1}
    end
  end
  def &(other : Range(B, E)) : Range(B, E)?
    b1, e1 = self.begin, self.exclusive? ? self.end - 1 : self.end
    b2, e2 = other.begin, other.exclusive? ? other.end - 1 : other.end
    b = b1 > b2 ? b1 : b2
    e = e1 < e2 ? e1 : e2
    if b <= e
      b..e
    else
      nil
    end
  end
  def ^(other : Range(B, E)) : {Range(B, E)?, Range(B, E)}
    b1, e1 = self.begin, self.exclusive? ? self.end - 1 : self.end
    b2, e2 = other.begin, other.exclusive? ? other.end - 1 : other.end
    if e2 < b1 || e1 < b2
      r1, r2 = b1..e1, b2..e2
      b1 < b2 ? {r1, r2} : {r2, r1}
    else
      b1, b2 = b2, b1 if b2 < b1
      e1, e2 = e2, e1 if e2 < e1
      {b1 < b2 ? b1..b2.pred : nil, e1 < e2 ? e2.succ..e2 : nil}
    end
  end
  def -(other : Range(B, E)) : {Range(B, E)?, Range(B, E)}
    b1, e1 = self.begin, self.exclusive? ? self.end - 1 : self.end
    b2, e2 = other.begin, other.exclusive? ? other.end - 1 : other.end
    if e2 < b1 || e1 < b2
      {b1..e1, nil}
    elsif b2 <= b1 && e1 <= e2
      {nil, nil}
    else
      {b1 < b2 ? b1..b2.pred : nil, e2 < e1 ? e2.succ..e1 : nil}
    end
  end
end
ios.geti.times do
  n, m = ios.geti, ios.geti
  l = r = offset = 0i64
  begin
    a, b = ios.geti64 - 1, ios.geti64
    offset = b
    l = a - b + 1
    r = a
  end
  ok = true
  2.upto(m) do
    a, b = ios.geti64 - 1, ios.geti64
    next if !ok
    l1, r1 = a - b  + 1 - offset, a - offset
    x = (l..r) & (l1..r1)
    if x
      l, r = x.begin, x.end
    else
      ok = false
    end
    offset += b
  end
  ios.outl ok ? "Yes" : "No"
end
0