#pragma region include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include //#include #include #pragma endregion //#include ///////// #pragma region typedef typedef long long LL; typedef long double LD; typedef unsigned long long ULL; typedef std::pair PLL;// typedef std::pair PII;// #pragma endregion //typedef ////定数 const int INF = (int)1e9; const LL MOD = (LL)1e9+7; const LL LINF = (LL)4e18+20; const LD PI = acos(-1.0); const double EPS = 1e-9; ///////// using namespace::std; int H,W; vector< vector > field; void solve(){ cin >> H >> W; field = vector< vector >(H+2,vector(W+2,4)); for(int h=0;h> field[h+1][w+1]; } } int Q; cin >> Q; int R,C,X; queue posQ; vector dir(4); dir[0] = 1; dir[1] = W+2; dir[2] = -1; dir[3] = -(W+2); int now; while(Q--){ cin >> R >> C >> X; if( field[R][C] == X ) continue; int chang = field[R][C]; field[R][C] = X; posQ.push( R*(W+2)+C); while(posQ.size()){ now = posQ.front(); posQ.pop(); for(int k=0;k<4;++k){ int temp = now + dir[k]; int r = temp/(W+2); int c = temp%(W+2); if( field[r][c] == chang ){ field[r][c] = X; posQ.push( temp ); } } } } for(int h=0;h