#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)n; i++) #define ST first #define ND second #define MP make_pair #define PB push_back typedef vector<int> VI; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef set<int> SI; typedef long long LL; #ifdef DEBUG const bool debug = true; #else const bool debug = false; #endif // #define MULTI_TASK true const int INF = 1000 * 1000 * 1000; const LL INFLL = 1e18; const int MAKSN = 300 * 1000 + 13; const LL MOD = 1e9 + 7; LL N, M, k, l, a, b, c, d, r; vector<pair<LL, LL>> v; set<int> possMasks; vector<int> E[MAKSN]; void zeruj() { v.clear(); } void genGraph() { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (abs(v[i].ST - v[j].ST) <= v[i].ND) { E[i].push_back(j); } } } } void readIn() { cin >> N; REP(i, N) { cin >> a >> r; v.PB({a, r}); } genGraph(); } void dfs(int v, vector<bool>& vis) { vis[v] = true; for (auto u : E[v]) { if (!vis[u]) { dfs(u, vis); } } } void checkMask(LL detonated) { LL mask = 0; vector<bool> vis(N, false); for (LL i = 0; i < N; i++) { if (detonated & (1 << i)) { dfs(i, vis); } } for (LL i = 0; i < N; i++) { if (vis[i]) mask |= (1 << i); } possMasks.insert(mask); } LL powMod(LL a, LL b) { LL res = 1LL, curP = a; while (b > 0) { if (b & 1LL) res = (res * curP) % MOD; curP = (long long)(curP * curP) % MOD; b >>= 1; } return res; } LL minu(LL a, LL b) { LL res = (a - b + MOD) % MOD; cerr << res << "\n"; return res; } LL lul() { LL res = powMod(2, N); for (LL i = 0; i < N; i++) { vector<bool> vis(N, false); dfs(i, vis); LL cur = 0; for (int j = 0; j < N; j++) { cur += vis[j]; } res = minu(res, powMod(2, cur - 1)); } return res; } void solve() { if (N <= 25) { for (LL i = 0; i < (1 << N); i++) { checkMask(i); } cout << possMasks.size() << "\n"; } else { cout << lul() << "\n"; } } int main() { ios_base::sync_with_stdio(0); #ifdef MULTI_TASK int test; cin >> test; while (test--) { #endif zeruj(); readIn(); solve(); #ifdef MULTI_TASK } #endif return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | #include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)n; i++) #define ST first #define ND second #define MP make_pair #define PB push_back typedef vector<int> VI; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef set<int> SI; typedef long long LL; #ifdef DEBUG const bool debug = true; #else const bool debug = false; #endif // #define MULTI_TASK true const int INF = 1000 * 1000 * 1000; const LL INFLL = 1e18; const int MAKSN = 300 * 1000 + 13; const LL MOD = 1e9 + 7; LL N, M, k, l, a, b, c, d, r; vector<pair<LL, LL>> v; set<int> possMasks; vector<int> E[MAKSN]; void zeruj() { v.clear(); } void genGraph() { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (abs(v[i].ST - v[j].ST) <= v[i].ND) { E[i].push_back(j); } } } } void readIn() { cin >> N; REP(i, N) { cin >> a >> r; v.PB({a, r}); } genGraph(); } void dfs(int v, vector<bool>& vis) { vis[v] = true; for (auto u : E[v]) { if (!vis[u]) { dfs(u, vis); } } } void checkMask(LL detonated) { LL mask = 0; vector<bool> vis(N, false); for (LL i = 0; i < N; i++) { if (detonated & (1 << i)) { dfs(i, vis); } } for (LL i = 0; i < N; i++) { if (vis[i]) mask |= (1 << i); } possMasks.insert(mask); } LL powMod(LL a, LL b) { LL res = 1LL, curP = a; while (b > 0) { if (b & 1LL) res = (res * curP) % MOD; curP = (long long)(curP * curP) % MOD; b >>= 1; } return res; } LL minu(LL a, LL b) { LL res = (a - b + MOD) % MOD; cerr << res << "\n"; return res; } LL lul() { LL res = powMod(2, N); for (LL i = 0; i < N; i++) { vector<bool> vis(N, false); dfs(i, vis); LL cur = 0; for (int j = 0; j < N; j++) { cur += vis[j]; } res = minu(res, powMod(2, cur - 1)); } return res; } void solve() { if (N <= 25) { for (LL i = 0; i < (1 << N); i++) { checkMask(i); } cout << possMasks.size() << "\n"; } else { cout << lul() << "\n"; } } int main() { ios_base::sync_with_stdio(0); #ifdef MULTI_TASK int test; cin >> test; while (test--) { #endif zeruj(); readIn(); solve(); #ifdef MULTI_TASK } #endif return 0; } |