Https://biancheng.love/problem/640/index
Always re
Not a collection?
#include <cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#include<assert.h>#defineIOS Ios::sync_with_stdio (False)using namespacestd;#defineINF (0X3F3F3F3F)typedefLong Long intLL; #include<iostream>#include<sstream>#include<vector>#include<Set>#include<map>#include<queue>#include<string>Const intMAXN = 1e6 + -;ConstLL MOD =10007;intN, M, q;stringSTR[MAXN];intFA[MAXN];intSIZE[MAXN];intFirst[mod + -];intnum;voidInitinttot) { for(inti =0; I <= MOD; ++i) {Fa[i]=i; Size[i]=1; } memset (First,0,sizeofFirst ); Num=0;}structNode {LL val; intID; intu; intTonext;} E[MAXN*2];voidAddintXinty) {++num; E[num].val= 1LL * x *1000000+y; ASSERT (E[num].val>=0); E[num].id=num; E[NUM].U= e[num].val%MOD; E[num].tonext=FIRST[E[NUM].U]; FIRST[E[NUM].U]=num;}intTohash (intXinty) {LL val= 1LL * x *1000000+y; intU = val%MOD; for(inti = First[u]; I i =E[i].tonext) { if(E[i].val = = val)returne[i].id; } while(1);//assert (false);}intTofind (intx) {if(Fa[x] = = x)returnx; Else returnFA[X] =Tofind (fa[x]);}voidTomerge (intXinty) {x=tofind (x); Y=tofind (y); if(X! =y) {fa[y]=x; SIZE[X]+=Size[y]; }}inttonext[4][2] = {{0,1}, {1,0}, {0, -1}, { -1,0}};structData {intVal, FA;} gg[ A];voidWork () {scanf ("%d%d%d", &n, &m, &q); for(inti =1; I <= N; ++i) {scanf ("%s", Str[i].c_str () +1); } init (n*m); for(inti =1; I <= N; ++i) { for(intj =1; J <= M; ++j) {Add (I, j); } } for(inti =1; I <= N; ++i) { for(intj =1; J <= M; ++j) {ifI1>=1&& Str[i-1][J] = =Str[i][j]) { intx =Tofind (Tohash (i, j)); inty = Tofind (Tohash (i-1, J)); Tomerge (x, y); } if(J-1>=1&& Str[i][j-1] ==Str[i][j]) { intx = Tofind (Tohash (i, J-1)); inty =Tofind (Tohash (i, j)); Tomerge (x, y); } } } while(q--) { intx, y; scanf ("%d%d", &x, &y); memset (GG,0,sizeofGG); intAns =Size[tofind (Tohash (x, y))]; for(inti =0; I <4; ++i) {inttx = x + tonext[i][0]; intty = y + tonext[i][1]; if(TX >=1&& TX <= n && ty >=1&& Ty <=m) {intFather =Tofind (Tohash (TX, Ty)); if(Gg[str[tx][ty]-'0'].fa = = father)Continue; Gg[str[tx][ty]-'0'].val + =Size[father]; Gg[str[tx][ty]-'0'].FA =father; } } intID =Str[x][y]; for(inti =0; I <4; ++i) {inttx = x + tonext[i][0]; intty = y + tonext[i][1]; if(TX >=1&& TX <= n && ty >=1&& Ty <=m) {//int father = Tofind (Tohash (TX, Ty)); if(Ans < gg[str[tx][ty]-'0'].val) {ans= Gg[str[tx][ty]-'0'].val; ID=Str[tx][ty]; } Else if(ans = = gg[str[tx][ty]-'0'].val) {if(id = =Str[x][y]) {ID=Str[tx][ty]; } }}} printf ("%d\n", ANS + (id! =str[x][y])); }}intMain () {#ifdef local freopen ("Data.txt","R", stdin);//freopen ("Data.txt", "w", stdout);#endif intT; scanf ("%d", &t); while(t--) work (); return 0;}
View Code
Two points between this problem is poisonous ah, will not do