This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
int c[N] , x[N] , y[N] , n , m , k;
set<pair<int , int> > st , s;
map<int , int> mp;
int ch = 1 , flg = 1 , cnt[2];
long long power(int a , int b){
if(!b) return 1;
long long tmp = power(a , b / 2);
tmp = tmp * tmp % MOD;
if(b & 1) tmp = tmp * a % MOD;
return tmp;
}
int32_t main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m >> k;
for(int i = 0 ; i < k ; i++){
char cc;
cin >> cc >> x[i] >> y[i];
c[i] = (cc == '+' ? 1 : 0);
}
for(int i = 0 ; i < k ; i++){
auto it = st.lower_bound({x[i] , -1});
if(it == st.end()){
st.insert({x[i] , ((y[i] + c[i]) & 1)});
continue;
}
pair<int , int> p = *it;
if(p.second != ((y[i] + c[i]) & 1)){
ch = 0;
break;
}
}
for(int i = 0 ; i < k ; i++){
auto it = s.lower_bound({y[i] , -1});
if(it == s.end()){
s.insert({y[i] , ((x[i] + c[i]) & 1)});
continue;
}
pair<int , int> p = *it;
if(p.second != ((x[i] + c[i]) & 1)){
flg = 0;
break;
}
}
for(auto &p : st){
if(!mp[p.first]){
cnt[0]++;
mp[p.first] = 1;
}
}
mp.clear();
for(auto &p : s){
if(!mp[p.first]){
cnt[1]++;
mp[p.first] = 1;
}
}
mp.clear();
long long ans = power(2 , n - cnt[0]) * ch + power(2 , m - cnt[1]) * flg % MOD;
ans += MOD;
flg = ch = 1;
for(int i = 0 ; i < k ; i++){
if((x[i] + y[i] + c[i]) & 1)
flg = 0;
else
ch = 0;
}
cout << (ans - flg - ch) % MOD << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |