0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:48:48 +00:00

#1454. 【NOIP模拟(第二套)】B. 数连通块

https://sjzezoj.com/submission/54011
This commit is contained in:
Baoshuo Ren 2022-07-22 21:47:30 +08:00
parent 813aade458
commit 1d93a5dcf2
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
22 changed files with 148 additions and 0 deletions

85
S2OJ/1454/1454.cpp Normal file
View 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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.