From 14e41be45f61e4151ccdfcdb6a21446d31dbc491 Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 19 Aug 2025 14:49:01 +0900 Subject: [PATCH] =?UTF-8?q?[20250819]=20BOJ=20/=20P1=20/=20=EC=88=98?= =?UTF-8?q?=EC=97=B4=EA=B3=BC=20=EC=BF=BC=EB=A6=AC=206=20/=20=EA=B6=8C?= =?UTF-8?q?=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...352\263\274 \354\277\274\353\246\254 6.md" | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 "khj20006/202508/19 BOJ P1 \354\210\230\354\227\264\352\263\274 \354\277\274\353\246\254 6.md" diff --git "a/khj20006/202508/19 BOJ P1 \354\210\230\354\227\264\352\263\274 \354\277\274\353\246\254 6.md" "b/khj20006/202508/19 BOJ P1 \354\210\230\354\227\264\352\263\274 \354\277\274\353\246\254 6.md" new file mode 100644 index 00000000..0323224f --- /dev/null +++ "b/khj20006/202508/19 BOJ P1 \354\210\230\354\227\264\352\263\274 \354\277\274\353\246\254 6.md" @@ -0,0 +1,161 @@ +```java +import java.awt.image.AreaAveragingScaleFilter; +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N, M; + static int sqrt; + static int[] a; + static int[][] queries; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + static void init() throws Exception { + + N = io.nextInt(); + a = new int[N]; + for(int i=0;i { + int s = a[0] / sqrt, e = b[0] / sqrt; + if(s == e) return a[1]-b[1]; + return s-e; + }); + + int[] cnt = new int[100001]; + int[] ccnt = new int[100001]; + ccnt[0] = 1; + int[] ans = new int[M]; + int s = queries[0][0], e = queries[0][1], max = 0; + for(int i=s;i<=e;i++) { + ccnt[cnt[a[i]]]--; + if(ccnt[max] == 0) max--; + ccnt[++cnt[a[i]]]++; + if(cnt[a[i]] > max) max = cnt[a[i]]; + } + ans[queries[0][2]] = max; + + for(int i=1;i e) { + for(int k=s;k<=e;k++) { + ccnt[cnt[a[k]]]--; + if(ccnt[max] == 0) max--; + ccnt[--cnt[a[k]]]++; + if(cnt[a[k]] > max) max = cnt[a[k]]; + } + s = ns; + e = ns; + ccnt[cnt[a[s]]]--; + if(ccnt[max] == 0) max--; + ccnt[++cnt[a[s]]]++; + if(cnt[a[s]] > max) max = cnt[a[s]]; + } + while(s < ns) { + ccnt[cnt[a[s]]]--; + if(ccnt[max] == 0) max--; + ccnt[--cnt[a[s]]]++; + if(cnt[a[s]] > max) max = cnt[a[s]]; + s++; + } + while(ns < s) { + s--; + ccnt[cnt[a[s]]]--; + if(ccnt[max] == 0) max--; + ccnt[++cnt[a[s]]]++; + if(cnt[a[s]] > max) max = cnt[a[s]]; + } + while(e < ne) { + e++; + ccnt[cnt[a[e]]]--; + if(ccnt[max] == 0) max--; + ccnt[++cnt[a[e]]]++; + if(cnt[a[e]] > max) max = cnt[a[e]]; + } + while(ne < e) { + ccnt[cnt[a[e]]]--; + if(ccnt[max] == 0) max--; + ccnt[--cnt[a[e]]]++; + if(cnt[a[e]] > max) max = cnt[a[e]]; + e--; + } + ans[idx] = max; + s = ns; + e = ne; + } + + for(int v:ans) io.write(v + "\n"); + + } + +} +```