public void run() { // Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(); StringBuilder sb = new StringBuilder(1000000); // System.setOut(new PrintStream(new BufferedOutputStream(System.out))); final int N = sc.nextInt(); final int M = sc.nextInt(); final int K = (int) floor(sqrt(N)); final int[] A = new int[N + 1]; A[0] = 1; for (int i = 1; i <= N; i++) A[i] = sc.nextInt(); final int[] next = new int[N + 1]; final int[] step = new int[N + 1]; final int[] last = new int[N + 1]; for (int i = N; i > 0; i--) { int j = i + A[i]; if (j > N || j / K > i / K) { last[i] = i; step[i] = 1; next[i] = j; } else { last[i] = last[j]; step[i] = step[j] + 1; next[i] = next[j]; } } for (int t = 0; t < M; t++) if (sc.nextInt() == 1) { int i = sc.nextInt(); int j = 0; int k = 0; while (i <= N) { j += step[i]; k = last[i]; i = next[i]; } sb.append(k).append(' ').append(j).append('\n'); // System.out.println(k + " " + j); } else { int k = sc.nextInt(); int b = k / K * K; A[k] = sc.nextInt(); for (int i = min(b + K - 1, N); i >= b; i--) { int j = i + A[i]; if (j > N || j / K > i / K) { last[i] = i; step[i] = 1; next[i] = j; } else { last[i] = last[j]; step[i] = step[j] + 1; next[i] = next[j]; } } } // System.out.flush(); System.out.print(sb); }
protected String solve(Scanner sc) { int N = sc.nextInt(); int K = sc.nextInt(); char[][] board = new char[N][]; for (int i = 0; i < N; i++) board[i] = sc.next().toCharArray(); char[][] rot = new char[N][N]; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) rot[i][j] = board[N - j - 1][i]; char[][] grav = new char[N][N]; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) grav[i][j] = '.'; for (int i = 0; i < N; i++) for (int j = N - 1, c = 0; j >= 0; j--) if (rot[j][i] == '.') c++; else grav[j + c][i] = rot[j][i]; // for (char[] cs : grav) // debug(new String(cs)); int[][][] R = new int[N][N][4]; int[][][] B = new int[N][N][4]; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) switch (grav[i][j]) { case 'B': { for (int d = 0; d < 4; d++) B[i][j][d] = (in(i + di[d], j + dj[d], N) ? B[i + di[d]][j + dj[d]][d] : 0) + 1; break; } case 'R': { for (int d = 0; d < 4; d++) R[i][j][d] = (in(i + di[d], j + dj[d], N) ? R[i + di[d]][j + dj[d]][d] : 0) + 1; break; } } boolean Rwin = false, Bwin = false; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) for (int d = 0; d < 4; d++) { if (R[i][j][d] >= K) Rwin = true; if (B[i][j][d] >= K) Bwin = true; } return Rwin ? Bwin ? "Both" : "Red" : Bwin ? "Blue" : "Neither"; }
public void diff(int id, String small, String large) { try { Scanner sm = new Scanner(new File(small)); Scanner lg = new Scanner(new File(large)); int line = 0; while (sm.hasNextLine() && lg.hasNextLine()) { String s = sm.nextLine(); String l = lg.nextLine(); if (!s.equals(l)) { System.out.println(line + ">" + s); System.out.println(line + "<" + l); } line++; } } catch (Exception e) { e.printStackTrace(); } }
public void run() { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); sc.nextLine(); for (int t = 1; t <= T; t++) System.out.printf("Case #%s: %s%n", t, solve(sc)); }