Language: C++

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 998244353;

long long power(long long a, long long b)
{
    long long ret = 1;
    long long tmp = a;
    while(b > 0){
        if(b & 1){
            ret *= tmp;
            ret %= MOD;
        }
        tmp *= tmp;
        tmp %= MOD;
        b >>= 1;
    }
    return ret;
}

long long solve(int n, const map<pair<int, int>, int>& cell)
{
    long long cnt = (n * (long long)n - (5 * n - 6)) / 2;
    for(const auto& p : cell){
        int a, b, c;
        tie(tie(a, b), c) = p;
        if(a < b - 2){
            auto it = cell.find(make_pair(b, a));
            if(it != cell.end() && c != it->second)
                return 0;
            -- cnt;
        }
    }

    vector<long long> dp(2, 0);
    dp[0] = power(2, cnt);
    for(int i=0; i<n; ++i){
        vector<long long> nextDp(2, 0);
        for(int a=0; a<2; ++a){
            for(int b=0; b<2; ++b){
                auto it = cell.find(make_pair(i, i));
                if(it != cell.end() && b != it->second)
                    continue;

                long long tmp = 1;
                if(i > 0){
                    auto it1 = cell.find(make_pair(i-1, i));
                    auto it2 = cell.find(make_pair(i, i-1));
                    if(it1 == cell.end() && it2 == cell.end())
                        tmp *= 2;
                    else if(it1 != cell.end() && it2 != cell.end() && (it1->second + it2->second + a + b) % 2 != 0)
                        continue;
                }
                if(i > 0 && i < n - 1){
                    auto it1 = cell.find(make_pair(i-1, i+1));
                    auto it2 = cell.find(make_pair(i+1, i-1));
                    if(it1 == cell.end() && it2 == cell.end())
                        tmp *= 2;
                    else if(it1 != cell.end() && it2 != cell.end() && (it1->second + it2->second + b) % 2 != 0)
                        continue;
                }

                nextDp[b] += dp[a] * tmp;
                nextDp[b] %= MOD;
            }
        }
        dp = move(nextDp);
    }

    return (dp[0] + dp[1]) % MOD;
}

int main()
{
    int n, m;
    cin >> n >> m;
    map<pair<int, int>, int> cell;
    for(int i=0; i<m; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        -- a;
        -- b;
        cell[make_pair(a, b)] = c;
    }

    cout << solve(n, cell) << endl;

    return 0;
}


Compiler output:
a.cc: In function 'long long int solve(int, const std::map<std::pair<int, int>, int>&)':
a.cc:52:16: error: cannot bind non-const lvalue reference of type 'std::tuple<int&, int&>&' to an rvalue of type 'std::tuple<int&, int&>'
   52 |         tie(tie(a, b), c) = p;
      |             ~~~^~~~~~
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:3:
/usr/include/c++/14/tuple:2791:19: note:   initializing argument 1 of 'constexpr std::tuple<_Elements& ...> std::tie(_Elements& ...) [with _Elements = {tuple<int&, int&>, int}]'
 2791 |     tie(_Elements&... __args) noexcept
      |         ~~~~~~~~~~^~~~~~~~~~