Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.io.BufferedReader;
- import java.awt.Point;
- public class sort{
- public static final String TASKNAME = "sort";
- public static long mod= 1000000007;
- public static Debug db;
- public static void main(String[] args) throws IOException {
- InputReader in = new InputReader(System.in);
- PrintWriter out = new PrintWriter(System.out);
- // InputReader in = new InputReader(new FileInputStream(TASKNAME+".in"));
- // PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(TASKNAME+".out")));
- Autocompletion solver = new Autocompletion();
- db=new Debug(System.getSecurityManager()==null);
- solver.solve(1, in, out);
- out.close();
- }
- static class Autocompletion {
- public void solve(int testNumber, InputReader in, PrintWriter out) {
- int n=in.nextInt();
- Pair[] arr=new Pair[n];
- for(int i=0;i<n;i++) {
- arr[i]=new Pair(in.nextInt(),i);
- }
- Arrays.sort(arr);
- int news[]=new int[n];
- for(int i=0;i<n;i++) {
- news[arr[i].y]=i;
- }
- // db.debug("news", news);
- bit bit=new bit(n);
- int ret=0;
- for(int i=0;i<n;i++) {
- bit.update(news[i], 1);
- ret=(int) Math.max(ret, i+1-bit.sum(i));
- }
- out.println(ret);
- }
- }
- static class bit {
- public int[] tree;
- public bit(int n) {
- tree = new int[n+5];
- }
- public void update(int index, int val) {
- index++;
- while(index < tree.length) {
- tree[index] += val;
- index += index & -index;
- }
- }
- public long sum(int i) {
- long ans = 0;
- while (i > 0) {
- ans += tree[i];
- i = i - (i & (-i));
- }
- return ans;
- }
- public long queryRange(int i, int j) {
- return sum(j) - sum(i - 1);
- }
- }
- static class Pair implements Comparable<Pair>{
- int x;
- int y;
- Pair(int a, int b){
- x=a;
- y=b;
- }
- @Override
- public int compareTo(Pair arg0) {
- if(arg0.x!=x)return x-arg0.x;
- return y-arg0.y;
- }
- }
- static class InputReader {
- public BufferedReader reader;
- public StringTokenizer tokenizer;
- public InputReader(InputStream stream) {
- reader = new BufferedReader(new InputStreamReader(stream), 32768);
- tokenizer = null;
- }
- public String next() {
- while (tokenizer == null || !tokenizer.hasMoreTokens()) {
- try {
- tokenizer = new StringTokenizer(reader.readLine());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- return tokenizer.nextToken();
- }
- public int nextInt() {
- return Integer.parseInt(next());
- }
- public long nextLong() {
- return Long.parseLong(next());
- }
- public int[] nextIntArr(int n) {
- int arr[]=new int[n];
- for(int i=0;i<n;i++) {
- arr[i]=this.nextInt();
- }
- return arr;
- }
- }
- public static class Debug {
- private boolean allowDebug;
- public Debug(boolean allowDebug) {
- this.allowDebug = allowDebug;
- }
- private void outputName(String name) {
- System.out.print(name + " = ");
- }
- public void debug(String name, int x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println("" + x);
- }
- public void debug(String name, long x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println("" + x);
- }
- public void debug(String name, double x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println("" + x);
- }
- public void debug(String name, int[] x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println(Arrays.toString(x));
- }
- public void debug(String name, long[] x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println(Arrays.toString(x));
- }
- public void debug(String name, double[] x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println(Arrays.toString(x));
- }
- public void debug(String name, Object x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println("" + x);
- }
- public void debug(String name, Object... x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println(Arrays.deepToString(x));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement