結果
問題 | No.801 エレベーター |
ユーザー |
|
提出日時 | 2019-03-17 22:04:03 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 1,386 ms / 2,000 ms |
コード長 | 3,515 bytes |
コンパイル時間 | 1,109 ms |
コンパイル使用メモリ | 113,456 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-13 04:20:52 |
合計ジャッジ時間 | 23,738 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
import std.stdio, std.string, std.conv;import std.range, std.algorithm, std.array, std.typecons, std.container;import std.math, std.numeric, core.bitop;enum inf3 = 1_001_001_001;enum inf6 = 1_001_001_001_001_001_001L;enum mod = 1_000_000_007L;void main() {int n, m, k;scan(n, m, k);auto L = new int[](m);auto R = new int[](m);iota(m).each!(i => scan(L[i], R[i]));L[] -= 1;auto cur = FenwickTree!(long)(n + 1);cur.add(0, 1);foreach (i ; 0 .. k) {auto nex = FenwickTree!(long)(n + 1);foreach (j ; 0 .. m) {auto a = cur.sum(L[j], R[j]);nex.add(L[j], a);nex.add(R[j], -a);}cur = FenwickTree!(long)(n + 1);foreach (j ; 0 .. n) {cur.add(j, nex.psum(j + 1));}}auto ans = cur.sum(n - 1, n);writeln(ans);}struct FenwickTree(T) {private {int _size;T[] _data;}this(int N) {_size = N;_data = new T[](_size + 1);}void add(int i, T x) {if (x < 0) {x += mod;}i++;while (i <= _size) {_data[i] += x;_data[i] %= mod;i += i & (-i);}}T psum(int r) {T res = 0;while (r > 0) {res += _data[r];res %= mod;r -= r & (-r);}return res;}T sum(int l, int r) {return (psum(r) - psum(l) + mod) % mod;}}int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {auto adj = new int[][](n, 0);foreach (i; 0 .. m) {int u, v;scan(u, v);if (is1indexed) {u--, v--;}adj[u] ~= v;if (isUndirected) {adj[v] ~= u;}}return adj;}alias Edge = Tuple!(int, "to", int, "cost");Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {auto adj = new Edge[][](n, 0);foreach (i; 0 .. m) {int u, v, c;scan(u, v, c);if (is1indexed) {u--, v--;}adj[u] ~= Edge(v, c);if (isUndirected) {adj[v] ~= Edge(u, c);}}return adj;}void yes(bool b) {writeln(b ? "Yes" : "No");}void YES(bool b) {writeln(b ? "YES" : "NO");}T[] readArr(T)() {return readln.split.to!(T[]);}T[] readArrByLines(T)(int n) {return iota(n).map!(i => readln.chomp.to!T).array;}void scan(T...)(ref T args) {import std.stdio : readln;import std.algorithm : splitter;import std.conv : to;import std.range.primitives;auto line = readln().splitter();foreach (ref arg; args) {arg = line.front.to!(typeof(arg));line.popFront();}assert(line.empty);}void fillAll(R, T)(ref R arr, T value) {static if (is(typeof(arr[] = value))) {arr[] = value;}else {foreach (ref e; arr) {fillAll(e, value);}}}bool chmin(T, U...)(ref T x, U args) {bool isChanged;foreach (arg; args) {if (x > arg) {x = arg;isChanged = true;}}return isChanged;}bool chmax(T, U...)(ref T x, U args) {bool isChanged;foreach (arg; args) {if (x < arg) {x = arg;isChanged = true;}}return isChanged;}