diff --git a/S2OJ/1454/1454.cpp b/S2OJ/1454/1454.cpp new file mode 100644 index 00000000..0c1ded94 --- /dev/null +++ b/S2OJ/1454/1454.cpp @@ -0,0 +1,85 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; +const int mod = 1e9 + 7; + +int n, m, q, p[N], s[N], c[N], ans[N]; +std::vector g[N]; +std::vector> qs[N]; + +int binpow(int a, int b) { + int res = 1; + a %= mod; + + while (b) { + if (b & 1) res = static_cast(res) * a % mod; + a = static_cast(a) * a % mod; + b >>= 1; + } + + return res; +} + +inline int lowbit(int x) { + return x & -x; +} + +void add(int x, int y) { + for (; x; x -= lowbit(x)) c[x] = (c[x] + y) % mod; +} + +int sum(int x) { + int res = 0; + for (; x <= n; x += lowbit(x)) res = (res + c[x]) % mod; + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m >> q; + + for (int i = 1, a, b; i <= n; i++) { + cin >> a >> b; + + p[i] = static_cast(a) * binpow(b, mod - 2) % mod; + s[i] = (s[i - 1] + p[i]) % mod; + } + + for (int i = 1, u, v; i <= m; i++) { + cin >> u >> v; + + if (u > v) std::swap(u, v); + + g[v].push_back(u); + } + + for (int i = 1, l, r; i <= q; i++) { + cin >> l >> r; + + ans[i] = (s[r] - s[l - 1]) % mod; + qs[r].emplace_back(i, l); + } + + for (int i = 1; i <= n; i++) { + for (int v : g[i]) { + add(v, static_cast(p[i]) * p[v] % mod); + } + + for (auto t : qs[i]) { + ans[t.first] = (ans[t.first] - sum(t.second)) % mod; + } + } + + for (int i = 1; i <= q; i++) { + cout << (static_cast(ans[i]) % mod + mod) % mod << endl; + } + + return 0; +} diff --git a/S2OJ/1454/data/data1.in b/S2OJ/1454/data/data1.in new file mode 100644 index 00000000..abe49d5b --- /dev/null +++ b/S2OJ/1454/data/data1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7a30217d09353f3a8fb0771b40d86d7349793cfce52c129be08830fa22b0a18f +size 227 diff --git a/S2OJ/1454/data/data1.out b/S2OJ/1454/data/data1.out new file mode 100644 index 00000000..53a47839 --- /dev/null +++ b/S2OJ/1454/data/data1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e37a370d08358224adc122423de44bbb4cc2d1550138956c978f07ff85d07a16 +size 110 diff --git a/S2OJ/1454/data/data10.in b/S2OJ/1454/data/data10.in new file mode 100644 index 00000000..8b42f303 --- /dev/null +++ b/S2OJ/1454/data/data10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0583d35e15d37de312d2b6348e35051938f39f71ce97560f01039e3beb26e9c3 +size 3638092 diff --git a/S2OJ/1454/data/data10.out b/S2OJ/1454/data/data10.out new file mode 100644 index 00000000..60d42b67 --- /dev/null +++ b/S2OJ/1454/data/data10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:14113633e30e513e12bd109e5272e97d6e977f32d3537323b0a1185933743f42 +size 1088829 diff --git a/S2OJ/1454/data/data2.in b/S2OJ/1454/data/data2.in new file mode 100644 index 00000000..cf7b560d --- /dev/null +++ b/S2OJ/1454/data/data2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be717c28a42e12e1d131b47def5a87b3645fb3c1247d356803d37738a85ddd22 +size 3637185 diff --git a/S2OJ/1454/data/data2.out b/S2OJ/1454/data/data2.out new file mode 100644 index 00000000..a9f29b9a --- /dev/null +++ b/S2OJ/1454/data/data2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:afaf6ff2300b703df6aed234627eefa36890367d59f6145703be01b484692d48 +size 1088884 diff --git a/S2OJ/1454/data/data3.in b/S2OJ/1454/data/data3.in new file mode 100644 index 00000000..dd3d23cd --- /dev/null +++ b/S2OJ/1454/data/data3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:006ced0adbb77f31a1610ca2950a7156de78dd87779f2d92209b12f0daeac8df +size 3637974 diff --git a/S2OJ/1454/data/data3.out b/S2OJ/1454/data/data3.out new file mode 100644 index 00000000..e2e04dc1 --- /dev/null +++ b/S2OJ/1454/data/data3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d5b3a900f079a6945f9da163c5577809511004841cfd237f1a0c81eb51be354 +size 1088993 diff --git a/S2OJ/1454/data/data4.in b/S2OJ/1454/data/data4.in new file mode 100644 index 00000000..94adf24c --- /dev/null +++ b/S2OJ/1454/data/data4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:23ffd5072f063b7453e1fbf26ca27a35bd11dc37c37783fbb67b9bea4987f788 +size 2461019 diff --git a/S2OJ/1454/data/data4.out b/S2OJ/1454/data/data4.out new file mode 100644 index 00000000..6bc1c916 --- /dev/null +++ b/S2OJ/1454/data/data4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4005e940e6e4d72054d1ad676bcd61f86ed0a3603a41f99e0f855f0b928350df +size 11 diff --git a/S2OJ/1454/data/data5.in b/S2OJ/1454/data/data5.in new file mode 100644 index 00000000..ec598502 --- /dev/null +++ b/S2OJ/1454/data/data5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e69460684345de230fec4c807c94228bac31b1074b46f30108e10899fb11b6d +size 3637202 diff --git a/S2OJ/1454/data/data5.out b/S2OJ/1454/data/data5.out new file mode 100644 index 00000000..3a309e79 --- /dev/null +++ b/S2OJ/1454/data/data5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a7d1b72d18e26637facdd472ed703b2aec28ab7487f8fa1bbbae6e8efa961bc +size 1088877 diff --git a/S2OJ/1454/data/data6.in b/S2OJ/1454/data/data6.in new file mode 100644 index 00000000..871699ae --- /dev/null +++ b/S2OJ/1454/data/data6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1cd4fd709b7c1a894a9ca2b6a52e9ca5098865967cf7b91ae5a5a96b76560921 +size 3637209 diff --git a/S2OJ/1454/data/data6.out b/S2OJ/1454/data/data6.out new file mode 100644 index 00000000..b5cad3e0 --- /dev/null +++ b/S2OJ/1454/data/data6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7936ed052768ad94400f3491332d0dd670136386136480ffc5eef3fbb65fb385 +size 1088973 diff --git a/S2OJ/1454/data/data7.in b/S2OJ/1454/data/data7.in new file mode 100644 index 00000000..8c678a46 --- /dev/null +++ b/S2OJ/1454/data/data7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0dd1edf92db489b47246dba606f059035972e0be5b0932cd0b50bffb3102b9b +size 3637463 diff --git a/S2OJ/1454/data/data7.out b/S2OJ/1454/data/data7.out new file mode 100644 index 00000000..db54bbf0 --- /dev/null +++ b/S2OJ/1454/data/data7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c171a2dc64a8aefe65da04b4c5b6daf68df4b2777c7d53713b62b0228bdb72a5 +size 1089015 diff --git a/S2OJ/1454/data/data8.in b/S2OJ/1454/data/data8.in new file mode 100644 index 00000000..62b6ef56 --- /dev/null +++ b/S2OJ/1454/data/data8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4f339b2301c20e223aa0daf4b15fcea0929b5038fa55e8855661cd99d117777f +size 3638295 diff --git a/S2OJ/1454/data/data8.out b/S2OJ/1454/data/data8.out new file mode 100644 index 00000000..dd7eccd4 --- /dev/null +++ b/S2OJ/1454/data/data8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e8461b8c06388f8324135c1afecb41abb5e653f94cc735cde0c2b8b71b5c8c92 +size 1088854 diff --git a/S2OJ/1454/data/data9.in b/S2OJ/1454/data/data9.in new file mode 100644 index 00000000..30ac0432 --- /dev/null +++ b/S2OJ/1454/data/data9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a301c1fc50a525c58dfb79de6155c90d61bd8fe1353a5f722f1ec9e484e929a2 +size 3636235 diff --git a/S2OJ/1454/data/data9.out b/S2OJ/1454/data/data9.out new file mode 100644 index 00000000..f84235be --- /dev/null +++ b/S2OJ/1454/data/data9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2215334efe0f4447ce0de4e9c441aef7d2e9257e4116381104923a722840b2e7 +size 1088946 diff --git a/S2OJ/1454/data/problem.conf b/S2OJ/1454/data/problem.conf new file mode 100644 index 00000000..ba9de959 --- /dev/null +++ b/S2OJ/1454/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:30571b8545311d892f94d95e21b7a5ee74e6f33bf2ec8f532fd209827fdd4be9 +size 194