#include #include #include #include using namespace std; bool inc(int a, int b, int c) { return a <= b && b <= c; } // result info struct result1 { int i1, i2, j1, j2, x, y; int res; int size; double ave; result1(int i1, int i2, int j1, int j2, int x, int y, int res): i1(i1), i2(i2), j1(j1), j2(j2), x(x), y(y), res(res) { size = (i2 - i1 + 1) * (j2 - j1 + 1); ave = float(res) / size; } bool contains(int i, int j) { return inc(i1, i, i2) && inc(j1, j, j2); } }; struct result2 { int i1, i2, j1, j2; int res; int size; double ave; result2(int i1, int i2, int j1, int j2, int res): i1(i1), i2(i2), j1(j1), j2(j2), res(res) { size = (i2 - i1 + 1) * (j2 - j1 + 1); ave = float(res) / size; } bool contains(int i, int j) { return inc(i1, i, i2) && inc(j1, j, j2); } }; int n, m; int **guess; int asks = 500000; int ask2s = 1000; // initialize stuff void init() { scanf("%d%d%d", &n, &m, &ask2s); guess = new int*[n]; for (int i = 0; i < n; i++) { guess[i] = new int[m]; for (int j = 0; j < m; j++) { guess[i][j] = 25; } } } // list of results (in case we need it in the future for some magic algorithm) vector r1s; vector r2s; // ask question 1. return -1 if questions ran out. int ask1(int i1, int i2, int j1, int j2, int x, int y) { if (asks <= 0) return -1; asks--; printf("1 %d %d %d %d %d %d\n", i1+1, i2+1, j1+1, j2+1, x, y); fflush(stdout); int res; scanf("%d", &res); r1s.push_back(result1(i1, i2, j1, j2, x, y, res)); return res; } // ask question 2. return -1 if questions ran out. int ask2(int i1, int i2, int j1, int j2) { if (ask2s <= 0) return -1; if (asks <= 0) return -1; ask2s--, asks--; printf("2 %d %d %d %d\n", i1+1, i2+1, j1+1, j2+1); fflush(stdout); int res; scanf("%d", &res); r2s.push_back(result2(i1, i2, j1, j2, res)); return res; } // print the guess void write_guess() { printf("3\n"); fflush(stdout); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (j) printf(" "); printf("%d", max(1, min(50, guess[i][j]))); } puts(""); } fflush(stdout); } int main() { init(); // semi-stupid solution: guess each value individually for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int v = ask2(i, i, j, j); if (v == -1) { // no more ask2.. binary search with ask1 int x = 1, y = 50; while (x < y) { int z = x + y >> 1; int res = ask1(i, i, j, j, x, z); if (res == -1) break; // no more ask1! just guess if (res) { y = z; } else { x = z+1; } } v = (x + y) / 2; // best bet is the middle value. } guess[i][j] = v; } } write_guess(); }