From bc32ca8045e9b78cb821db83d385466fb78740eb Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 25 Mar 2025 13:26:02 +0900 Subject: [PATCH] =?UTF-8?q?[20250325]=20BOJ=20/=20P2=20/=20=EB=B0=B1?= =?UTF-8?q?=EC=84=A4=EA=B3=B5=EC=A3=BC=EC=99=80=20=EB=82=9C=EC=9F=81?= =?UTF-8?q?=EC=9D=B4=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \353\202\234\354\237\201\354\235\264.md" | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 "khj20006/202503/25 BOJ P2 \353\260\261\354\204\244\352\263\265\354\243\274\354\231\200 \353\202\234\354\237\201\354\235\264.md" diff --git "a/khj20006/202503/25 BOJ P2 \353\260\261\354\204\244\352\263\265\354\243\274\354\231\200 \353\202\234\354\237\201\354\235\264.md" "b/khj20006/202503/25 BOJ P2 \353\260\261\354\204\244\352\263\265\354\243\274\354\231\200 \353\202\234\354\237\201\354\235\264.md" new file mode 100644 index 00000000..f0a5bc28 --- /dev/null +++ "b/khj20006/202503/25 BOJ P2 \353\260\261\354\204\244\352\263\265\354\243\274\354\231\200 \353\202\234\354\237\201\354\235\264.md" @@ -0,0 +1,98 @@ +```java + +import java.util.*; +import java.io.*; + +class Edge{ + int s, e; + double c; + Edge(int s, int e, double c){ + this.s = s; + this.e = e; + this.c = c; + } +} + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st = new StringTokenizer(""); + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static String nextToken() throws Exception { + while(!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static int N, C, M; + static int[] A; + static List[] Idx; + static Random rd = new Random(); + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + C = nextInt(); + A = new int[N+1]; + Idx = new List[C+1]; + for(int i=1;i<=C;i++) Idx[i] = new ArrayList<>(); + + for(int i=1;i<=N;i++) { + A[i] = nextInt(); + Idx[A[i]].add(i); + } + + } + + static void solve() throws Exception{ + + for(M=nextInt();M-->0;) { + int a = nextInt(), b = nextInt(); + + int res = -1; + for(int i=0;i<100;i++) { + int x = A[a + rd.nextInt(b-a+1)]; + + int cnt = lowerBound(x,b) - lowerBound(x,a-1); + if(cnt > (b-a+1)/2) { + res = x; + break; + } + + } + if(res == -1) bw.write("no\n"); + else bw.write("yes " + res + "\n"); + } + + } + + static int lowerBound(int k, int x) { + int s = 0, e = Idx[k].size(), m = (s+e)>>1; + while(s>1; + } + return m; + } + +} + +```