module Main; import BinaryHeap; import BoolArray; import CPLib.Arithmetic; import CPLib.DSegtree; import CPLib.Graph; import CPLib.IO; import CPLib.LSegtree; import CPLib.UnionFind; import CPLib.ZP; import CPLib.Monoid; import HashMap; import HashSet; type Z = ZP P1000000007; // type Tree = type Tree = LSegtree (WeightedSum Z) (RangeAdd WeightedSum Z); main : IO () = ( let cN = *read_i; // 回数 let cM = *read_i; // エレベータの数 let cK = *read_i; // 移動回数 let cLRs = *range(0, cM).fold_m([], |_, cLRs| let l = *read_i; let r = *read_i; let l = l - 1; cLRs.push_back((l, r)).pure ); // eval "cLRs = {}".debug_eprintfln((cLRs,)); let t = LSegtree::create(cN) : Tree; let t = t.set(0, WeightedSum::make_single(zp(1))); let t = range(0, cK).fold(t, |k, t| // eval "k = {}, t = {}".debug_eprintfln( // ( // k, // range(0, cN).map(|i| t.@(i).@v.@value).to_array // ) // ); let s = LSegtree::build(fill(cN, make_single(zp(0)))) : Tree; let s = range(0, cM).fold(s, |m, s| let (l, r) = cLRs.@(m); let sum = t.fold(l, r); // eval "k = {}, m = {}, l = {}, r = {}, sum = {}".debug_eprintfln((k,m,l,r,sum.@v.@value)); // eval "k = {}, before s = {}".debug_eprintfln( // ( // k, // range(0, cN).map(|i| s.@(i).@v.@value).to_array // ) // ); let s = s.act_range(l, r, RangeAdd { a : sum.@v }); // eval "k = {}, aftrer s = {}".debug_eprintfln( // ( // k, // range(0, cN).map(|i| s.@(i).@v.@value).to_array // ) // ); s ); s ); let ans = t.@(cN-1); ans.@v.@value.to_string.println );