Submission #388161

#TimeUsernameProblemLanguageResultExecution timeMemory
388161SaraPlus Minus (BOI17_plusminus)C++14
100 / 100
139 ms18360 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; #define ll long long #define F first #define S second #define pb push_back #define lc (ind << 1) #define rc (lc | 1) #define md ((b + e) >> 1) const ll N = 1e5 + 5; const ll M = 1e6 + 5; const ll LOG = 30; const ll INF = 1e9 + 5; const ll MOD = 1e9 + 7; ll power(ll x, ll t){ if (t == 0){ return 1ll; } return ((t & 1) ? x : 1ll) * power(x * x % MOD, t >> 1ll) % MOD; } int n, m, k; int X[N]; int Y[N]; bool ty[N]; vector <int> bib1, bib2; int ind1[N], ind2[N]; vector <int> in1[2][N], in2[2][N]; inline void compress(vector <int> &vec){ sort(vec.begin(), vec.end()); vec.resize(unique(vec.begin(), vec.end()) - vec.begin()); return; } inline ll solve(){ if (k == 0){ return (2ll * power(2ll, m - 1ll) % MOD + (power(2ll, n) - 2ll)) % MOD; } ll bad = 1; ll ans1 = power(2ll, (ll)n - (ll)bib1.size()); for (int i = 0; i < (int)bib1.size(); i ++){ for (int j = 1; j < (int)in1[0][i].size(); j ++){ bool f1 = (in1[0][i][j - 1] & 1); bool f2 = (in1[0][i][j] & 1); if (f1 != f2){ ans1 = 0; bad = 0; } } for (int j = 1; j < (int)in1[1][i].size(); j ++){ bool f1 = (in1[1][i][j - 1] & 1); bool f2 = (in1[1][i][j] & 1); if (f1 != f2){ ans1 = 0; bad = 0; } } if ((int)in1[0][i].size() && (int)in1[1][i].size()){ bool f1 = (in1[0][i][0] & 1); bool f2 = (in1[1][i][0] & 1); if (f1 == f2){ ans1 = 0; bad = 0; } } } ll ans2 = power(2ll, (ll)m - (ll)bib2.size()); for (int i = 0; i < (int)bib2.size(); i ++){ for (int j = 1; j < (int)in2[0][i].size(); j ++){ bool f1 = (in2[0][i][j - 1] & 1); bool f2 = (in2[0][i][j] & 1); if (f1 != f2){ ans2 = 0; bad = 0; } } for (int j = 1; j < (int)in2[1][i].size(); j ++){ bool f1 = (in2[1][i][j - 1] & 1); bool f2 = (in2[1][i][j] & 1); if (f1 != f2){ ans2 = 0; bad = 0; } } if ((int)in2[0][i].size() && (int)in2[1][i].size()){ bool f1 = (in2[0][i][0] & 1); bool f2 = (in2[1][i][0] & 1); if (f1 == f2){ ans2 = 0; bad = 0; } } } return ((ans1 + ans2) % MOD - bad + MOD) % MOD; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m >> k; for (int i = 0; i < k; i ++){ char c; cin >> c >> X[i] >> Y[i]; ty[i] = (c == '-'); bib1.pb(X[i]); bib2.pb(Y[i]); } compress(bib1); compress(bib2); for (int i = 0; i < k; i ++){ ind1[i] = lower_bound(bib1.begin(), bib1.end(), X[i]) - bib1.begin(); ind2[i] = lower_bound(bib2.begin(), bib2.end(), Y[i]) - bib2.begin(); } for (int i = 0; i < k; i ++){ in1[ty[i]][ind1[i]].pb(Y[i]); in2[ty[i]][ind2[i]].pb(X[i]); } cout << (solve() % MOD + MOD) % MOD << '\n'; return 0; } /* 2 4 4 + 1 1 - 1 2 + 1 3 - 1 4 */ /* 3 3 3 - 2 1 + 2 3 + 3 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...