there 2D grid size n x n cell grid lamp initially turn offyou give 2D array lamp position lamp lampsi rowi coli indicate lamp gridrowicoli turn even lamp list turn onwhen lamp turn illuminates cell cell row column diagonalyou give 2D array query queriesj rowj colj for jth query determine gridrowjcolj illuminate after answer jth query turn lamp gridrowjcolj 8 adjacent lamp exist a lamp adjacent cell share corner gridrowjcoljReturn array integer ans ansj 1 cell jth query illuminate 0 lamp Example 1input n 5 lamp 0044 query 1110output 10explanation we initial grid lamp turn in picture grid turn lamp grid00 turn lamp grid44the 0th query ask lamp grid11 illuminate blue square it illuminate set ans0 1 then turn lamp red squarethe 1st query ask lamp grid10 illuminate blue square it illuminate set ans1 0 then turn lamp red rectangleexample 2input n 5 lamp 0044 query 1111output 11example 3input n 5 lamp 0004 query 040114output 110 Constraints1 n 1090 lampslength 200000 querieslength 20000lampsilength 20 rowi coli nqueriesjlength 20 rowj colj n