Submission #303224

#TimeUsernameProblemLanguageResultExecution timeMemory
303224llakiComparing Plants (IOI20_plants)Java
0 / 100
93 ms10396 KiB
import java.util.Arrays; public class plants { int n; int[] nxt; int[] r; void init(int k, int[] r) { n = r.length; nxt = new int[n]; this.r = r; // r[i] = (a[i] > a[(i + 1)%n] ? 1 : 0) // x -> find smallest z on circle clockwise s.t. r[z] != r[x]. // If y is between x and z (clockwise), than ans(x,y) = r[x]. // r[x] = r[x+1] = ... = r[s] = 1 => a[x] > a[x+1] > a[x+2] > ... > a[s + 1] // r[x] = r[x+1] = ... = r[s] = -1 => a[x] < a[x+1] < a[x+2] > ... < a[s + 1] // nxt[x] = smallest y s.t. nxt[y] != nxt[x]. for query z s.t. x < z <= nxt[x] + 1, comp(x,z) known. for (int i = 0; i < n; i++) { int j = i; boolean jump = false; while (r[(j + 1) % n] == r[i]) { j = (j + 1) % n; if (j == 0) jump = true; } // r[i] = r[i+1] = ... = r[j] != r[j + 1]. for (int x = i; x <= j; x++) { nxt[x] = j + 1; } if (jump) break; i = j; } //System.out.println(Arrays.toString(nxt)); } boolean between(int l, int r, int x) { if (l <= r) { return l <= x && x <= r; } return (r <= x && x <= n - 1) || (0 <= x && x <= l); } int compare_plants(int x, int y) { // r[x] > r[x+1] > ... > r[j]. if (between(x, nxt[x], y)) { return r[x] > 0 ? 1 : -1; } if (between(y, nxt[y], x)) { return r[y] > 0 ? -1 : 1; } return 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...