結果

問題 No.905 Sorted?
ユーザー k_6101
提出日時 2019-12-05 17:53:37
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,206 ms / 2,000 ms
コード長 1,869 bytes
コンパイル時間 2,988 ms
コンパイル使用メモリ 78,820 KB
実行使用メモリ 67,044 KB
最終ジャッジ日時 2024-12-21 11:59:27
合計ジャッジ時間 17,629 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==================================================================
    public void solve() {
    	int N = Integer.parseInt(sc.next());
    	long a, sv;
    	int[] up = new int[N];
    	int[] down = new int[N];
    	sv = Long.parseLong(sc.next());
    	for (int i = 1; i < N; i++) {
			a = Long.parseLong(sc.next());
			if(sv < a)			up[i] = 1;
			else if(sv > a)		down[i] = 1;
			sv = a;
		}
    	for (int i = 1; i < N; i++) {
			up[i] += up[i-1];
			down[i] += down[i-1];
		}
    	int Q = Integer.parseInt(sc.next());
    	int l, r, uCnt, dCnt;
    	for (int i = 0; i < Q; i++) {
        	l = Integer.parseInt(sc.next());
        	r = Integer.parseInt(sc.next());
			uCnt = up[r] - up[l];
			dCnt = down[r] - down[l];
			if(uCnt == 0 && dCnt == 0)		out.println("1 1");
			else if(uCnt > 0 && dCnt == 0)	out.println("1 0");
			else if(uCnt == 0 && dCnt > 0)	out.println("0 1");
			else							out.println("0 0");
		}
    }
    // ==================================================================
}
class PP{
	public int key, val;
	public PP(int key, int val) {
		this.key = key;
		this.val = val;
	}
	public int getKey() {
		return key;
	}
	public int getVal() {
		return val;
	}
}
0