git reimport
This commit is contained in:
91
archive/2017.10/2017.10.16 - unsorted/D.java
Normal file
91
archive/2017.10/2017.10.16 - unsorted/D.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package chelper;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class D extends SimpleSavingChelperSolution {
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
wrapSolve(testNumber, in, out);
|
||||
}
|
||||
|
||||
class Node {
|
||||
int l, r, m;
|
||||
|
||||
int sum;
|
||||
|
||||
Node cl, cr;
|
||||
|
||||
Node(int l, int r) {
|
||||
this.l = l;
|
||||
this.r = r;
|
||||
|
||||
m = (l + r) / 2;
|
||||
sum = 0;
|
||||
|
||||
if (r - l > 1) {
|
||||
cl = new Node(l, m);
|
||||
cr = new Node(m, r);
|
||||
}
|
||||
}
|
||||
|
||||
void add(int x) {
|
||||
sum++;
|
||||
if (r - l > 1) {
|
||||
if (x < m) {
|
||||
cl.add(x);
|
||||
} else {
|
||||
cr.add(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int sum(int ll, int rr) {
|
||||
if (ll == l && rr == r) {
|
||||
return sum;
|
||||
}
|
||||
|
||||
int ans = 0;
|
||||
if (ll < m) {
|
||||
ans += cl.sum(ll, Math.min(m, rr));
|
||||
}
|
||||
if (rr > m) {
|
||||
ans += cr.sum(Math.max(m, ll), rr);
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
int n = in.nextInt();
|
||||
|
||||
out.print(1 + " ");
|
||||
|
||||
Node root = new Node(0, n);
|
||||
|
||||
for (int totalSum = 1; totalSum <= n; totalSum++) {
|
||||
root.add(in.nextInt() - 1);
|
||||
|
||||
|
||||
int l = 0;
|
||||
int r = n + 1;
|
||||
|
||||
while (r - l > 1) {
|
||||
int m = (l + r) / 2;
|
||||
int x = root.sum(n - m, n);
|
||||
if (x == m) {
|
||||
l = m;
|
||||
} else {
|
||||
r = m;
|
||||
}
|
||||
}
|
||||
|
||||
out.print((totalSum - l + 1) + " ");
|
||||
|
||||
// out.println(root.sum(0, n));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user