mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 15:58:48 +00:00
parent
813aade458
commit
1d93a5dcf2
85
S2OJ/1454/1454.cpp
Normal file
85
S2OJ/1454/1454.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
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<int> g[N];
|
||||
std::vector<std::pair<int, int>> qs[N];
|
||||
|
||||
int binpow(int a, int b) {
|
||||
int res = 1;
|
||||
a %= mod;
|
||||
|
||||
while (b) {
|
||||
if (b & 1) res = static_cast<long long>(res) * a % mod;
|
||||
a = static_cast<long long>(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<long long>(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<long long>(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<long long>(ans[i]) % mod + mod) % mod << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/1454/data/data1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/data9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/data9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1454/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1454/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user