exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
listlengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
difficulty
int64
-1
3.5k
prob_desc_output_spec
stringlengths
17
1.47k
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
c224cf72d8095e3af1d74aac88029ec1
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class Main { static FastScanner fs = new FastScanner(); static PrintWriter pw = new PrintWriter(System.out); static StringBuilder sb = new StringBuilder(""); public static void main(String[] args) { int t = fs.nextInt(); for (int tt = 0; tt < t; tt++) { int n = fs.nextInt(); P[] a = new P[n+1]; P[] b = new P[n+1]; for (int i = 0; i < n+1; i++) { a[i] = new P(0, 0); b[i] = new P(0, 0); } int[] c = new int[n+1]; int[] d = new int[n+1]; for (int i = 1; i <= n; i++) { a[i].fi = fs.nextInt(); a[i].se = i; } for (int i = 1; i <= n; i++) { b[i].fi = fs.nextInt(); b[i].se = i; } Arrays.sort(a); Arrays.sort(b); for (int i = 1; i <= n; i++) c[b[i].se] = i; int min = n + 1; // System.out.println(); // for(int i=0;i<=n;i++){ // System.out.print(c[i]+" "); // } // System.out.println(); for (int i = n; i >= 1; i--) { min = Math.min(min, c[a[i].se]); d[a[i].se] = 1; if (min == i) { for (int j = 1; j <= n; j++) sb.append(d[j]); sb.append("\n"); break; } } } pw.print(sb.toString()); pw.close(); } static class P implements Comparable<P> { int fi, se; public P(int fi, int se) { this.fi = fi; this.se = se; } public int compareTo(P o) { return Integer.compare(fi, o.fi); } } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() {while (!st.hasMoreTokens())try {st = new StringTokenizer(br.readLine());} catch (IOException e) {}return st.nextToken();} int nextInt() {return Integer.parseInt(next());} long nextLong() {return Long.parseLong(next());} double nextDouble() {return Double.parseDouble(next());} int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) {a[i] = nextInt();} return a;} } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
6ef529d9cc112869cb93e7600678286c
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
// package c1608; import java.io.File; import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.PriorityQueue; import java.util.Random; import java.util.Scanner; // // Codeforces Round 2021-12-11 02:05 // C. Game Master // https://codeforces.com/contest/1608/problem/C // time limit per test 1 second; memory limit per test 256 megabytes // public class Pseudo for 'Source should satisfy regex [^{}]*public\s+(final)?\s*class\s+(\w+).*' // // n players are playing a game. // // There are two different maps in the game. For each player, we know his strength on each map. When // two players fight on a specific map, the player with higher strength on that map always wins. No // two players have the same strength on the same map. // // You are the game master and want to organize a tournament. There will be a total of n-1 battles. // While there is more than one player in the tournament, choose any map and any two remaining // players to fight on it. The player who loses will be eliminated from the tournament. // // In the end, exactly one player will remain, and he is declared the winner of the tournament. For // each player determine if he can win the tournament. // // Input // // The first line contains a single integer t (1 <= t <= 100) -- the number of test cases. The // description of test cases follows. // // The first line of each test case contains a single integer n (1 <=q n <=q 10^5) -- the number of // players. // // The second line of each test case contains n integers a_1, a_2, ..., a_n (1 <=q a_i <=q 10^9, a_i // \neq a_j for i \neq j), where a_i is the strength of the i-th player on the first map. // // The third line of each test case contains n integers b_1, b_2, ..., b_n (1 <=q b_i <=q 10^9, b_i // \neq b_j for i \neq j), where b_i is the strength of the i-th player on the second map. // // It is guaranteed that the sum of n over all test cases does not exceed 10^5. // // Output // // For each test case print a string of length n. i-th character should be "" if the i-th player can // win the tournament, or "" otherwise. // // Example /* input: 3 4 1 2 3 4 1 2 3 4 4 11 12 20 21 44 22 11 30 1 1000000000 1000000000 output: 0001 1111 1 */ // Note // // In the first test case, the 4-th player will beat any other player on any game, so he will // definitely win the tournament. // // In the second test case, everyone can be a winner. // // In the third test case, there is only one player. Clearly, he will win the tournament. // public class C1608C { static final int MOD = (int)1e9+7; static final Random RAND = new Random(); static class TestCase { int n; // Both id and rank are in the range [0,n-1). Rank n-1 has the highest strength. // ra[i] is the rank of id i in a int[] ra; int[] rb; // ia[i] is the id of rank i in map a (reverse lookup of ra) int[] ia; int[] ib; TestCase(int[] a, int[] b) { init(a, b); } void init(int[] a, int[] b) { this.n = a.length; this.ra = getRankArray(a); this.rb = getRankArray(b); this.ia = new int[n]; this.ib = new int[n]; for (int i = 0; i < n; i++) { ia[ra[i]] = i; ib[rb[i]] = i; } } static void handle(int[] ia, int[] ib, int[] ra, int[] rb, boolean[] oks) { // Consider players in increasing order of rank in map a. // // In below, A eliminates C in mapb, B eliminates A in map A // A B C // map a: * * * // \ / / // X / // / \ / // / X // / / \ // map b: * o * * // // We like to find the minimal rank in map b of the final survivor across all // superior players in map a. // int n = ia.length; int max = 0; PriorityQueue<Integer> pq = new PriorityQueue<>((x,y)->rb[y] - rb[x]); int[] suf = new int[n]; suf[n-1] = rb[ia[n-1]]; pq.add(ia[n-1]); for (int r = n - 2; r >= 0; r--) { int id = ia[r]; int x = rb[id]; if (x < rb[pq.peek()]) { pq.add(id); } else { while (pq.size() > 1 && x > rb[pq.peek()]) { pq.poll(); } } suf[r] = rb[pq.peek()]; } for (int r = 0; r < n; r++) { int id = ia[r]; max = Math.max(max, rb[id]); // System.out.format(" r:%d id:%d suf:%d\n", r, id, suf[r]); if (max >= suf[r]) { oks[id] = true; } } } String solve() { boolean[] oks = new boolean[n]; handle(ia, ib, ra, rb, oks); handle(ib, ia, rb, ra, oks); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(oks[i] ? 1 : 0); } return sb.toString(); } // Gets rank array where rank[i] is the rank (0-based) of a[i] in a static int[] getRankArray(int[] a) { int n = a.length; int[][] x = new int[n][2]; for (int i = 0; i < n; i++) { x[i][0] = a[i]; x[i][1] = i; } Arrays.sort(x, (v, w)->Integer.compare(v[0], w[0])); int[] ra = new int[n]; for (int i = 0; i < n; i++) { ra[x[i][1]] = i; } return ra; } } static void doTest() { int n = 10; List<Integer> arr = new ArrayList<>(); for (int i = 0; i < n; i++) { arr.add(i); } Collections.shuffle(arr); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = arr.get(i); } Collections.shuffle(arr); int[] b = new int[n]; for (int i = 0; i < n; i++) { b[i] = arr.get(i); } System.out.format(" a:%s\n", Arrays.toString(a)); System.out.format(" b:%s\n", Arrays.toString(b)); TestCase tc = new TestCase(a,b); String ans = tc.solve(); System.out.println(ans); System.exit(0); } public static void main(String[] args) { // doTest(); Scanner in = getInputScanner(); int T = in.nextInt(); for (int t = 1; t <= T; t++) { int n = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } int[] b = new int[n]; for (int i = 0; i < n; i++) { b[i] = in.nextInt(); } TestCase tc = new TestCase(a,b); String ans = tc.solve(); System.out.println(ans); } in.close(); } static Scanner getInputScanner() { try { final String USERDIR = System.getProperty("user.dir"); final String CNAME = MethodHandles.lookup().lookupClass().getSimpleName(); final File fin = new File(USERDIR + "/io/c" + CNAME.substring(1,5) + "/" + CNAME + ".in"); return fin.exists() ? new Scanner(fin) : new Scanner(System.in); } catch (Exception e) { return new Scanner(System.in); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
2dd40488f69cabd482587044c817b4af
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class gotoJapan { public static void main(String[] args) throws java.lang.Exception { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solution solver = new Solution(); boolean isTest = true; int tC = isTest ? Integer.parseInt(in.next()) : 1; for (int i = 1; i <= tC; i++) solver.solve(in, out, i); out.close(); } /* ............................................................. */ static class Solution { InputReader in; PrintWriter out; public void solve(InputReader in, PrintWriter out, int test) { this.in = in; this.out = out; int n=ni(); Pair a[]=new Pair[n]; Pair b[]=new Pair[n]; int x[]=new int[n]; int y[]=new int[n]; int ans[]=new int[n]; for(int i=0;i<n;i++) { a[i]=new Pair(ni(),i); } for(int i=0;i<n;i++) { b[i]=new Pair(ni(),i); } Arrays.sort(a,new Comparator<Pair>() { public int compare(Pair p1,Pair p2) { return p2.x-p1.x; } }); Arrays.sort(b,new Comparator<Pair>() { public int compare(Pair p1,Pair p2) { return p2.x-p1.x; } }); for(int i=0;i<n;i++) { x[a[i].y]=i; y[b[i].y]=i; } Queue<Integer> que=new LinkedList<>(); que.add(a[0].y); que.add(b[0].y); //ans[a[0].y]=1; //ans[b[0].y]=1; boolean va[]=new boolean[n]; boolean vb[]=new boolean[n]; while(!que.isEmpty()) { int pl=que.poll(); ans[pl]=1; for(int i=x[pl]-1;i>=0;i--) { if(va[i])break; que.add(a[i].y); va[i]=true; } for(int i=y[pl]-1;i>=0;i--) { if(vb[i])break; que.add(b[i].y); vb[i]=true; } } for(int i=0;i<n;i++)out.print(ans[i]); out.println(); } class Pair { int x; int y; Pair(int x, int y) { this.x = x; this.y = y; } } char[] n() { return in.next().toCharArray(); } int ni() { return in.nextInt(); } long nl() { return in.nextLong(); } long[] nal(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) a[i] = nl(); return a; } void pn(long zx) { out.println(zx); } void pn(String sz) { out.println(sz); } void pn(double dx) { out.println(dx); } void pn(long ar[]) { for (int i = 0; i < ar.length; i++) out.print(ar[i] + " "); out.println(); } void pn(String ar[]) { for (int i = 0; i < ar.length; i++) out.println(ar[i]); } } /* ......................Just Input............................. */ 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()); } } /* ......................Just Input............................. */ }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
4a021d78d28c84af2077f79a8b4e9140
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); CGameMaster solver = new CGameMaster(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class CGameMaster { boolean[] vis; int[][] g; int n; int m; int[] from; int[] to; public void solve(int testNumber, InputReader in, OutputWriter out) { n = in.nextInt(); int[] a = in.nextIntArray(n), b = in.nextIntArray(n); int[][] arr = new int[n][3]; for (int i = 0; i < n; i++) { arr[i][0] = a[i]; arr[i][1] = b[i]; arr[i][2] = i; } Arrays.sort(arr, (x, y) -> { return x[0] - y[0]; }); m = 2 * n - 2; from = new int[m]; to = new int[m]; int maxid = arr[n - 1][2]; for (int i = 0; i < n - 1; i++) { from[i] = arr[i][2]; to[i] = arr[i + 1][2]; } Arrays.sort(arr, (x, y) -> { return x[1] - y[1]; }); for (int i = n - 1; i < m; i++) { from[i] = arr[i - n + 1][2]; to[i] = arr[i - n + 2][2]; } g = makeGraph(in); vis = new boolean[n]; dfs(maxid); for (int i = 0; i < n; i++) { if (vis[i]) out.print(1); else out.print(0); } out.println(); } void dfs(int nn) { vis[nn] = true; for (int a : g[nn]) { if (vis[a]) continue; dfs(a); } } int[][] makeGraph(InputReader in) { return makeGraph(n, m); } int[][] makeGraph(int N, int M) { int[][] G = new int[N][]; int[] p = new int[N]; for (int i = 0; i < M; i++) { p[from[i]]++; } for (int i = 0; i < N; i++) G[i] = new int[p[i]]; for (int i = 0; i < M; i++) { G[from[i]][--p[from[i]]] = to[i]; } return G; } } static class InputReader { BufferedReader reader; 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[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; ++i) array[i] = nextInt(); return array; } public int nextInt() { return Integer.parseInt(next()); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void println() { writer.println(); } public void close() { writer.close(); } public void print(int i) { writer.print(i); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
fa0c3de732b0669092d8d0861c2900bf
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { ArrayList<Integer>[] graph; HashSet<Integer> set; void solve() { int n = in.nextInt(); int[] a = array(n, 1); int[] b = array(n, 1); Integer[] indexA = sort(a); Integer[] indexB = sort(b); graph = new ArrayList[n]; for (int i = 0; i < n; i++)graph[i] = new ArrayList<>(); for (int i = 0; i < n - 1; i++) { graph[indexA[i]].add(indexA[i + 1]); graph[indexB[i]].add(indexB[i + 1]); } set = new HashSet<>(); dfs(indexA[n - 1]); dfs(indexB[n - 1]); int[] res = new int[n]; for (Integer i : set)res[i] = 1; for (int i = 0 ; i < n; i++) { out.append(res[i]); } out.append(endl); } void dfs(int node ) { if (set.contains(node))return; set.add(node); for (Integer child : graph[node]) { dfs(child); } } Integer[] sort(int[] a) { int n = a.length; Integer[] index = new Integer[n]; for (int i = 0; i < n; i++)index[i] = i; Arrays.sort(index, new Comparator<Integer>() { public int compare(Integer i, Integer j) { return a[i] - a[j]; } }); return index; } public static void main (String[] args) { // It happens - Syed Mizbahuddin Main sol = new Main(); int t = 1; t = in.nextInt(); while (t-- != 0) { sol.solve(); } System.out.print(out); } <T> void println(T[] s) { if (err == null)return; err.println(Arrays.toString(s)); } <T> void println(T s) { if (err == null)return; err.println(s); } void println(int s) { if (err == null)return; err.println(s); } void println(int[] a) { if (err == null)return; println(Arrays.toString(a)); } void println(long[] a) { if (err == null)return; println(Arrays.toString(a)); } int[] array(int n, int x) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } return a; } long[] array(int n, long x) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = in.nextLong(); } return a; } int[] array1(int n) { int[] a = new int[n + 1]; for (int i = 1; i <= n; i++) { a[i] = in.nextInt(); } return a; } int max(int[] a) { int max = a[0]; for (int i = 0; i < a.length; i++)max = Math.max(max, a[i]); return max; } int min(int[] a) { int min = a[0]; for (int i = 0; i < a.length; i++)min = Math.min(min, a[i]); return min; } int count(int[] a, int x) { int count = 0; for (int i = 0; i < a.length; i++)if (x == a[i])count++; return count; } void printArray(int[] a) { for (int ele : a)out.append(ele + " "); out.append("\n"); } void printArray(long[] a) { for (long ele : a)out.append(ele + " "); out.append("\n"); } static { try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); err = new PrintStream(new FileOutputStream("error.txt")); } catch (Exception e) {} } static FastReader in; static StringBuilder out; static PrintStream err; static String yes , no , endl; final int MAX; final int MIN; int mod ; Main() { in = new FastReader(); out = new StringBuilder(); MAX = Integer.MAX_VALUE; MIN = Integer.MIN_VALUE; mod = (int)1e9 + 7; yes = "YES\n"; no = "NO\n"; endl = "\n"; } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } class Pair implements Comparable<Pair> { int first , second; Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair b) { return this.first - b.first; } public String toString() { String s = "{ " + Integer.toString(first) + " , " + Integer.toString(second) + " }"; return s; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
38e1f6d3a48b8b4b576de850a45e7ead
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; import java.sql.Array; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLIntegrityConstraintViolationException; public class Main { private static class MyScanner { private static final int BUF_SIZE = 2048; BufferedReader br; private MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } private boolean isSpace(char c) { return c == '\n' || c == '\r' || c == ' '; } String next() { try { StringBuilder sb = new StringBuilder(); int r; while ((r = br.read()) != -1 && isSpace((char)r)); if (r == -1) { return null; } sb.append((char) r); while ((r = br.read()) != -1 && !isSpace((char)r)) { sb.append((char)r); } return sb.toString(); } catch (IOException e) { e.printStackTrace(); } return null; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } static class Reader{ BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static long mod = (long)(1e9 + 7); static void sort(long[] arr ) { ArrayList<Long> al = new ArrayList<>(); for(long e:arr) al.add(e); Collections.sort(al); for(int i = 0 ; i<al.size(); i++) arr[i] = al.get(i); } static void sort(int[] arr ) { ArrayList<Integer> al = new ArrayList<>(); for(int e:arr) al.add(e); Collections.sort(al); for(int i = 0 ; i<al.size(); i++) arr[i] = al.get(i); } static void sort(char[] arr) { ArrayList<Character> al = new ArrayList<Character>(); for(char cc:arr) al.add(cc); Collections.sort(al); for(int i = 0 ;i<arr.length ;i++) arr[i] = al.get(i); } static long mod_mul( long... a) { long ans = a[0]%mod; for(int i = 1 ; i<a.length ; i++) { ans = (ans * (a[i]%mod))%mod; } return ans; } static long mod_sum( long... a) { long ans = 0; for(long e:a) { ans = (ans + e)%mod; } return ans; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static boolean[] prime(int num) { boolean[] bool = new boolean[num]; for (int i = 0; i< bool.length; i++) { bool[i] = true; } for (int i = 2; i< Math.sqrt(num); i++) { if(bool[i] == true) { for(int j = (i*i); j<num; j = j+i) { bool[j] = false; } } } if(num >= 0) { bool[0] = false; bool[1] = false; } return bool; } static long modInverse(long a, long m) { long g = gcd(a, m); return power(a, m - 2, m); } static long lcm(long a , long b) { return (a*b)/gcd(a, b); } static int lcm(int a , int b) { return (int)((a*b)/gcd(a, b)); } static long power(long x, long y, long m){ if (y == 0) return 1; long p = power(x, y / 2, m) % m; p = (int)((p * (long)p) % m); if (y % 2 == 0) return p; else return (int)((x * (long)p) % m); } static class Combinations{ private long[] z; private long[] z1; private long[] z2; private long mod; public Combinations(long N , long mod) { this.mod = mod; z = new long[(int)N+1]; z1 = new long[(int)N+1]; z[0] = 1; for(int i =1 ; i<=N ; i++) z[i] = (z[i-1]*i)%mod; z2 = new long[(int)N+1]; z2[0] = z2[1] = 1; for (int i = 2; i <= N; i++) z2[i] = z2[(int)(mod % i)] * (mod - mod / i) % mod; z1[0] = z1[1] = 1; for (int i = 2; i <= N; i++) z1[i] = (z2[i] * z1[i - 1]) % mod; } long fac(long n) { return z[(int)n]; } long invrsNum(long n) { return z2[(int)n]; } long invrsFac(long n) { return invrsFac((int)n); } long ncr(long N, long R) { if(R<0 || R>N ) return 0; long ans = ((z[(int)N] * z1[(int)R]) % mod * z1[(int)(N - R)]) % mod; return ans; } } static class DisjointUnionSets { int[] rank, parent; int n; public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } void makeSet() { for (int i = 0; i < n; i++) { parent[i] = i; } } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } void union(int x, int y) { int xRoot = find(x), yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } } } static int max(int... a ) { int max = a[0]; for(int e:a) max = Math.max(max, e); return max; } static long max(long... a ) { long max = a[0]; for(long e:a) max = Math.max(max, e); return max; } static int min(int... a ) { int min = a[0]; for(int e:a) min = Math.min(e, min); return min; } static long min(long... a ) { long min = a[0]; for(long e:a) min = Math.min(e, min); return min; } static int[] KMP(String str) { int n = str.length(); int[] kmp = new int[n]; for(int i = 1 ; i<n ; i++) { int j = kmp[i-1]; while(j>0 && str.charAt(i) != str.charAt(j)) { j = kmp[j-1]; } if(str.charAt(i) == str.charAt(j)) j++; kmp[i] = j; } return kmp; } /************************************************ Query **************************************************************************************/ /***************************************** Sparse Table ********************************************************/ static class SparseTable{ private long[][] st; SparseTable(long[] arr){ int n = arr.length; st = new long[n][25]; log = new int[n+2]; build_log(n+1); build(arr); } private void build(long[] arr) { int n = arr.length; for(int i = n-1 ; i>=0 ; i--) { for(int j = 0 ; j<25 ; j++) { int r = i + (1<<j)-1; if(r>=n) break; if(j == 0 ) st[i][j] = arr[i]; else st[i][j] = Math.min(st[i][j-1] , st[ i + ( 1 << (j-1) ) ][ j-1 ] ); } } } public long gcd(long a ,long b) { if(a == 0) return b; return gcd(b%a , a); } public long query(int l ,int r) { int w = r-l+1; int power = log[w]; return Math.min(st[l][power],st[r - (1<<power) + 1][power]); } private int[] log; void build_log(int n) { log[1] = 0; for(int i = 2 ; i<=n ; i++) { log[i] = 1 + log[i/2]; } } } /******************************************************** Segement Tree *****************************************************/ /** static class SegmentTree{ long[] tree; long[] arr; int n; SegmentTree(long[] arr){ this.n = arr.length; tree = new long[4*n+1]; this.arr = arr; buildTree(0, n-1, 1); } void buildTree(int s ,int e ,int index ) { if(s == e) { tree[index] = arr[s]; return; } int mid = (s+e)/2; buildTree( s, mid, 2*index); buildTree( mid+1, e, 2*index+1); tree[index] = Math.min(tree[2*index] , tree[2*index+1]); } long query(int si ,int ei) { return query(0 ,n-1 , si ,ei , 1 ); } private long query( int ss ,int se ,int qs , int qe,int index) { if(ss>=qs && se<=qe) return tree[index]; if(qe<ss || se<qs) return (long)(1e17); int mid = (ss + se)/2; long left = query( ss , mid , qs ,qe , 2*index); long right= query(mid + 1 , se , qs ,qe , 2*index+1); return Math.min(left, right); } public void update(int index , int val) { arr[index] = val; for(long e:arr) System.out.print(e+" "); update(index , 0 , n-1 , 1); } private void update(int id ,int si , int ei , int index) { if(id < si || id>ei) return; if(si == ei ) { tree[index] = arr[id]; return; } if(si > ei) return; int mid = (ei + si)/2; update( id, si, mid , 2*index); update( id , mid+1, ei , 2*index+1); tree[index] = Math.min(tree[2*index] ,tree[2*index+1]); } } */ /* ***************************************************************************************************************************************************/ // static MyScanner sc = new MyScanner(); // only in case of less memory static Reader sc = new Reader(); static StringBuilder sb = new StringBuilder(); public static void main(String args[]) throws IOException { int tc = 1; tc = sc.nextInt(); for(int i = 1 ; i<=tc ; i++) { // sb.append("Case #" + i + ": " ); // During KickStart && HackerCup TEST_CASE(); } System.out.print(sb); } static void TEST_CASE() { int n = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for(int i =0 ; i<n ; i++) a[i] = sc.nextInt(); for(int i =0 ; i<n ; i++) b[i] = sc.nextInt(); ArrayList<Pair> al1 = new ArrayList<>() , al2 = new ArrayList<>(); for(int i =0 ; i<n ; i++) { al1.add(new Pair(a[i], i)); al2.add(new Pair(b[i], i)); } Collections.sort(al1); Collections.sort(al2); // System.out.println(al1); // System.out.println(al2); int[] min1 = new int[n]; int[] min2 = new int[n]; min1[0] = b[al1.get(0).ind]; min2[0] = a[al2.get(0).ind]; for(int i = 1 ; i<n ; i++) { min1[i] = min(min1[i-1] , b[al1.get(i).ind]); min2[i] = min(min2[i-1] , a[al2.get(i).ind]); } // for(int e:min1) System.out.print(e+" "); // System.out.println(); // for(int e:min2) System.out.print(e+" "); // System.out.println(); int[] ans1 = fnc(al1, al2, min1, min2); int[] ans2 = fnc(al2 ,al1, min2, min1); for(int i =0 ; i<n ; i++) { sb.append((ans1[i]|ans2[i])); } sb.append("\n"); } static class Pair implements Comparable<Pair>{ int pow; int ind; Pair(int pow , int ind){ this.pow = pow; this.ind = ind; } @Override public int compareTo(Main.Pair o) { return Integer.compare(o.pow, this.pow); } public String toString() { return "{" + this.pow +"," + this.ind +"}"; } } static int[] fnc(ArrayList<Pair> a1 , ArrayList<Pair> a2,int[] min1 ,int[] min2) { int n = a1.size(); int[] ans = new int[n]; boolean[] visit1 = new boolean[n]; boolean[] visit2 = new boolean[n]; boolean arr1 = true; int i = 0; while(true) { if(arr1) { if(visit1[i]) break; visit1[i] = true; int min = min1[i]; int l = 0, r = n-1; while(l<=r) { int m = (l+r)/2; if(a2.get(m).pow < min) r = m-1; else l = m+1; } if(r == -1) break; i = r; }else { if(visit2[i]) break; visit2[i] = true; int min = min2[i]; int l = 0 , r = n-1; while(l<=r) { int m = (l+r)/2; if(a1.get(m).pow < min) r = m-1; else l = m+1; } if(r == -1) break; i = r; } arr1 = !arr1; } for( i = n-1 ; i>=0 ; i--) { if(visit1[i] ) { while(i>=0) { ans[a1.get(i).ind] |= 1; i--; } break; } } for( i = n-1 ; i>=0 ; i--) { if(visit2[i] ) { while(i>=0) { ans[a1.get(i).ind] |= 1; i--; } break; } } return ans; } } /*******************************************************************************************************************************************************/ /** */
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
07eda208887efdcf568cc771e0aea33b
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class CodeForces{ /*-------------------------------------------EDITING CODE STARTS HERE-------------------------------------------*/ public static void main(String[] args) throws IOException{ openIO(); int testCase = 1; testCase = sc.nextInt(); for (int i = 1; i <= testCase; i++) solve(i); closeIO(); } public static void solve(int tCase)throws IOException { int n= sc.nextInt(); int[][] arr = new int[n][3]; adj = new ArrayList[n]; for(int i=0;i<n;i++){ arr[i][0] = sc.nextInt(); arr[i][2] = i; adj[i] = new ArrayList<>(); } for(int i = 0 ;i<n;i++){ arr[i][1] = sc.nextInt(); } win = new boolean[n]; Arrays.sort(arr,(a,b)->(a[0]-b[0])); for(int i=1;i<n;i++)adj[arr[i-1][2]].add(arr[i][2]); int s1 = arr[n-1][2]; Arrays.sort(arr,(a,b)->(a[1] - b[1])); for(int i=1;i<n;i++)adj[arr[i-1][2]].add(arr[i][2]); int s2 = arr[n-1][2]; dfs(s1); dfs(s2); for(int i=0;i<n;i++)out.print(win[i]?'1':'0'); out.println(); } static ArrayList<Integer>[] adj; static boolean[] win; private static void dfs(int curr){ win[curr] = true; for(int neig : adj[curr]){ if(!win[neig])dfs(neig); } } /*-------------------------------------------EDITING CODE ENDS HERE-------------------------------------------*/ static FastestReader sc; static PrintWriter out; private static void openIO() throws IOException{ sc = new FastestReader(); out = new PrintWriter(System.out); } /*------------------------------------------HELPER FUNCTION STARTS HERE------------------------------------------*/ public static int mod = (int) 1e9 + 7; private static int mod2 = 998244353; public static int inf_int = (int) 2e9 + 10; public static long inf_long = (long) 2e15; public static int _digitCount(long num,int base){ return (int)(1 + Math.log(num)/Math.log(base)); } public static long _fact(int n){ long ans = 1; for(int i=2;i<=n;i++) ans = ans * i % mod; return ans; } // time : O(r) public static int _ncr(int n,int r){ if (r > n) return 0; long[] inv = new long[r + 1]; inv[0] = 1; if(r+1>=2) inv[1] = 1; // Getting the modular inversion // for all the numbers // from 2 to r with respect to mod for (int i = 2; i <= r; i++) inv[i] = mod - (mod / i) * inv[(mod % i)] % mod; int ans = 1; // for 1/(r!) part for (int i = 2; i <= r; i++) ans = (int) (((ans % mod) * (inv[i] % mod)) % mod); // for (n)*(n-1)*(n-2)*...*(n-r+1) part for (int i = n; i >= (n - r + 1); i--) ans = (((ans % mod) * (i % mod)) % mod); return ans; } // euclidean algorithm time O(max (loga ,logb)) public static long _gcd(long a, long b) { if (a == 0) return b; return _gcd(b % a, a); } public static long _lcm(long a, long b) { // lcm(a,b) * gcd(a,b) = a * b return (a / _gcd(a, b)) * b; } // binary exponentiation time O(logn) public static long _power(long x, long n) { long ans = 1; while (n > 0) { if ((n & 1) == 1) { ans *= x; ans %= mod; n--; } else { x *= x; x %= mod; n >>= 1; } } return ans; } //sieve/first divisor time : O(mx * log ( log (mx) ) ) public static int[] _seive(int mx){ int[] firstDivisor = new int[mx+1]; for(int i=0;i<=mx;i++)firstDivisor[i] = i; for(int i=2;i*i<=mx;i++) if(firstDivisor[i] == i) for(int j = i*i;j<=mx;j+=i) firstDivisor[j] = i; return firstDivisor; } private static boolean _isPrime(long x){ for(long i=2;i*i<=x;i++) if(x%i==0)return false; return true; } public static void _sort(int[] arr,boolean isAscending){ int n = arr.length; List<Integer> list = new ArrayList<>(); for(int ele : arr)list.add(ele); Collections.sort(list); if(!isAscending)Collections.reverse(list); for(int i=0;i<n;i++)arr[i] = list.get(i); } public static void _sort(long[] arr,boolean isAscending){ int n = arr.length; List<Long> list = new ArrayList<>(); for(long ele : arr)list.add(ele); Collections.sort(list); if(!isAscending)Collections.reverse(list); for(int i=0;i<n;i++)arr[i] = list.get(i); } /*------------------------------------------HELPER FUNCTION ENDS HERE-------------------------------------------*/ /*-------------------------------------------FAST INPUT STARTS HERE---------------------------------------------*/ public static void closeIO() throws IOException{ out.flush(); out.close(); sc.close(); } private static final class FastestReader { private static final int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; public FastestReader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public FastestReader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() throws IOException { int b; //noinspection StatementWithEmptyBody while ((b = read()) != -1 && isSpaceChar(b)) {} return b; } public String next() throws IOException { int b = skip(); final StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = read(); } return sb.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } public void close() throws IOException { din.close(); } } /*---------------------------------------------FAST INPUT ENDS HERE ---------------------------------------------*/ }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
32af8a1087201572f78ec9304b891a7b
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class CodeForces{ /*-------------------------------------------EDITING CODE STARTS HERE-------------------------------------------*/ public static void main(String[] args) throws IOException{ openIO(); int testCase = 1; testCase = sc.nextInt(); for (int i = 1; i <= testCase; i++) solve(i); closeIO(); } public static void solve(int tCase)throws IOException { int n= sc.nextInt(); int[][] arr = new int[n][3]; adj = new ArrayList[n]; for(int i=0;i<n;i++){ arr[i][0] = sc.nextInt(); arr[i][2] = i; adj[i] = new ArrayList<>(); } for(int i = 0 ;i<n;i++){ arr[i][1] = sc.nextInt(); } win = new boolean[n]; Arrays.sort(arr,(a,b)->(a[0]-b[0])); for(int i=1;i<n;i++)adj[arr[i-1][2]].add(arr[i][2]); int s1 = arr[n-1][2]; Arrays.sort(arr,(a,b)->(a[1] - b[1])); for(int i=1;i<n;i++)adj[arr[i-1][2]].add(arr[i][2]); dfs(arr[n-1][2]); dfs(s1); for(int i=0;i<n;i++)out.print(win[i]?'1':'0'); out.println(); } static ArrayList<Integer>[] adj; static boolean[] win; private static void dfs(int curr){ if(win[curr])return; win[curr] = true; for(int neig : adj[curr]){ dfs(neig); } } /*-------------------------------------------EDITING CODE ENDS HERE-------------------------------------------*/ static FastestReader sc; static PrintWriter out; private static void openIO() throws IOException{ sc = new FastestReader(); out = new PrintWriter(System.out); } /*------------------------------------------HELPER FUNCTION STARTS HERE------------------------------------------*/ public static int mod = (int) 1e9 + 7; private static int mod2 = 998244353; public static int inf_int = (int) 2e9 + 10; public static long inf_long = (long) 2e15; public static int _digitCount(long num,int base){ return (int)(1 + Math.log(num)/Math.log(base)); } public static long _fact(int n){ long ans = 1; for(int i=2;i<=n;i++) ans = ans * i % mod; return ans; } // time : O(r) public static int _ncr(int n,int r){ if (r > n) return 0; long[] inv = new long[r + 1]; inv[0] = 1; if(r+1>=2) inv[1] = 1; // Getting the modular inversion // for all the numbers // from 2 to r with respect to mod for (int i = 2; i <= r; i++) inv[i] = mod - (mod / i) * inv[(mod % i)] % mod; int ans = 1; // for 1/(r!) part for (int i = 2; i <= r; i++) ans = (int) (((ans % mod) * (inv[i] % mod)) % mod); // for (n)*(n-1)*(n-2)*...*(n-r+1) part for (int i = n; i >= (n - r + 1); i--) ans = (((ans % mod) * (i % mod)) % mod); return ans; } // euclidean algorithm time O(max (loga ,logb)) public static long _gcd(long a, long b) { if (a == 0) return b; return _gcd(b % a, a); } public static long _lcm(long a, long b) { // lcm(a,b) * gcd(a,b) = a * b return (a / _gcd(a, b)) * b; } // binary exponentiation time O(logn) public static long _power(long x, long n) { long ans = 1; while (n > 0) { if ((n & 1) == 1) { ans *= x; ans %= mod; n--; } else { x *= x; x %= mod; n >>= 1; } } return ans; } //sieve/first divisor time : O(mx * log ( log (mx) ) ) public static int[] _seive(int mx){ int[] firstDivisor = new int[mx+1]; for(int i=0;i<=mx;i++)firstDivisor[i] = i; for(int i=2;i*i<=mx;i++) if(firstDivisor[i] == i) for(int j = i*i;j<=mx;j+=i) firstDivisor[j] = i; return firstDivisor; } private static boolean _isPrime(long x){ for(long i=2;i*i<=x;i++) if(x%i==0)return false; return true; } public static void _sort(int[] arr,boolean isAscending){ int n = arr.length; List<Integer> list = new ArrayList<>(); for(int ele : arr)list.add(ele); Collections.sort(list); if(!isAscending)Collections.reverse(list); for(int i=0;i<n;i++)arr[i] = list.get(i); } public static void _sort(long[] arr,boolean isAscending){ int n = arr.length; List<Long> list = new ArrayList<>(); for(long ele : arr)list.add(ele); Collections.sort(list); if(!isAscending)Collections.reverse(list); for(int i=0;i<n;i++)arr[i] = list.get(i); } /*------------------------------------------HELPER FUNCTION ENDS HERE-------------------------------------------*/ /*-------------------------------------------FAST INPUT STARTS HERE---------------------------------------------*/ public static void closeIO() throws IOException{ out.flush(); out.close(); sc.close(); } private static final class FastestReader { private static final int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; public FastestReader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public FastestReader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() throws IOException { int b; //noinspection StatementWithEmptyBody while ((b = read()) != -1 && isSpaceChar(b)) {} return b; } public String next() throws IOException { int b = skip(); final StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = read(); } return sb.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } public void close() throws IOException { din.close(); } } /*---------------------------------------------FAST INPUT ENDS HERE ---------------------------------------------*/ }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
237508f6878c959be33ed6e351e775aa
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
/* Rating: 1367 Date: 24-01-2022 Time: 17-11-22 Author: Kartik Papney Linkedin: https://www.linkedin.com/in/kartik-papney-4951161a6/ Leetcode: https://leetcode.com/kartikpapney/ Codechef: https://www.codechef.com/users/kartikpapney */ import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class C_Game_Master { public static void check(ArrayList<Integer>[] graph, int src, boolean[] visited) { if(visited[src]) return; visited[src] = true; for(int val : graph[src]) { check(graph, val, visited); } return; } public static void s() { int n = sc.nextInt(); ArrayList<Integer>[] graph = new ArrayList[n]; for(int i=0; i<graph.length; i++) graph[i] = new ArrayList<>(); int[][] arr = new int[n][2]; int max = Integer.MIN_VALUE; int des = -1; for(int i=0; i<arr.length; i++) { arr[i][0] = i; arr[i][1] = sc.nextInt(); if(max < arr[i][1]) { max = arr[i][1]; des = i; } } Arrays.sort(arr, (x, y) -> x[1] - y[1]); for(int i=0; i<arr.length-1; i++) { graph[arr[i][0]].add(arr[i+1][0]); } for(int i=0; i<arr.length; i++) { arr[i][0] = i; arr[i][1] = sc.nextInt(); } Arrays.sort(arr, (x, y) -> x[1] - y[1]); for(int i=0; i<arr.length-1; i++) { graph[arr[i][0]].add(arr[i+1][0]); } boolean[] visited = new boolean[n]; StringBuilder ans = new StringBuilder(); check(graph, des, visited); for(int i=0; i<n; i++) { if(visited[i]) { ans.append(1); } else { ans.append(0); } } p.writeln(ans.toString()); } public static void main(String[] args) { int t = 1; t = sc.nextInt(); while (t-- != 0) { s(); } p.print(); } static final Integer MOD = (int) 1e9 + 7; static final FastReader sc = new FastReader(); static final Print p = new Print(); static class Functions { static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static int max(int[] a) { int max = Integer.MIN_VALUE; for (int val : a) max = Math.max(val, max); return max; } static int min(int[] a) { int min = Integer.MAX_VALUE; for (int val : a) min = Math.min(val, min); return min; } static long min(long[] a) { long min = Long.MAX_VALUE; for (long val : a) min = Math.min(val, min); return min; } static long max(long[] a) { long max = Long.MIN_VALUE; for (long val : a) max = Math.max(val, max); return max; } static long sum(long[] a) { long sum = 0; for (long val : a) sum += val; return sum; } static int sum(int[] a) { int sum = 0; for (int val : a) sum += val; return sum; } public static long mod_add(long a, long b) { return (a % MOD + b % MOD + MOD) % MOD; } public static long pow(long a, long b) { long res = 1; while (b > 0) { if ((b & 1) != 0) res = mod_mul(res, a); a = mod_mul(a, a); b >>= 1; } return res; } public static long mod_mul(long a, long b) { long res = 0; a %= MOD; while (b > 0) { if ((b & 1) > 0) { res = mod_add(res, a); } a = (2 * a) % MOD; b >>= 1; } return res; } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static long factorial(long n) { long res = 1; for (int i = 1; i <= n; i++) { res = (i % MOD * res % MOD) % MOD; } return res; } public static int count(int[] arr, int x) { int count = 0; for (int val : arr) if (val == x) count++; return count; } public static ArrayList<Integer> generatePrimes(int n) { boolean[] primes = new boolean[n]; for (int i = 2; i < primes.length; i++) primes[i] = true; for (int i = 2; i < primes.length; i++) { if (primes[i]) { for (int j = i * i; j < primes.length; j += i) { primes[j] = false; } } } ArrayList<Integer> arr = new ArrayList<>(); for (int i = 0; i < primes.length; i++) { if (primes[i]) arr.add(i); } return arr; } } static class Print { StringBuffer strb = new StringBuffer(); public void write(Object str) { strb.append(str); } public void writes(Object str) { char c = ' '; strb.append(str).append(c); } public void writeln(Object str) { char c = '\n'; strb.append(str).append(c); } public void writeln() { char c = '\n'; strb.append(c); } public void writes(int[] arr) { for (int val : arr) { write(val); write(' '); } } public void writes(long[] arr) { for (long val : arr) { write(val); write(' '); } } public void writeln(int[] arr) { for (int val : arr) { writeln(val); } } public void print() { System.out.print(strb); } public void println() { System.out.println(strb); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } double[] readArrayDouble(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } String nextLine() { String str = new String(); try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
b98e58305e2f391ae5e448062712f387
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class GameMaster { static int p; static boolean map1on; public static void main(String[] args) throws Exception { CustomScanner sc = new CustomScanner(); CustomPrinter cp = new CustomPrinter(); int T = sc.nextInt(); for (int t =0; t < T; t++){ p = sc.nextInt(); int[] m1 = sc.nextIntArray(p); int[] m2 = sc.nextIntArray(p); int i; Player[] players = new Player[p]; StringBuilder sb = new StringBuilder(p); for (i=0;i<p;i++){ players[i] = new Player(m1[i],m2[i]); } Player[] map1 = players.clone(); Player[] map2 = players.clone(); map1on = true; Arrays.sort(map1); map1on = false; Arrays.sort(map2); int pointofmax1 = map1[0].map2; int pointofmax2 = map2[0].map1; //logic is : if you can beat the guy who can beat the highest dude in map A in map B, you can win the tournament; //vice-versa for map b. boolean notdone = true; int k=0; while(notdone && k < players.length) { notdone = false; Player player1 = map1[k]; Player player2 = map2[k]; if (player1.map2 >= pointofmax1 || player1.map1 >= pointofmax2) { player1.possible = true; pointofmax1 = Math.min(pointofmax1, player1.map2); pointofmax2 = Math.min(pointofmax2, player1.map1); notdone = true; } if (player2.map2 >= pointofmax1 || player2.map1 >= pointofmax2) { player2.possible = true; pointofmax1 = Math.min(pointofmax1, player2.map2); pointofmax2 = Math.min(pointofmax2, player2.map1); notdone = true; } k++; } for (Player player : players){ if (player.possible){ sb.append('1'); }else{ sb.append('0'); } } cp.print(sb); cp.print("\n"); } cp.close(); } public static class Player implements Comparable<Player>{ int map1; int map2; boolean possible; Player(int a, int b){ this.map1 = a; this.map2 = b; } @Override public int compareTo(Player p) { if(map1on){ return this.map1 > p.map1 ? -1 : 1; }else{ return this.map2 > p.map2 ? -1 : 1; } } @Override public String toString() { return "Player{" + "map1=" + map1 + ", map2=" + map2 + ", possible=" + possible + '}'; } } static class CustomScanner { private final InputStream in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private static final long LONG_MAX_TENTHS = 922337203685477580L; private static final int LONG_MAX_LAST_DIGIT = 7; private static final int LONG_MIN_LAST_DIGIT = 8; public CustomScanner(InputStream in) { this.in = in; } public CustomScanner() { this(System.in); } private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { int digit = b - '0'; if (n >= LONG_MAX_TENTHS) { if (n == LONG_MAX_TENTHS) { if (minus) { if (digit <= LONG_MIN_LAST_DIGIT) { n = -n * 10 - digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString(b))); } } } else { if (digit <= LONG_MAX_LAST_DIGIT) { n = n * 10 + digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString(b))); } } } } throw new ArithmeticException( String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit)); } n = n * 10 + digit; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } public long[] nextLongArray(int length) { long[] array = new long[length]; for (int i = 0; i < length; i++) array[i] = this.nextLong(); return array; } public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map) { long[] array = new long[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsLong(this.nextLong()); return array; } public int[] nextIntArray(int length) { int[] array = new int[length]; for (int i = 0; i < length; i++) array[i] = this.nextInt(); return array; } public int[][] nextIntArrayMulti(int length, int width) { int[][] arrays = new int[width][length]; for (int i = 0; i < length; i++) { for (int j = 0; j < width; j++) arrays[j][i] = this.nextInt(); } return arrays; } public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map) { int[] array = new int[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsInt(this.nextInt()); return array; } public double[] nextDoubleArray(int length) { double[] array = new double[length]; for (int i = 0; i < length; i++) array[i] = this.nextDouble(); return array; } public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map) { double[] array = new double[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsDouble(this.nextDouble()); return array; } public long[][] nextLongMatrix(int height, int width) { long[][] mat = new long[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextLong(); } return mat; } public int[][] nextIntMatrix(int height, int width) { int[][] mat = new int[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextInt(); } return mat; } public double[][] nextDoubleMatrix(int height, int width) { double[][] mat = new double[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextDouble(); } return mat; } public char[][] nextCharMatrix(int height, int width) { char[][] mat = new char[height][width]; for (int h = 0; h < height; h++) { String s = this.next(); for (int w = 0; w < width; w++) { mat[h][w] = s.charAt(w); } } return mat; } } static class CustomPrinter extends PrintWriter { public CustomPrinter(PrintStream stream) { super(stream); } public CustomPrinter() { super(System.out); } private static String dtos(double x, int n) { StringBuilder sb = new StringBuilder(); if (x < 0) { sb.append('-'); x = -x; } x += Math.pow(10, -n) / 2; sb.append((long) x); sb.append("."); x -= (long) x; for (int i = 0; i < n; i++) { x *= 10; sb.append((int) x); x -= (int) x; } return sb.toString(); } @Override public void print(float f) { super.print(dtos(f, 20)); } @Override public void println(float f) { super.println(dtos(f, 20)); } @Override public void print(double d) { super.print(dtos(d, 20)); } @Override public void println(double d) { super.println(dtos(d, 20)); } public void printArray(int[] array, String separator) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(array[i]); super.print(separator); } super.println(array[n - 1]); } public void printArray(int[] array) { this.printArray(array, " "); } public void printArray(int[] array, String separator, java.util.function.IntUnaryOperator map) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(map.applyAsInt(array[i])); super.print(separator); } super.println(map.applyAsInt(array[n - 1])); } public void printArray(int[] array, java.util.function.IntUnaryOperator map) { this.printArray(array, " ", map); } public void printArray(long[] array, String separator) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(array[i]); super.print(separator); } super.println(array[n - 1]); } public void printArray(long[] array) { this.printArray(array, " "); } public void printArray(long[] array, String separator, java.util.function.LongUnaryOperator map) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(map.applyAsLong(array[i])); super.print(separator); } super.println(map.applyAsLong(array[n - 1])); } public void printArray(long[] array, java.util.function.LongUnaryOperator map) { this.printArray(array, " ", map); } } public static void safeSort(int[] array) { Integer[] temp = new Integer[array.length]; for (int n = 0; n < array.length; n++) { temp[n] = array[n]; } Arrays.sort(temp); for (int n = 0; n < array.length; n++) { array[n] = temp[n]; } } public static void safeSort(long[] array) { Long[] temp = new Long[array.length]; for (int n = 0; n < array.length; n++) { temp[n] = array[n]; } Arrays.sort(temp); for (int n = 0; n < array.length; n++) { array[n] = temp[n]; } } public static void safeSort(double[] array) { Double[] temp = new Double[array.length]; for (int n = 0; n < array.length; n++) { temp[n] = array[n]; } Arrays.sort(temp); for (int n = 0; n < array.length; n++) { array[n] = temp[n]; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
058a76ae1a300ace7272bb7ebd34a73c
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.util.stream.IntStream; import java.io.PrintWriter; import java.io.OutputStream; import java.util.Arrays; import java.io.IOException; import java.io.InputStreamReader; import java.io.FileNotFoundException; import java.util.stream.Stream; import java.util.StringTokenizer; import java.io.Writer; import java.io.BufferedReader; import java.util.Comparator; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Asgar Javadov */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); CGameMaster solver = new CGameMaster(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class CGameMaster { int[] a; int[] b; public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.nextInt(); a = in.readIntArray(n); b = in.readIntArray(n); var result = ArrayUtils.createCharArray(n, '0'); var aPlayerIdByPlace = IntStream.range(0, n).boxed().sorted(Comparator.comparingInt(i -> a[i])).mapToInt(i -> i).toArray(); var bPlayerIdByPlace = IntStream.range(0, n).boxed().sorted(Comparator.comparingInt(i -> b[i])).mapToInt(i -> i).toArray(); var next = new int[n][2]; ArrayUtils.fill(-1, next); for (int i = n - 2; i >= 0; --i) { var playerId = aPlayerIdByPlace[i]; var index = next[playerId][0] == -1 ? 0 : 1; next[playerId][index] = aPlayerIdByPlace[i + 1]; } for (int i = n - 2; i >= 0; --i) { var playerId = bPlayerIdByPlace[i]; var index = next[playerId][0] == -1 ? 0 : 1; next[playerId][index] = bPlayerIdByPlace[i + 1]; } dfs(aPlayerIdByPlace[n - 1], next, result); dfs(bPlayerIdByPlace[n - 1], next, result); /* var playerPlaceByIdInA = new int[n]; IntStream.range(0, n).forEach(i -> playerPlaceByIdInA[aPlayerIdByPlace[i]] = i); var playerPlaceByIdInB = new int[n]; IntStream.range(0, n).forEach(i -> playerPlaceByIdInB[bPlayerIdByPlace[i]] = i); var winners = new LinkedList<Integer>(); winners.add(aPlayerIdByPlace[n - 1]); winners.add(bPlayerIdByPlace[n - 1]); int leastA = n - 1; int leastB = n - 1; while (!winners.isEmpty()) { var currentIndex = winners.removeLast(); if (playerPlaceByIdInA[currentIndex] < leastA) { IntStream.range(playerPlaceByIdInA[currentIndex], leastA).forEach(winners::add); leastA = playerPlaceByIdInA[currentIndex]; } if (playerPlaceByIdInB[currentIndex] < leastB) { IntStream.range(playerPlaceByIdInB[currentIndex], leastB).forEach(winners::add); leastB = playerPlaceByIdInB[currentIndex]; } } for (int i = leastA; i < n; ++i) { result[aPlayerIdByPlace[i]] = '1'; } for (int i = leastB; i < n; i++) { result[bPlayerIdByPlace[i]] = '1'; } */ out.println(result); } private void dfs(int playerId, int[][] next, char[] result) { result[playerId] = '1'; for (int i = 0; i < 2 && next[playerId][i] != -1; ++i) { if (result[next[playerId][i]] == '0') { dfs(next[playerId][i], next, result); } } } } static class InputReader extends BufferedReader { StringTokenizer tokenizer; public InputReader(InputStream inputStream) { super(new InputStreamReader(inputStream), 32768); } public InputReader(String filename) { super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename))); } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { String line = readLine(); if (line == null) continue; tokenizer = new StringTokenizer(line); } catch (IOException e) { throw new RuntimeException(); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public int[] readIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = nextInt(); // IntStream.generate(this::nextInt).limit(size).toArray(); return array; } } static class OutputWriter extends PrintWriter { public OutputWriter(OutputStream outputStream) { super(outputStream); } public OutputWriter(Writer writer) { super(writer); } public OutputWriter(String filename) throws FileNotFoundException { super(filename); } public void close() { super.close(); } } static class ArrayUtils { public static void fill(int value, int[]... args) { for (int[] arg : args) Arrays.fill(arg, value); } public static char[] createCharArray(int count, char value) { char[] array = new char[count]; Arrays.fill(array, value); return array; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
c57276f961b8ecc0aa9712210bd36992
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; // Problem Link: https://codeforces.com/problemset/problem/1608/C public class game_master { public static int n; public static int[] canWin; public static void main (String[] args) throws IOException { // set up BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("test.in"))); PrintWriter out = new PrintWriter(System.out); int T = Integer.parseInt(in.readLine()); for (int i=0;i<T;i++) { n = Integer.parseInt(in.readLine()); StringTokenizer st = new StringTokenizer(in.readLine()); ArrayList<player> players = new ArrayList<>(); for (int j=1;j<=n;j++) players.add(new player (Integer.parseInt(st.nextToken()), 0, j)); st = new StringTokenizer(in.readLine()); for (int j=0;j<n;j++) players.get(j).setB_str(Integer.parseInt(st.nextToken())); canWin = new int[n+1]; solve(players); StringBuilder ans = new StringBuilder(); for (int j=1;j<=n;j++) ans.append(canWin[j]); out.println(ans); } out.close(); } static void solve(ArrayList<player> players) { // create directed graph of who can beat who ArrayList<Integer> startingPoints = new ArrayList<>(); HashSet<Integer>[] isBeatenBy = new HashSet[n+1]; for (int i=0;i<=n;i++) isBeatenBy[i] = new HashSet<>(); players.sort(Comparator.comparingInt(o -> o.a_str)); int last = players.get(n-1).id; startingPoints.add(last); //System.out.println(players); for (int i=n-2;i>=0;i--) { player curr = players.get(i); //isBeatenBy[curr.id].addAll(isBeatenBy[last]); isBeatenBy[curr.id].add(last); //isBeatenBy[curr.id].remove(curr.id); last = curr.id; } //System.out.println(Arrays.toString(isBeatenBy)); players.sort(Comparator.comparingInt(o -> o.b_str)); HashSet<Integer>[] isBeatenBy_two = new HashSet[n+1]; for (int i=0;i<=n;i++) isBeatenBy_two[i] = new HashSet<>(); last = players.get(n-1).id; startingPoints.add(last); //System.out.println(players); for (int i=n-2;i>=0;i--) { player curr = players.get(i); //isBeatenBy_two[curr.id].addAll(isBeatenBy_two[last]); isBeatenBy_two[curr.id].add(last); //isBeatenBy_two[curr.id].remove(curr.id); last = curr.id; } for (int i=1;i<=n;i++) isBeatenBy[i].addAll(isBeatenBy_two[i]); //System.out.println(Arrays.toString(isBeatenBy)); // dfs twice for (int point: startingPoints) { //System.out.println(point); dfs(point, isBeatenBy); } } static void dfs(int start, HashSet<Integer>[] graph) { boolean[] visited = new boolean[n+1]; visited[start] = true; Stack<Integer> stack = new Stack<>(); stack.push(start); while (!stack.isEmpty()) { int node = stack.pop(); canWin[node] = 1; for (int next: graph[node]) { if (!visited[next]) { visited[next] = true; stack.push(next); } } } } static class player { int a_str, b_str, id; player(int a, int b, int i) { a_str = a; // map one strength b_str = b; // map two strength id = i; // player id } public void setB_str(int b_str) { this.b_str = b_str; } public String toString() { return id + " " + a_str + " " + b_str; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
4454ee29eb6092eb9800ba220bfa994d
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.util.Collection; import java.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.Queue; import java.util.LinkedList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author saikat021 */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, InputReader in, OutputWriter out) { int T = in.nextInt(); while (T-- > 0) { int n = in.nextInt(); int[] a = in.nextIntArray(n); int[] b = in.nextIntArray(n); Integer[] index = new Integer[n]; for (int i = 0; i < n; i++) { index[i] = i; } ArrayList<ArrayList<Integer>> adj = new ArrayList<>(); for (int i = 0; i < n; i++) { adj.add(new ArrayList<>()); } Arrays.sort(index, (x, y) -> Integer.compare(a[y], a[x])); int maxA = index[0]; for (int i = 0; i < n - 1; i++) { addEdge(adj, index[i], index[i + 1]); } Arrays.sort(index, (x, y) -> Integer.compare(b[y], b[x])); for (int i = 0; i < n - 1; i++) { addEdge(adj, index[i], index[i + 1]); } int maxB = index[0]; boolean[] visited = new boolean[n]; BFS(adj, maxA, visited); BFS(adj, maxB, visited); for (int i = 0; i < n; i++) { out.print(visited[i] ? "1" : "0"); } out.println(); } } private void BFS(ArrayList<ArrayList<Integer>> adj, int i, boolean[] visited) { Queue<Integer> q = new LinkedList<>(); q.add(i); while (!q.isEmpty()) { int u = q.poll(); visited[u] = true; for (int v : adj.get(u)) { if (!visited[v]) q.add(v); } } } private void addEdge(ArrayList<ArrayList<Integer>> adj, int u, int v) { adj.get(v).add(u); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; ++i) array[i] = nextInt(); return array; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println() { writer.println(); } public void close() { writer.close(); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
99118bf390b7809bf9836f013d7e1da6
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.util.Collection; import java.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.Queue; import java.util.LinkedList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author saikat021 */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, InputReader in, OutputWriter out) { int T = in.nextInt(); while (T-- > 0) { int n = in.nextInt(); int[] a = in.nextIntArray(n); int[] b = in.nextIntArray(n); Integer[] index = new Integer[n]; for (int i = 0; i < n; i++) { index[i] = i; } ArrayList<ArrayList<Integer>> adj = new ArrayList<>(); for (int i = 0; i < n; i++) { adj.add(new ArrayList<>()); } Arrays.sort(index, (x, y) -> Integer.compare(a[y], a[x])); int maxA = index[0]; for (int i = 0; i < n - 1; i++) { addEdge(adj, index[i], index[i + 1]); } Arrays.sort(index, (x, y) -> Integer.compare(b[y], b[x])); for (int i = 0; i < n - 1; i++) { addEdge(adj, index[i], index[i + 1]); } int maxB = index[0]; boolean[] visited = new boolean[n]; BFS(adj, maxA, visited); BFS(adj, maxB, visited); for (int i = 0; i < n; i++) { out.print(visited[i] ? "1" : "0"); } out.println(); } } private void BFS(ArrayList<ArrayList<Integer>> adj, int i, boolean[] visited) { Queue<Integer> q = new LinkedList<>(); q.add(i); while (!q.isEmpty()) { int u = q.poll(); visited[u] = true; for (int v : adj.get(u)) { if (!visited[v]) q.add(v); } } } private void addEdge(ArrayList<ArrayList<Integer>> adj, int u, int v) { adj.get(v).add(u); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; ++i) array[i] = nextInt(); return array; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println() { writer.println(); } public void close() { writer.close(); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
3bfcf48dd4bb4cac015f5a98b3656aae
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void sort(long[] a) { ArrayList<Long> arr = new ArrayList<>(); for (int i = 0; i < a.length; i++) arr.add(a[i]); Collections.sort(arr); for (int i = 0; i < arr.size(); i++) a[i] = arr.get(i); } public static void revsort(long[] a) { ArrayList<Long> arr = new ArrayList<>(); for (int i = 0; i < a.length; i++) arr.add(a[i]); Collections.sort(arr, Collections.reverseOrder()); for (int i = 0; i < arr.size(); i++) a[i] = arr.get(i); } public static class pair //for value and index { long val; int in; pair(long val,int in) { this.val=val; this.in=in; } } public static void revsortpair(pair[] num) { ArrayList<pair> arr=new ArrayList<>(); for(int i=1;i<=num.length-1;i++)arr.add(new pair(num[i].val,i)); arr.sort(new Comparator<pair>() { public int compare(pair o1, pair o2) { long val = o1.val - o2.val; if (val == 0) return 0; else if (val > 0) return -1; else return 1; } }); for(int i=1;i<num.length;i++) { num[i].val=arr.get(i-1).val; num[i].in=arr.get(i-1).in; } } //Cover the small test cases like for n=1 . public static ArrayList<HashSet<Integer>> adj; public static void main(String[] args) { FastReader obj = new FastReader(); PrintWriter out = new PrintWriter(System.out); int len = obj.nextInt(); while (len-- != 0) { int n = obj.nextInt(); adj=new ArrayList<>(n+1); HashMap<Long,Integer> aa=new HashMap<>(); HashMap<Long,Integer> bb=new HashMap<>(); for(int i=0;i<=n;i++)adj.add(new HashSet<>()); pair[] a=new pair[n+1]; long ma=0,mb=0; for(int i=1;i<=n;i++) { long val=obj.nextLong(); a[i]=new pair(val,i); aa.put(val,i); ma=Math.max(ma, val); } pair[] b=new pair[n+1]; for(int i=1;i<=n;i++) { long val=obj.nextLong(); b[i]=new pair(val,i); bb.put(val,i); mb=Math.max(mb, val); } revsortpair(a); revsortpair(b); for(int i=1;i<n;i++) { adj.get(a[i+1].in).add(a[i].in); adj.get(b[i+1].in).add(b[i].in); } int[] ans=new int[n+1]; int[] vis=new int[n+1]; dfs(aa.get(ma),vis,ans); Arrays.fill(vis,0); dfs(bb.get(mb),vis,ans); for(int i=1;i<=n;i++)out.print(ans[i]); out.println(); } out.flush(); } public static void dfs(int cur,int[] vis,int[] ans) { vis[cur]=1; ans[cur]=1; for(int nd:adj.get(cur)) { if(vis[nd]==0)dfs(nd,vis,ans); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
cc1e581e53fd6ee94dd37f008cb156b0
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class C_1608 { static ArrayList<Integer>[] adjList; static char[] vis; public static void dfs(int u) { vis[u] = '1'; for(int v : adjList[u]) if(vis[v] == '0') dfs(v); } public static void main(String[] args) throws Exception { //Scanner sc = new Scanner("genC_1608.txt"); Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int[] a = sc.nextIntArray(n), b = sc.nextIntArray(n); adjList = new ArrayList[n]; for(int i = 0; i < n; i++) adjList[i] = new ArrayList<>(); Integer[] ind = new Integer[n]; for(int i = 0; i < n; i++) ind[i] = i; Arrays.sort(ind, (i, j) -> a[i] - a[j]); for(int i = 0; i < n - 1; i++) adjList[ind[i]].add(ind[i + 1]); Arrays.sort(ind, (i, j) -> b[i] - b[j]); for(int i = 0; i < n - 1; i++) adjList[ind[i]].add(ind[i + 1]); vis = new char[n]; Arrays.fill(vis, '0'); dfs(ind[n - 1]); pw.println(vis); } pw.flush(); } public static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public Scanner(String file) throws Exception { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public long nextLong() throws IOException { return Long.parseLong(next()); } public int[] nextIntArray(int n) throws IOException { int[] array = new int[n]; for (int i = 0; i < n; i++) array[i] = nextInt(); return array; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] array = new Integer[n]; for (int i = 0; i < n; i++) array[i] = new Integer(nextInt()); return array; } public long[] nextLongArray(int n) throws IOException { long[] array = new long[n]; for (int i = 0; i < n; i++) array[i] = nextLong(); return array; } public double[] nextDoubleArray(int n) throws IOException { double[] array = new double[n]; for (int i = 0; i < n; i++) array[i] = nextDouble(); return array; } public static int[] shuffle(int[] a) { int n = a.length; Random rand = new Random(); for (int i = 0; i < n; i++) { int tmpIdx = rand.nextInt(n); int tmp = a[i]; a[i] = a[tmpIdx]; a[tmpIdx] = tmp; } return a; } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(3000); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
531263ae1cf73905c885fc807b62919a
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; import java.util.concurrent.ScheduledExecutorService; import static java.lang.Math.*; import static java.lang.Math.ceil; import static java.util.Arrays.sort; public class C { public static void main(String[] args) throws IOException { int t = ri(); while (t-- > 0) { int n = ri(); int a[] = ria(n); int b[] = ria(n); ArrayList<Nodes> list = new ArrayList<>(); for (int i = 0; i < n; i++) { list.add(new Nodes(a[i], b[i], i)); } Collections.sort(list, new Comparator<Nodes>() { @Override public int compare(Nodes o1, Nodes o2) { return o1.a - o2.a; } }); boolean ans [] =new boolean[n]; int min = list.get(n-1).b; ans[list.get(n-1).i] = true; for (int i = n-2 ; i >=0 ; i--){ if (list.get(i).b > min) { for (int j = i; j < n && !ans[list.get(j).i]; j++) { ans[list.get(j).i] = true; min = Math.min(min, list.get(j).b); } } } for (int i = 0 ; i < n ; i++){ pr(ans[i] ? '1' : '0'); } prln(); } close(); } static class Nodes { int a; int b; int i; Nodes(int a, int b, int i) { this.a = a; this.b = b; this.i = i; } } static class DisjointSetUnion { int p[]; int count[]; public DisjointSetUnion(int n) { p = new int[n]; count = new int[n]; for (int i = 0; i < n; i++) { count[i] = 1; } clear(n); } public void clear(int n) { for (int i = 0; i < n; i++) { p[i] = i; } } public int get(int x) { return x != p[x] ? p[x] = get(p[x]) : x; } public int getCount(int x) { return count[x]; } public boolean union(int a, int b) { a = get(a); b = get(b); p[a] = b; if (a != b) { count[b] += count[a]; count[a] = 0; } return a != b; } } static BufferedReader __i = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter __o = new PrintWriter(new OutputStreamWriter(System.out)); static StringTokenizer input; static boolean[] isPrime; static Random __r = new Random(); // references // IBIG = 1e9 + 7 // IMAX ~= 2e9 // LMAX ~= 9e18 // constants static final int IBIG = 1000000007; static final int IMAX = 2147483647; static final long LMAX = 9223372036854775807L; // math util static int minof(int a, int b, int c) { return min(a, min(b, c)); } static int minof(int... x) { if (x.length == 1) return x[0]; if (x.length == 2) return min(x[0], x[1]); if (x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i]; return min; } static long minof(long a, long b, long c) { return min(a, min(b, c)); } static long minof(long... x) { if (x.length == 1) return x[0]; if (x.length == 2) return min(x[0], x[1]); if (x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i]; return min; } static int maxof(int a, int b, int c) { return max(a, max(b, c)); } static int maxof(int... x) { if (x.length == 1) return x[0]; if (x.length == 2) return max(x[0], x[1]); if (x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i]; return max; } static long maxof(long a, long b, long c) { return max(a, max(b, c)); } static long maxof(long... x) { if (x.length == 1) return x[0]; if (x.length == 2) return max(x[0], x[1]); if (x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i]; return max; } static int powi(int a, int b) { if (a == 0) return 0; int ans = 1; while (b > 0) { if ((b & 1) > 0) ans *= a; a *= a; b >>= 1; } return ans; } static long powl(long a, int b) { if (a == 0) return 0; long ans = 1; while (b > 0) { if ((b & 1) > 0) ans *= a; a *= a; b >>= 1; } return ans; } static int fli(double d) { return (int) d; } static int cei(double d) { return (int) ceil(d); } static long fll(double d) { return (long) d; } static long cel(double d) { return (long) ceil(d); } static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } static int[] exgcd(int a, int b) { if (b == 0) return new int[]{1, 0}; int[] y = exgcd(b, a % b); return new int[]{y[1], y[0] - y[1] * (a / b)}; } static long[] exgcd(long a, long b) { if (b == 0) return new long[]{1, 0}; long[] y = exgcd(b, a % b); return new long[]{y[1], y[0] - y[1] * (a / b)}; } static int randInt(int min, int max) { return __r.nextInt(max - min + 1) + min; } static long mix(long x) { x += 0x9e3779b97f4a7c15L; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L; x = (x ^ (x >> 27)) * 0x94d049bb133111ebL; return x ^ (x >> 31); } static void setTrue(int n) { for (int i = 0; i < n; i++) { isPrime[i] = true; } } static void prime(int n) { for (int i = 2; i * i < n; i++) { if (isPrime[i]) { for (int j = i * i; j < n; j += i) isPrime[j] = false; } } } // array util static void reverse(int[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(long[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(double[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { double swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(char[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void shuffle(int[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void shuffle(long[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void shuffle(double[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void rsort(int[] a) { shuffle(a); sort(a); } static void rsort(long[] a) { shuffle(a); sort(a); } static void rsort(double[] a) { shuffle(a); sort(a); } static int[] copy(int[] a) { int[] ans = new int[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static long[] copy(long[] a) { long[] ans = new long[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static double[] copy(double[] a) { double[] ans = new double[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static char[] copy(char[] a) { char[] ans = new char[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static void resetBoolean(boolean[] vis, int n) { for (int i = 0; i < n; i++) { vis[i] = false; } } static void setMinusOne(int[][] matrix) { int row = matrix.length; int col = matrix[0].length; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { matrix[i][j] = -1; } } } // input static void r() throws IOException { input = new StringTokenizer(rline()); } static int ri() throws IOException { return Integer.parseInt(rline().split(" ")[0]); } static long rl() throws IOException { return Long.parseLong(rline()); } static double rd() throws IOException { return Double.parseDouble(rline()); } static int[] ria(int n) throws IOException { int[] a = new int[n]; r(); for (int i = 0; i < n; ++i) a[i] = ni(); return a; } static void ria(int[] a) throws IOException { int n = a.length; r(); for (int i = 0; i < n; ++i) a[i] = ni(); } static int[] riam1(int n) throws IOException { int[] a = new int[n]; r(); for (int i = 0; i < n; ++i) a[i] = ni() - 1; return a; } static void riam1(int[] a) throws IOException { int n = a.length; r(); for (int i = 0; i < n; ++i) a[i] = ni() - 1; } static long[] rla(int n) throws IOException { long[] a = new long[n]; r(); for (int i = 0; i < n; ++i) a[i] = nl(); return a; } static void rla(long[] a) throws IOException { int n = a.length; r(); for (int i = 0; i < n; ++i) a[i] = nl(); } static double[] rda(int n) throws IOException { double[] a = new double[n]; r(); for (int i = 0; i < n; ++i) a[i] = nd(); return a; } static void rda(double[] a) throws IOException { int n = a.length; r(); for (int i = 0; i < n; ++i) a[i] = nd(); } static char[] rcha() throws IOException { return rline().toCharArray(); } static void rcha(char[] a) throws IOException { int n = a.length, i = 0; for (char c : rline().toCharArray()) a[i++] = c; } static String rline() throws IOException { return __i.readLine(); } static String n() { return input.nextToken(); } static int rni() throws IOException { r(); return ni(); } static int ni() { return Integer.parseInt(n()); } static long rnl() throws IOException { r(); return nl(); } static long nl() { return Long.parseLong(n()); } static double rnd() throws IOException { r(); return nd(); } static double nd() { return Double.parseDouble(n()); } // output static void pr(int i) { __o.print(i); } static void prln(int i) { __o.println(i); } static void pr(long l) { __o.print(l); } static void prln(long l) { __o.println(l); } static void pr(double d) { __o.print(d); } static void prln(double d) { __o.println(d); } static void pr(char c) { __o.print(c); } static void prln(char c) { __o.println(c); } static void pr(char[] s) { __o.print(new String(s)); } static void prln(char[] s) { __o.println(new String(s)); } static void pr(String s) { __o.print(s); } static void prln(String s) { __o.println(s); } static void pr(Object o) { __o.print(o); } static void prln(Object o) { __o.println(o); } static void prln() { __o.println(); } static void pryes() { prln("yes"); } static void pry() { prln("Yes"); } static void prY() { prln("YES"); } static void prno() { prln("no"); } static void prn() { prln("No"); } static void prN() { prln("NO"); } static boolean pryesno(boolean b) { prln(b ? "yes" : "no"); return b; } ; static boolean pryn(boolean b) { prln(b ? "Yes" : "No"); return b; } static boolean prYN(boolean b) { prln(b ? "YES" : "NO"); return b; } static void prln(int... a) { for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ; if (a.length > 0) prln(a[a.length - 1]); else prln(); } static void prln(long... a) { for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ; if (a.length > 0) prln(a[a.length - 1]); else prln(); } static void prln(double... a) { for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ; if (a.length > 0) prln(a[a.length - 1]); else prln(); } static <T> void prln(Collection<T> c) { int n = c.size() - 1; Iterator<T> iter = c.iterator(); for (int i = 0; i < n; pr(iter.next()), pr(' '), ++i) ; if (n >= 0) prln(iter.next()); else prln(); } static void h() { prln("hlfd"); flush(); } static void flush() { __o.flush(); } static void close() { __o.close(); } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
c30bf8417920f374cb73f5774299af94
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class Main { static int[] ans; static int n; public static void main(String[] args) { FastScanner fs=new FastScanner(); PrintWriter out = new PrintWriter(System.out); /****** CODE STARTS HERE *****/ //-------------------------------------------------------------------------------------------------------- int t = fs.nextInt(); while(t-->0) { n = fs.nextInt(); int[] a = fs.readArray(n); int[] b = fs.readArray(n); ans = new int[n]; List<Pair> list = new ArrayList<>(); for(int i=0; i<n; i++) { list.add(new Pair(i, a[i])); } Collections.sort(list, (o1, o2) -> Integer.compare(o1.val, o2.val)); int[] cc = new int[n]; for(int i=0; i<n; i++) { cc[i] = b[list.get(i).pos]; } int[] dpl = new int[n]; dpl[0] = cc[0]; for(int i=1; i<n; i++) { dpl[i] = Math.max(dpl[i-1], cc[i]); } int[] dpr = new int[n]; dpr[n-1] = cc[n-1]; for(int i=n-2; i>=0; i--) { dpr[i] = Math.min(dpr[i+1], cc[i]); } ans[list.get(n-1).pos] = 1; for(int i=n-2; i>=0; i--) { if(dpl[i] > dpr[i+1])ans[list.get(i).pos] = 1; else break; } for(int x: ans)out.print(x); out.println(); } out.close(); } static class Pair{ int pos, val; Pair(int pos, int val){ this.pos = pos; this.val = val; } } //****** CODE ENDS HERE ***** //---------------------------------------------------------------------------------------------------------------- static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } //----------- FastScanner class for faster input--------------------------- static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
77d8a0fdd6defe1260c470d90ce9b8c3
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class Main { static int[] ans; static int n; public static void main(String[] args) { FastScanner fs=new FastScanner(); PrintWriter out = new PrintWriter(System.out); /****** CODE STARTS HERE *****/ //-------------------------------------------------------------------------------------------------------- int t = fs.nextInt(); while(t-->0) { n = fs.nextInt(); int[] a = fs.readArray(n); int[] b = fs.readArray(n); ans = new int[n]; f(a, b); for(int x: ans)out.print(x); out.println(); } out.close(); } static void f(int[] a, int[] b) { List<Pair> list = new ArrayList<>(); for(int i=0; i<n; i++) { list.add(new Pair(i, a[i])); } Collections.sort(list, (o1, o2) -> Integer.compare(o1.val, o2.val)); int[] cc = new int[n]; for(int i=0; i<n; i++) { cc[i] = b[list.get(i).pos]; } int[] dpl = new int[n]; dpl[0] = cc[0]; for(int i=1; i<n; i++) { dpl[i] = Math.max(dpl[i-1], cc[i]); } int[] dpr = new int[n]; dpr[n-1] = cc[n-1]; for(int i=n-2; i>=0; i--) { dpr[i] = Math.min(dpr[i+1], cc[i]); } ans[list.get(n-1).pos] = 1; for(int i=n-2; i>=0; i--) { if(dpl[i] > dpr[i+1])ans[list.get(i).pos] = 1; else break; } } static class Pair{ int pos, val; Pair(int pos, int val){ this.pos = pos; this.val = val; } } //****** CODE ENDS HERE ***** //---------------------------------------------------------------------------------------------------------------- static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } //----------- FastScanner class for faster input--------------------------- static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
a343ce1554292788e51558e05727c037
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class Main { static int[] ans; static int n; public static void main(String[] args) { FastScanner fs=new FastScanner(); PrintWriter out = new PrintWriter(System.out); /****** CODE STARTS HERE *****/ //-------------------------------------------------------------------------------------------------------- int t = fs.nextInt(); while(t-->0) { n = fs.nextInt(); int[] a = fs.readArray(n); int[] b = fs.readArray(n); ans = new int[n]; f(a, b); f(b, a); for(int x: ans)out.print(x); out.println(); } out.close(); } static void f(int[] a, int[] b) { List<Pair> list = new ArrayList<>(); for(int i=0; i<n; i++) { list.add(new Pair(i, a[i])); } Collections.sort(list, (o1, o2) -> Integer.compare(o1.val, o2.val)); int[] cc = new int[n]; for(int i=0; i<n; i++) { cc[i] = b[list.get(i).pos]; } int[] dpl = new int[n]; dpl[0] = cc[0]; for(int i=1; i<n; i++) { dpl[i] = Math.max(dpl[i-1], cc[i]); } int[] dpr = new int[n]; dpr[n-1] = cc[n-1]; for(int i=n-2; i>=0; i--) { dpr[i] = Math.min(dpr[i+1], cc[i]); } ans[list.get(n-1).pos] = 1; for(int i=n-2; i>=0; i--) { if(dpl[i] > dpr[i+1])ans[list.get(i).pos] = 1; else break; } } static class Pair{ int pos, val; Pair(int pos, int val){ this.pos = pos; this.val = val; } } //****** CODE ENDS HERE ***** //---------------------------------------------------------------------------------------------------------------- static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } //----------- FastScanner class for faster input--------------------------- static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
832a7a98bce3b23fde9efc01ed9bf87f
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class gameMaster { public static void main(String args[]) throws IOException { FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); for ( ; t > 0; t--) { int n = in.nextInt(); int[][] a = new int[n][2]; for (int i = 0; i < n; i++) { a[i] = new int[] {i,in.nextInt()}; } int[][] b = new int[n][2]; for (int i = 0; i < n; i++) { b[i] = new int[] {i,in.nextInt()}; } TreeMap<Integer, Integer> av = new TreeMap<>(); TreeMap<Integer, Integer> bv = new TreeMap<>(); Arrays.sort(a, (x,y)->x[1]-y[1]); Arrays.sort(b, (x,y)->x[1]-y[1]); for (int i = 0; i < n; i++) { //System.out.println(Arrays.toString(a[i])); av.put(a[i][0], i); } for (int i = 0; i < n; i++) { //System.out.println(Arrays.toString(b[i])); bv.put(b[i][0], i); } int largest = 0; for (int i = 0; i < n; i++) { if (a[i][1] > a[largest][1]) largest = i; } largest = a[largest][0]; boolean[] win = new boolean[n]; boolean[] seen1 = new boolean[n]; boolean[] seen2 = new boolean[n]; int index1 = -1; int index2 = bv.get(largest); //System.out.println(index2); while (index1 != -1 || index2 != -1) { if (index1 != -1) { index2 = (int)(1e9); for (int i = index1 + 1; i < n; i++) { if (seen1[i]) break; seen1[i] = true; win[a[i][0]] = true; index2 = Math.min(index1, bv.get(a[i][0])); } if (index2 == (int)(1e9)) index2 = -1; index1 = -1; } else { index1 = (int)(1e9); for (int i = index2; i < n; i++) { if (seen2[i]) break; seen2[i] = true; win[b[i][0]] = true; index1 = Math.min(index1, av.get(b[i][0])); } if (index1 == (int)(1e9)) index1 = -1; index2 = -1; } } for (int i = 0; i < n; i++) if (win[i]) out.print(1); else out.print(0); out.println(); } out.close(); } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream i) { br = new BufferedReader(new InputStreamReader(i)); st = new StringTokenizer(""); } public String next() throws IOException { if (st.hasMoreTokens()) return st.nextToken(); else st = new StringTokenizer(br.readLine()); return next(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
571ba5c67a117b71e7579509a4928504
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; /** * https://codeforces.com/contest/1608/problem/C * (input omitted due to length) */ public final class GameMaster { public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int testNum = Integer.parseInt(read.readLine()); for (int t = 0; t < testNum; t++) { int playerNum = Integer.parseInt(read.readLine()); StringTokenizer map1 = new StringTokenizer(read.readLine()); StringTokenizer map2 = new StringTokenizer(read.readLine()); int[][] players = new int[playerNum][]; for (int p = 0; p < playerNum; p++) { players[p] = new int[]{ Integer.parseInt(map1.nextToken()), Integer.parseInt(map2.nextToken()), p }; } // elements are guaranteed to be unique Arrays.sort(players, Comparator.comparingInt(p -> p[0])); TreeMap<Integer, Integer> maxKills = new TreeMap<>(); for (int p = 0; p < players.length; p++) { maxKills.put(players[p][1], p); } int prev = Integer.MIN_VALUE; for (int i : maxKills.keySet()) { if (prev != Integer.MIN_VALUE) { maxKills.put(i, Math.max(maxKills.get(i), maxKills.get(prev))); } prev = i; } int[] bestMap2 = new int[playerNum]; bestMap2[0] = players[0][1]; for (int p = 1; p < playerNum; p++) { bestMap2[p] = Math.max(bestMap2[p - 1], players[p][1]); } // System.out.println(maxKills); // System.out.println(Arrays.toString(bestMap2)); int lo = 0; int hi = playerNum - 1; int valid = -1; while (lo <= hi) { int mid = (lo + hi) / 2; int at = mid; while (maxKills.get(bestMap2[at]) != at) { at = maxKills.get(bestMap2[at]); } if (at == playerNum - 1) { valid = mid; hi = mid - 1; } else { lo = mid + 1; } } int[] possible = new int[playerNum]; for (int p = valid; p < playerNum; p++) { possible[players[p][2]] = 1; } for (int p = 0; p < playerNum; p++) { System.out.print(possible[p]); } System.out.println(); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
af13c60db7d2534dae1164637413b0c3
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.text.DecimalFormat; import java.util.Scanner; import java.util.*; public class Test1 { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 测试次数 int testnum = in.nextInt(); for (int k = 0; k <testnum; k++) { int n = in.nextInt(); int[][] a = new int[n][2]; int[][] b = new int[n][2]; int[][] rank = new int[n][2]; for (int i = 0; i <n ; i++) { a[i][0] = in.nextInt(); a[i][1] = i; } for (int i = 0; i < n; i++) { b[i][0] = in.nextInt(); b[i][1] = i; } Arrays.sort(a,(x,y)->y[0]-x[0]); Arrays.sort(b,(x,y)->y[0]-x[0]); for (int i = 0; i < n; i++) { rank[a[i][1]][0] = i; rank[b[i][1]][1] = i; } int[] dp = new int[n]; dp[0] = 1; int[] right = new int[n]; int min = rank[a[n - 1][1]][1]; for (int i = n-1; i >=0; i--) { right[i] = Math.min(min, rank[a[i][1]][1]); min = right[i]; } int max = rank[a[0][1]][1]; int[] left = new int[n]; for (int i = 1; i < n; i++) { left[i] = Math.max(max, rank[a[i-1][1]][1]); max = left[i]; if(right[i]<left[i]){ dp[i] = 1; }else{ break; } } StringBuffer sb = new StringBuffer(); for (int i = 0; i < n; i++) { sb.append(dp[rank[i][0]]); } System.out.println(sb); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
efdb957621b42c770ba6b2d22c7c6a40
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.text.DecimalFormat; import java.util.Scanner; import java.util.*; public class Test1 { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 测试次数 int testnum = in.nextInt(); for (int k = 0; k <testnum; k++) { int n = in.nextInt(); int[][] a = new int[n][2]; int[][] b = new int[n][2]; int[][] rank = new int[n][2]; for (int i = 0; i <n ; i++) { a[i][0] = in.nextInt(); a[i][1] = i; } for (int i = 0; i < n; i++) { b[i][0] = in.nextInt(); b[i][1] = i; } Arrays.sort(a,(x,y)->y[0]-x[0]); Arrays.sort(b,(x,y)->y[0]-x[0]); for (int i = 0; i < n; i++) { rank[a[i][1]][0] = i; rank[b[i][1]][1] = i; } int[] dp = new int[n]; dp[0] = 1; // int[] dp2 = new int[n]; // a后缀最高排名 int[] right = new int[n]; int min = rank[a[n - 1][1]][1]; for (int i = n-1; i >=0; i--) { right[i] = Math.min(min, rank[a[i][1]][1]); min = right[i]; } // a的前缀最低排名 int max = rank[a[0][1]][1]; int[] left = new int[n]; for (int i = 1; i < n; i++) { left[i] = Math.max(max, rank[a[i-1][1]][1]); max = left[i]; if(right[i]<left[i]){ dp[i] = 1; }else{ break; } } // b的排第一的在a中的坐标 // int index = rank[b[0][1]][0]; // int c = 0; // while (c<=index){ // dp[c++] = 1; // } // int index2 = rank[a[0][1]][1]; // int c2 = 0; // while (c2<=index){ // dp2[c2++] = 1; // } for (int i = 0; i < n; i++) { System.out.print(dp[rank[i][0]]); } System.out.println(); } } // private static int check(int[][] rank, int[][] a, int[][] b) { // // } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
35e8716f432e66adf5a4e175c4f298c6
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Locale; import java.util.Map.Entry; import java.util.PriorityQueue; import java.util.Random; import java.util.Scanner; import java.util.TreeSet; public final class CF_758_D2_C2 { static boolean verb=true; static void log(Object X){if (verb) System.err.println(X);} static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}} static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}} static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}} static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}} static void logWln(Object X){if (verb) System.err.print(X);} static void info(Object o){ System.out.println(o);} static void output(Object o){outputWln(""+o+"\n"); } static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}} // Global vars static BufferedWriter out; static InputReader reader; static long powerMod(long b,long e,long m){ long x=1; while (e>0) { if (e%2==1) x=(b*x)%m; b=(b*b)%m; e=e/2; } return x; } static void test() { log("testing"); Random r=new Random(); int NTESTS=1000000000; int NMAX=100; //int MMAX=10000; int VMAX=100; for( int t=0;t<NTESTS;t++) { } log("done"); } static int sign(int x) { if (x>0) return 1; if (x==0) return 0; return -1; } static class Segment implements Comparable<Segment>{ int a; int b; public int compareTo(Segment X) { if (a!=X.a) return a-X.a; if (b!=X.b) return b-X.b; return 0; } public Segment(int a, int b) { this.a = a; this.b = b; } } // REVERSE static class Composite implements Comparable<Composite>{ int x; int t; public int compareTo(Composite X) { if (x!=X.x) return -(x-X.x); return t-X.t; } public Composite(int x, int t) { this.x = x; this.t = t; } } static class BIT { int[] tree; int N; BIT(int N){ tree=new int[N+1]; this.N=N; } void add(int idx,int val){ idx++; while (idx<=N){ tree[idx]+=val; idx+=idx & (-idx); } } int read(int idx){ idx++; int sum=0; while (idx>0){ sum+=tree[idx]; idx-=idx & (-idx); } return sum; } } // reverse segment --> list of segments static int mod=1000000001; static void process() throws Exception { out = new BufferedWriter(new OutputStreamWriter(System.out)); reader=new InputReader(System.in); Locale.setDefault(Locale.US); //Scanner sc=new Scanner(System.in); //sc.useLocale(Locale.US); //test(); int T=reader.readInt(); for (int t=0;t<T;t++) { int n=reader.readInt(); int[] a=new int[n]; int[] b=new int[n]; Composite[] A=new Composite[n]; Composite[] B=new Composite[n]; for (int i=0;i<n;i++) { a[i]=reader.readInt(); A[i]=new Composite(a[i],i); } for (int i=0;i<n;i++) { b[i]=reader.readInt(); B[i]=new Composite(b[i],i); } Arrays.sort(A); Arrays.sort(B); int[] ranka=new int[n]; int[] rankb=new int[n]; for (int i=0;i<n;i++) { ranka[A[i].t]=i; rankb[B[i].t]=i; } int sa=A[0].t; int sb=A[0].t; boolean[] win=new boolean[n]; win[sa]=true; win[sb]=true; int la=0; int lb=0; int[] maxrankab=new int[n]; int[] maxrankba=new int[n]; int cur=0; for (int e=0;e<n;e++) { int i=A[e].t; cur=Math.max(cur, rankb[i]); maxrankab[e]=cur; } cur=0; for (int e=0;e<n;e++) { int i=B[e].t; cur=Math.max(cur, ranka[i]); maxrankba[e]=cur; } boolean goon=true; while (goon) { goon=false; int nlb=maxrankab[la]; if (nlb>lb) { goon=true; lb=nlb; } int nla=maxrankba[lb]; if (nla>la) { goon=true; la=nla; } } for (int e=0;e<=la;e++) { int i=A[e].t; win[i]=true; int j=B[e].t; win[j]=true; } char[] ans=new char[n]; //log(topa); // log(topb); for (int i=0;i<n;i++) { if (win[i]) ans[i]='1'; else ans[i]='0'; } output(new String(ans)); } try { out.close(); } catch (Exception EX){} } public static void main(String[] args) throws Exception { process(); } static final class InputReader { private final InputStream stream; private final byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } private int read() throws IOException { if (curChar >= numChars) { curChar = 0; numChars = stream.read(buf); if (numChars <= 0) { return -1; } } return buf[curChar++]; } public final String readString() throws IOException { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res=new StringBuilder(); do { res.append((char)c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public final int readInt() throws IOException { int c = read(); boolean neg=false; while (isSpaceChar(c)) { c = read(); } char d=(char)c; //log("d:"+d); if (d=='-') { neg=true; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); //log("res:"+res); if (neg) return -res; return res; } public final long readLong() throws IOException { int c = read(); boolean neg=false; while (isSpaceChar(c)) { c = read(); } char d=(char)c; //log("d:"+d); if (d=='-') { neg=true; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); //log("res:"+res); if (neg) return -res; return res; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
de7e2c7ff09afd4269abeee5aedc389a
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static int MOD = 1000000007; // After writing solution, quick scan for: // array out of bounds // special cases e.g. n=1? // npe, particularly in maps // // Big numbers arithmetic bugs: // int overflow // sorting, or taking max, after MOD void solve() throws IOException { int T = ri(); for (int Ti = 0; Ti < T; Ti++) { int n = ri(); int[] a = ril(n); int[] b = ril(n); boolean[] ans = new boolean[n]; // Player with max map1 score can obviously win. Who can beat him? If so, then that person can win too. int imaxa = 0; int imaxb = 0; for (int i = 0; i < n; i++) { if (a[i] > a[imaxa]) imaxa = i; if (b[i] > b[imaxb]) imaxb = i; } ans[imaxa] = ans[imaxb] = true; Deque<Integer> q = new ArrayDeque<>(); q.addLast(imaxa); q.addLast(imaxb); TreeSet<Integer> idxByA = new TreeSet<>((i1, i2) -> Integer.compare(a[i1], a[i2])); TreeSet<Integer> idxByB = new TreeSet<>((i1, i2) -> Integer.compare(b[i1], b[i2])); for (int i = 0; i < n; i++) { idxByA.add(i); idxByB.add(i); } boolean[] visited = new boolean[n]; visited[imaxa] = visited[imaxb] = true; while (!q.isEmpty()) { int idx = q.removeFirst(); int ai = a[idx]; int bi = b[idx]; while (!idxByA.isEmpty() && a[idxByA.last()] > ai) { int v = idxByA.last(); idxByA.remove(v); if (!visited[v]) { visited[v] = true; q.addLast(v); ans[v] = true; } } while (!idxByB.isEmpty() && b[idxByB.last()] > bi) { int v = idxByB.last(); idxByB.remove(v); if (!visited[v]) { visited[v] = true; q.addLast(v); ans[v] = true; } } } for (boolean bb : ans) pw.print(bb ? "1" : "0"); pw.println(); } } // IMPORTANT // DID YOU CHECK THE COMMON MISTAKES ABOVE? // Template code below BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws IOException { Main m = new Main(); m.solve(); m.close(); } void close() throws IOException { pw.flush(); pw.close(); br.close(); } int ri() throws IOException { return Integer.parseInt(br.readLine().trim()); } long rl() throws IOException { return Long.parseLong(br.readLine().trim()); } int[] ril(int n) throws IOException { int[] nums = new int[n]; int c = 0; for (int i = 0; i < n; i++) { int sign = 1; c = br.read(); int x = 0; if (c == '-') { sign = -1; c = br.read(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } nums[i] = x * sign; } while (c != '\n' && c != -1) c = br.read(); return nums; } long[] rll(int n) throws IOException { long[] nums = new long[n]; int c = 0; for (int i = 0; i < n; i++) { int sign = 1; c = br.read(); long x = 0; if (c == '-') { sign = -1; c = br.read(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } nums[i] = x * sign; } while (c != '\n' && c != -1) c = br.read(); return nums; } int[] rkil() throws IOException { int sign = 1; int c = br.read(); int x = 0; if (c == '-') { sign = -1; c = br.read(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } return ril(x); } long[] rkll() throws IOException { int sign = 1; int c = br.read(); int x = 0; if (c == '-') { sign = -1; c = br.read(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } return rll(x); } char[] rs() throws IOException { return br.readLine().toCharArray(); } void sort(int[] A) { Random r = new Random(); for (int i = A.length-1; i > 0; i--) { int j = r.nextInt(i+1); int temp = A[i]; A[i] = A[j]; A[j] = temp; } Arrays.sort(A); } void printDouble(double d) { pw.printf("%.16f", d); } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
b1e6fee33afdbc3f7841b5aea8ebfa56
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; /** * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools * * To modify the template, go to Preferences -> Editor -> File and Code Templates -> Other */ public class Main { public static void main(String[] args) { int t = fs.nextInt(); while (t-- >0) { int n = fs.nextInt(); int[] a = fs.readArray(n); int[] b = fs.readArray(n); boolean[] ans = whoCanWin(n, a, b); for (boolean x: ans) { o.format("%d", x ? 1 : 0); } o.println(); } o.flush(); } private static boolean[] whoCanWin(int n, int[] a, int[] b) { List<Integer> playersByRankA = new ArrayList<>(); for (int i = 0; i<n; i++) playersByRankA.add(i); List<Integer> playersByRankB = new ArrayList<>(playersByRankA); Collections.sort(playersByRankA, Comparator.comparingInt(x -> a[x])); Collections.sort(playersByRankB, Comparator.comparingInt(x -> b[x])); boolean[] has = new boolean[n]; // has[x] = true if we saw x exactly once int discrepancy = 0; // the count of x such that has[x] = true int bottomIdx = -1; for (int i = n-1; i>=0; i--) { int x = playersByRankA.get(i), y = playersByRankB.get(i); has[x] = !has[x]; if (has[x]) { discrepancy++; } else { discrepancy--; } has[y] = !has[y]; if (has[y]) { discrepancy++; } else { discrepancy--; } if (discrepancy==0) { bottomIdx = i; break; } } // found minimal bottmIdx such that playersByRankA[bottomIdx,n) // equals (set-wise) playersByRankB[bottomIdx,n) // assert (bottomIdx > -1); boolean[] ans = new boolean[n]; for (int i = 0; i<n; i++) { if (i<bottomIdx) { ans[playersByRankA.get(i)] = false; } else { ans[playersByRankA.get(i)] = true; } } return ans; } static FastScanner fs = new FastScanner(); static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } static PrintWriter o = new PrintWriter(new OutputStreamWriter(System.out)); }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
dab544a1697d7734c237c005129fc3cb
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); StringBuilder sb = new StringBuilder(); for(int t = 0; t < T; ++t) { int n = in.nextInt(); int[] ans = new int[n]; Arrays.fill(ans, 0); int[][] a = new int[n][2]; int[][] b = new int[n][2]; for(int i = 0; i < n; ++i) a[i] = new int[] {in.nextInt(), i}; for(int i = 0; i < n; ++i) b[i] = new int[] {in.nextInt(), i}; Arrays.sort(a, (int[] x, int[] y) -> { if(x[0] > y[0]) return -1; else return 1; }); Arrays.sort(b, (int[] x, int[] y) -> { if(x[0] > y[0]) return -1; else return 1; }); Set<Integer> s = new HashSet<>(); int[] freq = new int[n]; for(int i = 0; i < n; ++i) { int ind1 = a[i][1]; freq[ind1] += 1; s.add(ind1); int ind2 = b[i][1]; freq[ind2] -= 1; s.add(ind2); if(freq[ind1] == 0) s.remove(ind1); if(freq[ind2] == 0) s.remove(ind2); if(s.isEmpty()) { for(int j = 0; j <= i; ++j) { ans[a[j][1]] = 1; } break; } } for(int i = 0; i < n; ++i) { sb.append(ans[i]); } sb.append("\n"); } System.out.print(sb.toString()); } private static void populate(int[] arr, StringBuilder sb) { for(int ele : arr) { sb.append(ele + " "); } sb.append("\n"); } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
ff85e67e333f1ffd4d15e028f9d9aea5
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; import java.time.*; import static java.lang.Math.*; @SuppressWarnings("unused") public class C { static boolean DEBUG = false; static Reader fs; static PrintWriter pw; static void solve() { int n = fs.nextInt(), a[] = fs.readArray(n), b[] = fs.readArray(n); ArrayList<pair> a_ = new ArrayList<pair>(); ArrayList<pair> b_ = new ArrayList<pair>(); for (int i = 0; i < n; i++) { a_.add(new pair(a[i], i)); b_.add(new pair(b[i], i)); } Collections.sort(a_); Collections.sort(b_); int ans[] = new int[n]; Comparator<Integer> reverse = (p1, p2) -> p1 > p2 ? -1 : 1; PriorityQueue<Integer> pq_a = new PriorityQueue<Integer>(); PriorityQueue<Integer> pq_b = new PriorityQueue<Integer>(); ans[a_.get(n-1).s] = 1; ans[b_.get(n-1).s] = 1; pq_a.add(a[a_.get(n-1).s]); pq_a.add(a[b_.get(n-1).s]); pq_b.add(b[a_.get(n-1).s]); pq_b.add(b[b_.get(n-1).s]); for(int i = n-2 ; i >= 0 ; i--) { int a_cur = a_.get(i).s; int b_cur = b_.get(i).s; if(b[a_cur] > pq_b.peek() || a[a_cur] > pq_a.peek()) { ans[a_cur] = 1; pq_b.add(b[a_cur]); pq_a.add(a[a_cur]); if(a[a_cur] < a[b_cur] || b[a_cur] < b[a_cur]) { ans[b_cur] = 1; pq_b.add(b[b_cur]); pq_a.add(a[b_cur]); } } if(a[b_cur] > pq_a.peek() || b[b_cur] > pq_b.peek()) { ans[b_cur] = 1; pq_b.add(b[b_cur]); pq_a.add(a[b_cur]); if(a[a_cur] > a[b_cur] || b[a_cur] > b[a_cur]) { ans[a_cur] = 1; pq_b.add(b[a_cur]); pq_a.add(a[a_cur]); } } } for (int x : ans) pw.print(x); pw.println(); } static class pair implements Comparable<pair> { int f, s; pair(int f, int s) { this.f = f; this.s = s; } @Override public int compareTo(C.pair o) { if (o.f < f) { return 1; } return -1; } } public static void main(String[] args) throws IOException { Instant start = Instant.now(); if (args.length == 2) { System.setIn(new FileInputStream(new File("D:\\program\\javaCPEclipse\\CodeForces\\src\\input.txt"))); // System.setOut(new PrintStream(new File("output.txt"))); System.setErr(new PrintStream(new File("D:\\program\\javaCPEclipse\\CodeForces\\src\\error.txt"))); DEBUG = true; } fs = new Reader(); pw = new PrintWriter(System.out); int t = fs.nextInt(); while (t-- > 0) { solve(); } Instant end = Instant.now(); if (DEBUG) { pw.println(Duration.between(start, end)); } pw.close(); } public static void print(long a, long b, long c, PrintWriter pw) { pw.println(a + " " + b + " " + c); return; } static class Reader { BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int[][] read2Array(int n, int m) { int a[][] = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = nextInt(); } } return a; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
b0b3c2313308de3c5780cbd4fd3edd1d
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; import java.util.*; public class Main { public static void main(String[] args) { // write your code here boolean readFromLocal = true; //readFromLocal = false; String filepath = "src/input.txt"; //FileInputStream fileInputStream = new FileInputStream(filepath); InputReader inputReader = new InputReader(System.in); Solve s = new Solve(); s.solve(inputReader); } } class Solve { public void solve(InputReader inputReader) { int t = inputReader.nextInt(); long mod = 1000_000_000 + 9; Pair[] mapA = new Pair[100_000 + 5]; Pair[] mapB = new Pair[100_000 + 5]; while (t > 0) { t--; int n = inputReader.nextInt(); for (int i = 0; i < n; i++) { mapA[i] = new Pair(i+1, inputReader.nextInt()); } for (int i = 0; i < n; i++) { mapB[i] = new Pair(i+1,inputReader.nextInt()); } Arrays.sort(mapA,0,n); Arrays.sort(mapB,0,n); Graph graph = new Graph(n); for(int i=1;i<n;i++) { graph.addEdge(mapA[i-1].first, mapA[i].first, false); graph.addEdge(mapB[i-1].first, mapB[i].first, false); } graph.dfs(mapA[n-1].first); char[] res = new char[n]; for (int i = 1; i <= n; i++) { res[i-1] = graph.vis[i]? '1':'0'; graph.vis[i] = false; } graph.dfs(mapB[n-1].first); for (int i = 0; i < n; i++) { if(res[i]=='0' && graph.vis[i+1]){ res[i] = '1'; } } System.out.println(res); } } } class Graph { private ArrayList<Integer>[] adj; int size; boolean[] vis; Graph(int n){ this.size = n; this.adj = new ArrayList[n+1]; this.vis = new boolean[n+1]; for (int i = 0; i <=n; i++) { adj[i] = new ArrayList<>(); } } public void addEdge(int a, int b, boolean biDirectional){ adj[a].add(b); if (biDirectional) { adj[b].add(a); } } public void dfs(int node){ this.vis[node] = true; for(int child : adj[node]) { if (this.vis[child]){ continue; } dfs(child); } } } class Pair implements Comparable<Pair> { int first,second; public Pair(int first, int second) { this.first = first; this.second = second; } @Override public int compareTo(Pair o) { return this.second - o.second; } } class Utils { static void swap(int[] res, int i, int j) { int temp = res[i]; res[i] = res[j]; res[j] = temp; } static long pow(long num, int n, long mod) { long res = num%mod; while (n > 0) { if ((n & 1) != 0) { res = (res * num) % mod; } num = (num * num) % mod; n >>= 1; } return res; } } class InputReader { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int peek() { if (numChars == -1) { return -1; } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) { return -1; } } return buf[curChar]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') { buf.appendCodePoint(c); } c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) { s = readLine0(); } return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) { return readLine(); } else { return readLine0(); } } public BigInteger readBigInteger() { try { return new BigInteger(nextString()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char nextCharacter() { int c = read(); while (isSpaceChar(c)) { c = read(); } return (char) c; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) { read(); } return value == -1; } public String next() { return nextString(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } public interface SpaceCharFilter { boolean isSpaceChar(int ch); } public int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; ++i) array[i] = nextInt(); return array; } public int[] nextSortedIntArray(int n) { int[] array = nextIntArray(n); Arrays.sort(array); return array; } public int[] nextSumIntArray(int n) { int[] array = new int[n]; array[0] = nextInt(); for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt(); return array; } public long[] nextLongArray(int n) { long[] array = new long[n]; for (int i = 0; i < n; ++i) array[i] = nextLong(); return array; } public long[] nextSumLongArray(int n) { long[] array = new long[n]; array[0] = nextInt(); for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt(); return array; } public long[] nextSortedLongArray(int n) { long[] array = nextLongArray(n); Arrays.sort(array); return array; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
da01b8ad57e1d014e09664ff7dd8aff1
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; import java.util.*; public class Main { public static void main(String[] args) { // write your code here boolean readFromLocal = true; //readFromLocal = false; String filepath = "src/input.txt"; //FileInputStream fileInputStream = new FileInputStream(filepath); InputReader inputReader = new InputReader(System.in); Solve s = new Solve(); s.solve(inputReader); } } class Solve { public void solve(InputReader inputReader) { int t = inputReader.nextInt(); long mod = 1000_000_000 + 9; Pair[] mapA = new Pair[100_000 + 5]; Pair[] mapB = new Pair[100_000 + 5]; while (t > 0) { t--; int n = inputReader.nextInt(); for (int i = 0; i < n; i++) { mapA[i] = new Pair(i+1, inputReader.nextInt()); } for (int i = 0; i < n; i++) { mapB[i] = new Pair(i+1,inputReader.nextInt()); } Arrays.sort(mapA,0,n); Arrays.sort(mapB,0,n); Graph graph = new Graph(n); for(int i=1;i<n;i++) { graph.addEdge(mapA[i-1].first, mapA[i].first, false); graph.addEdge(mapB[i-1].first, mapB[i].first, false); } graph.dfs(mapA[n-1].first); char[] res = new char[n]; for (int i = 1; i <= n; i++) { res[i-1] = graph.vis[i]? '1':'0'; } System.out.println(res); } } } class Graph { private ArrayList<Integer>[] adj; int size; boolean[] vis; Graph(int n){ this.size = n; this.adj = new ArrayList[n+1]; this.vis = new boolean[n+1]; for (int i = 0; i <=n; i++) { adj[i] = new ArrayList<>(); } } public void addEdge(int a, int b, boolean biDirectional){ adj[a].add(b); if (biDirectional) { adj[b].add(a); } } public void dfs(int node){ this.vis[node] = true; for(int child : adj[node]) { if (this.vis[child]){ continue; } dfs(child); } } } class Pair implements Comparable<Pair> { int first,second; public Pair(int first, int second) { this.first = first; this.second = second; } @Override public int compareTo(Pair o) { return this.second - o.second; } } class Utils { static void swap(int[] res, int i, int j) { int temp = res[i]; res[i] = res[j]; res[j] = temp; } static long pow(long num, int n, long mod) { long res = num%mod; while (n > 0) { if ((n & 1) != 0) { res = (res * num) % mod; } num = (num * num) % mod; n >>= 1; } return res; } } class InputReader { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int peek() { if (numChars == -1) { return -1; } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) { return -1; } } return buf[curChar]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') { buf.appendCodePoint(c); } c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) { s = readLine0(); } return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) { return readLine(); } else { return readLine0(); } } public BigInteger readBigInteger() { try { return new BigInteger(nextString()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char nextCharacter() { int c = read(); while (isSpaceChar(c)) { c = read(); } return (char) c; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) { read(); } return value == -1; } public String next() { return nextString(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } public interface SpaceCharFilter { boolean isSpaceChar(int ch); } public int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; ++i) array[i] = nextInt(); return array; } public int[] nextSortedIntArray(int n) { int[] array = nextIntArray(n); Arrays.sort(array); return array; } public int[] nextSumIntArray(int n) { int[] array = new int[n]; array[0] = nextInt(); for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt(); return array; } public long[] nextLongArray(int n) { long[] array = new long[n]; for (int i = 0; i < n; ++i) array[i] = nextLong(); return array; } public long[] nextSumLongArray(int n) { long[] array = new long[n]; array[0] = nextInt(); for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt(); return array; } public long[] nextSortedLongArray(int n) { long[] array = nextLongArray(n); Arrays.sort(array); return array; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
a632dba1b0a73b2627d4f5d7fc7eb455
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import static java.lang.System.out; import java.util.*; import java.io.*; import java.math.*; /* -> Give your 100%, that's it! -> Rules To Solve Any Problem: 1. Read the problem. 2. Think About It. 3. Solve it! */ public class Template { static int mod = 1000000007; public static void main(String[] args){ FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int yo = sc.nextInt(); while (yo-- > 0) { int n = sc.nextInt(); int[] a = sc.readInts(n); int[] b = sc.readInts(n); Map<Integer,Integer> map1 = new HashMap<>(); Map<Integer,Integer> map2 = new HashMap<>(); for(int i = 0; i < n; i++){ map1.put(a[i],i); map2.put(b[i],i); } sort(a); sort(b); List<List<Integer>> list = new ArrayList<>(); for(int i = 0; i < n; i++){ list.add(new ArrayList<>()); } for(int i = 0; i < n-1; i++){ int i1 = map1.get(a[i]); list.get(i1).add(map1.get(a[i+1])); int i2 = map2.get(b[i]); list.get(i2).add(map2.get(b[i+1])); } boolean[] vis = new boolean[n]; dfs(list,map1.get(a[n-1]),vis); StringBuilder sb = new StringBuilder(); for(int i = 0; i < n; i++){ if(vis[i]) sb.append("1"); else sb.append("0"); } out.println(sb.toString()); } out.close(); } static void dfs(List<List<Integer>> list, int curr, boolean[] vis){ List<Integer> neighbours = list.get(curr); vis[curr] = true; for(int e : neighbours){ if(vis[e]){ continue; } dfs(list,e,vis); } } /* Source: hu_tao Random stuff to try when stuck: - use bruteforcer - check for n = 1, n = 2, so on -if it's 2C then it's dp -for combo/probability problems, expand the given form we're interested in -make everything the same then build an answer (constructive, make everything 0 then do something) -something appears in parts of 2 --> model as graph -assume a greedy then try to show why it works -find way to simplify into one variable if multiple exist -treat it like fmc (note any passing thoughts/algo that could be used so you can revisit them) -find lower and upper bounds on answer -figure out what ur trying to find and isolate it -see what observations you have and come up with more continuations -work backwards (in constructive, go from the goal to the start) -turn into prefix/suffix sum argument (often works if problem revolves around adjacent array elements) -instead of solving for answer, try solving for complement (ex, find n-(min) instead of max) -draw something -simulate a process -dont implement something unless if ur fairly confident its correct -after 3 bad submissions move on to next problem if applicable -do something instead of nothing and stay organized -write stuff down Random stuff to check when wa: -if code is way too long/cancer then reassess -switched N/M -int overflow -switched variables -wrong MOD -hardcoded edge case incorrectly Random stuff to check when tle: -continue instead of break -condition in for/while loop bad Random stuff to check when rte: -switched N/M -long to int/int overflow -division by 0 -edge case for empty list/data structure/N=1 */ public static class Pair { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void sort(int[] arr) { ArrayList<Integer> ls = new ArrayList<Integer>(); for (int x : arr) ls.add(x); Collections.sort(ls); for (int i = 0; i < arr.length; i++) arr[i] = ls.get(i); } public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static boolean[] sieve(int N) { boolean[] sieve = new boolean[N + 1]; for (int i = 2; i <= N; i++) sieve[i] = true; for (int i = 2; i <= N; i++) { if (sieve[i]) { for (int j = 2 * i; j <= N; j += i) { sieve[j] = false; } } } return sieve; } public static long power(long x, long y, long p) { long res = 1L; x = x % p; while (y > 0) { if ((y & 1) == 1) res = (res * x) % p; y >>= 1; x = (x * x) % p; } return res; } public static void print(int[] arr, PrintWriter out) { //for debugging only for (int x : arr) out.print(x + " "); out.println(); } public static int log2(int a){ return (int)(Math.log(a)/Math.log(2)); } public static long ceil(long x, long y){ return (x + 0l + y - 1) / y; } static class FastScanner { private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] readInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] readLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] readDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } // For Input.txt and Output.txt // FileInputStream in = new FileInputStream("input.txt"); // FileOutputStream out = new FileOutputStream("output.txt"); // PrintWriter pw = new PrintWriter(out); // Scanner sc = new Scanner(in); }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
e8e17577ced9c6b1809e0dc8f6610b0f
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef {static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // static int mod = 998244353 ; // static int N = 200005; // static long factorial_num_inv[] = new long[N+1]; // static long natual_num_inv[] = new long[N+1]; // static long fact[] = new long[N+1]; // static void InverseofNumber() //{ // natual_num_inv[0] = 1; // natual_num_inv[1] = 1; // for (int i = 2; i <= N; i++) // natual_num_inv[i] = natual_num_inv[mod % i] * (mod - mod / i) % mod; //} //static void InverseofFactorial() //{ // factorial_num_inv[0] = factorial_num_inv[1] = 1; // for (int i = 2; i <= N; i++) // factorial_num_inv[i] = (natual_num_inv[i] * factorial_num_inv[i - 1]) % mod; //} //static long nCrModP(long N, long R) //{ // long ans = ((fact[(int)N] * factorial_num_inv[(int)R]) % mod * factorial_num_inv[(int)(N - R)]) % mod; // return ans%mod; //} //static boolean prime[]; //static void sieveOfEratosthenes(int n) //{ // prime = new boolean[n+1]; // for (int i = 0; i <= n; i++) // prime[i] = true; // for (int p = 2; p * p <= n; p++) // { // // If prime[p] is not changed, then it is a // // prime // if (prime[p] == true) // { // // Update all multiples of p // for (int i = p * p; i <= n; i += p) // prime[i] = false; // } // } //} static int visited[]; public static void main (String[] args) throws java.lang.Exception { // InverseofNumber(); // InverseofFactorial(); // fact[0] = 1; // for (long i = 1; i <= 2*100000; i++) // { // fact[(int)i] = (fact[(int)i - 1] * i) % mod; // } FastReader scan = new FastReader(); PrintWriter pw = new PrintWriter(System.out); int t = scan.nextInt(); while(t-->0){ int n = scan.nextInt(); visited = new int[n]; Pair a[] = new Pair[n]; Pair b[] = new Pair[n]; int max = 0,max_index = 0; for(int i=0;i<n;i++){ int val = scan.nextInt(); if(val>max){ max = val; max_index = i; } a[i] = new Pair(i,val); } for(int i=0;i<n;i++){ int val = scan.nextInt(); b[i] = new Pair(i,val); } Arrays.sort(a,new Compar()); Arrays.sort(b,new Compar()); List<List<Integer>> graph = new ArrayList<List<Integer>>(); for(int i=0;i<=n;i++){ graph.add(new ArrayList<Integer>()); } for(int i=0;i<n-1;i++){ graph.get(a[i].x).add(a[i+1].x); graph.get(b[i].x).add(b[i+1].x); } visited[max_index] = 1; dfs(max_index,graph); for(int i=0;i<n;i++){ pw.print(visited[i]); } pw.println(); pw.flush(); } } static void dfs(int max,List<List<Integer>> graph){ List<Integer> temp = graph.get(max); int n = temp.size(); for(int i=0;i<n;i++){ int index = temp.get(i); if(visited[index]==0){ visited[index] = 1; dfs(index,graph); } } } //static long bin_exp_mod(long a,long n){ // long res = 1; // if(a==0) // return 0; // while(n!=0){ // if(n%2==1){ // res = ((res)*(a)); // } // n = n/2; // a = ((a)*(a)); // } // return res; //} //static long bin_exp_mod(long a,long n){ // long mod = 998244353; // long res = 1; // a = a%mod; // if(a==0) // return 0; // while(n!=0){ // if(n%2==1){ // res = ((res%mod)*(a%mod))%mod; // } // n = n/2; // a = ((a%mod)*(a%mod))%mod; // } // res = res%mod; // return res; //} // static long gcd(long a,long b){ // if(a==0) // return b; // return gcd(b%a,a); // } // static long lcm(long a,long b){ // return (a/gcd(a,b))*b; // } } class Pair{ int x,y; Pair(int x,int y){ this.x = x; this.y = y; } } // public boolean equals(Object obj) { // // TODO Auto-generated method stub // if(obj instanceof Pair) // { // Pair temp = (Pair) obj; // if(this.x.equals(temp.x) && this.y.equals(temp.y)) // return true; // } // return false; // } // @Override // public int hashCode() { // // TODO Auto-generated method stub // return (this.x.hashCode() + this.y.hashCode()); // } //} class Compar implements Comparator<Pair>{ public int compare(Pair p1,Pair p2){ if(p1.y>p2.y) return 1; else return -1; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
369fb5e2680ee547efe0ce8d29e1463f
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class Solution extends PrintWriter { void solve() { int t = sc.nextInt(); for(int i = 1; i <= t; i++) { test_case(); } } void test_case() { int n = sc.nextInt(); int[][] a = new int[n][]; for(int i = 0; i < n; i++) { a[i] = new int[] {i, sc.nextInt()}; } int[][] b = new int[n][]; for(int i = 0; i < n; i++) { b[i] = new int[] {i, sc.nextInt()}; } Arrays.sort(a, Comparator.comparing(arr -> arr[1])); Arrays.sort(b, Comparator.comparing(arr -> arr[1])); boolean[] done = new boolean[n]; int sum = 0; boolean[] ans = new boolean[n]; for(int i = n-1; i >= 0; i--) { done[a[i][0]] = !done[a[i][0]]; if(done[a[i][0]]) sum++; else sum--; done[b[i][0]] = !done[b[i][0]]; if(done[b[i][0]]) sum++; else sum--; if(sum == 0) { for(int j = i; j < n; j++) ans[a[j][0]] = true; break; } } for(int i = 0; i < n; i++) { print(ans[i]?1:0); } println(); } // Main() throws FileNotFoundException { super(new File("output.txt")); } // InputReader sc = new InputReader(new FileInputStream("test_input.txt")); Solution() { super(System.out); } InputReader sc = new InputReader(System.in); static class InputReader { InputReader(InputStream in) { this.in = in; } InputStream in; private byte[] buf = new byte[16384]; private int curChar; private int numChars; public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = in.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } /* private String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); }*/ public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } public static void main(String[] $) { new Thread(null, new Runnable() { public void run() { long start = System.nanoTime(); try {Solution solution = new Solution(); solution.solve(); solution.flush();} catch (Exception e) {e.printStackTrace(); System.exit(1);} System.err.println((System.nanoTime()-start)/1E9); } }, "1", 1 << 27).start(); } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
ff4f45c0e9f333e3226df76c20491307
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class Codeforces { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int t=Integer.parseInt(bu.readLine()); while(t-->0) { int n=Integer.parseInt(bu.readLine()); String s[]=bu.readLine().split(" "); int a[][]=new int[n][3],i; for(i=0;i<n;i++) a[i][0]=Integer.parseInt(s[i]); s=bu.readLine().split(" "); HashMap<Integer,Integer> hm=new HashMap<>(); PriorityQueue<Integer> sorter=new PriorityQueue<>(); for(i=0;i<n;i++) { a[i][1]=Integer.parseInt(s[i]); a[i][2]=i; if(hm.get(a[i][1])==null) { hm.put(a[i][1],0); sorter.add(a[i][1]); } } for(i=0;i<n;i++) hm.put(sorter.poll(),i); PriorityQueue<int[]> pq=new PriorityQueue<>(new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2) { if(o1[0]>o2[0]) return 1; else return -1; }}); for(i=0;i<n;i++) pq.add(new int[]{a[i][0],hm.get(a[i][1]),a[i][2]}); int max[]=new int[n]; for(i=0;i<n;i++) { a[i]=pq.poll(); max[i]=a[i][1]; if(i>0) max[i]=Math.max(max[i],max[i-1]); } int ans[]=new int[n]; bit=new int[n+1]; ans[a[n-1][2]]=1; update(a[n-1][1],n); for(i=n-2;i>=0;i--) { //System.out.println(max[i]+" "+query(max[i])); if(query(max[i])>0) {update(a[i][1],n); ans[a[i][2]]=1;} } for(i=0;i<n;i++) sb.append(ans[i]); sb.append("\n"); } System.out.print(sb); } static int bit[]; static void update(int i,int n) { i++; while(i<=n) { bit[i]++; i+=i&-i; } } static int query(int i) { int s=0; i++; while(i>0) { s+=bit[i]; i-=i&-i; } return s; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
33fdf493d63b19a06f890d5581edda0e
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class q3 { public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // public static long mod = 1000000007; public static class Pair{ int i; int a; int b; Pair(int i,int a){ this.i = i; this.a = a; } } public static void solve() throws Exception { String[] parts = br.readLine().split(" "); int n = Integer.parseInt(parts[0]); Pair[] arr = new Pair[n]; parts = br.readLine().split(" "); for (int i = 0; i < n; i++) { arr[i] = new Pair(i,Integer.parseInt(parts[i])); } parts = br.readLine().split(" "); for (int i = 0; i < n; i++) { arr[i].b = Integer.parseInt(parts[i]); } Arrays.sort(arr,(x,y) -> { return y.b - x.b; }); int[] ans = new int[n]; Arrays.fill(ans,0); ans[arr[0].i] = 1; int min = arr[0].a; for(int i = 1;i < n;i++){ if(arr[i].a > min){ for(int j = i;j >= 0 && ans[arr[j].i] == 0;j--){ ans[arr[j].i] = 1; min = Math.min(min,arr[j].a); } } } StringBuilder sb = new StringBuilder(); for(int val : ans) sb.append(val); System.out.println(sb); } public static void main(String[] args) throws Exception { int tests = Integer.parseInt(br.readLine()); for (int test = 1; test <= tests; test++) { solve(); } } // public static void sort(int[] arr){ // ArrayList<Integer> temp = new ArrayList<>(); // for(int val : arr) temp.add(val); // // Collections.sort(temp); // // for(int i = 0;i < arr.length;i++) arr[i] = temp.get(i); // } // public static void sort(long[] arr){ // ArrayList<Long> temp = new ArrayList<>(); // for(long val : arr) temp.add(val); // // Collections.sort(temp); // // for(int i = 0;i < arr.length;i++) arr[i] = temp.get(i); // } // // public static long power(long a,long b,long mod){ // if(b == 0) return 1; // // long p = power(a,b / 2,mod); // p = (p * p) % mod; // // if(b % 2 == 1) return (p * a) % mod; // return p; // } // // public static int GCD(int a,int b){ // return b == 0 ? a : GCD(b,a % b); // } // public static long GCD(long a,long b){ // return b == 0 ? a : GCD(b,a % b); // } // // public static int LCM(int a,int b){ // return a * b / GCD(a,b); // } // public static long LCM(long a,long b){ // return a * b / GCD(a,b); // } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
9ccfa57e0cb1a0c50ee632b16d64d1df
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
//some updates in import stuff import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; public class Main{ static int mod = (int) (Math.pow(10, 9)+7); static final int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 }; static final int[] dx8 = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy8 = { -1, 0, 1, -1, 1, -1, 0, 1 }; static final int[] dx9 = { -1, -1, -1, 0, 0, 0, 1, 1, 1 }, dy9 = { -1, 0, 1, -1, 0, 1, -1, 0, 1 }; static final double eps = 1e-10; static List<Integer> primeNumbers = new ArrayList<>(); public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); //code below int test = sc.nextInt(); while(test -- > 0){ int n = sc.nextInt(); int[] one = new int[n]; int[] two = new int[n]; ArrayList<Pair> onee = new ArrayList<>(); ArrayList<Pair> twoo = new ArrayList<>(); Set<Integer> winner = new HashSet<>(); for(int i = 0; i < n; i++){ one[i] = sc.nextInt(); onee.add(new Pair(i+1, one[i])); } for(int i = 0; i < n; i++){ two[i] = sc.nextInt(); twoo.add(new Pair(i+1, two[i])); } Collections.sort(onee, (a,b) -> Integer.compare(b.b, a.b)); Collections.sort(twoo, (a,b) -> Integer.compare(b.b, a.b)); Map<Integer, Integer> map1 = new HashMap<>(); Map<Integer, Integer> map2 = new HashMap<>(); for(int i = 0; i < n; i++){ map1.put(onee.get(i).a, i); map2.put(twoo.get(i).a, i); } //keep pushing both sides until you face stopage while switching int upar = 0; int niche = 0; winner.add(onee.get(0).a); winner.add(twoo.get(0).a); upar = map1.get(twoo.get(0).a); niche = map2.get(onee.get(0).a); int l = 1; int r = 1; while(true){ int count = 0; for(; l < upar; l++){ count++; int curr = onee.get(l).a; if(winner.contains(curr)) continue; //otherwise winner.add(curr); niche = max(map2.get(curr), niche); } for(; r < niche; r++){ count++; int curr = twoo.get(r).a; if(winner.contains(twoo.get(r).a)) continue; winner.add(curr); upar = max(map1.get(curr), upar); } if(count == 0) break; } int[] answer = new int[n]; for(int i = 0; i < n;i++){ answer[i] = winner.contains(i+1) ? 1 : 0; } for(int i : answer){ out.print(i); } out.println(); //sort all of them } out.close(); } //Updation Required //Fenwick Tree (customisable) //Segment Tree (customisable) //-----CURRENTLY PRESENT-------// //Graph //DSU //powerMODe //power //Segment Tree (work on this one) //Prime Sieve //Count Divisors //Next Permutation //Get NCR //isVowel //Sort (int) //Sort (long) //Binomial Coefficient //Pair //Triplet //lcm (int & long) //gcd (int & long) //gcd (for binomial coefficient) //swap (int & char) //reverse //Fast input and output //------------------------------------------------------------------- //------------------------------------------------------------------- //------------------------------------------------------------------- //------------------------------------------------------------------- //------------------------------------------------------------------- //GRAPH (basic structure) public static class Graph{ public int V; public ArrayList<ArrayList<Integer>> edges; //2 -> [0,1,2] (current) Graph(int V){ this.V = V; edges = new ArrayList<>(V+1); for(int i= 0; i <= V; i++){ edges.add(new ArrayList<>()); } } public void addEdge(int from , int to){ edges.get(from).add(to); } } //DSU (path and rank optimised) public static class DisjointUnionSets { int[] rank, parent; int n; public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; Arrays.fill(rank, 1); Arrays.fill(parent,-1); this.n = n; } public int find(int curr){ if(parent[curr] == -1) return curr; //path compression optimisation return parent[curr] = find(parent[curr]); } public void union(int a, int b){ int s1 = find(a); int s2 = find(b); if(s1 != s2){ if(rank[s1] < rank[s2]){ parent[s1] = s2; rank[s2] += rank[s1]; }else{ parent[s2] = s1; rank[s1] += rank[s2]; } } } } //with mod public static long powerMOD(long x, long y) { long res = 1L; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0){ x %= mod; res %= mod; res = (res * x)%mod; } // y must be even now y = y >> 1; // y = y/2 x%= mod; x = (x * x)%mod; // Change x to x^2 } return res%mod; } //without mod public static long power(long x, long y) { long res = 1L; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0){ res = (res * x); } // y must be even now y = y >> 1; // y = y/ x = (x * x); } return res; } public static class segmentTree{ public long[] arr; public long[] tree; public long[] lazy; segmentTree(long[] array){ int n = array.length; arr = new long[n]; for(int i= 0; i < n; i++) arr[i] = array[i]; tree = new long[4*n + 1]; lazy = new long[4*n + 1]; } public void build(int[]arr, int s, int e, int[] tree, int index){ if(s == e){ tree[index] = arr[s]; return; } //otherwise divide in two parts and fill both sides simply int mid = (s+e)/2; build(arr, s, mid, tree, 2*index); build(arr, mid+1, e, tree, 2*index+1); //who will build the current position dude tree[index] = Math.min(tree[2*index], tree[2*index+1]); } public int query(int sr, int er, int sc, int ec, int index, int[] tree){ if(lazy[index] != 0){ tree[index] += lazy[index]; if(sc != ec){ lazy[2*index+1] += lazy[index]; lazy[2*index] += lazy[index]; } lazy[index] = 0; } //no overlap if(sr > ec || sc > er) return Integer.MAX_VALUE; //found the index baby if(sr <= sc && ec <= er) return tree[index]; //finding the index on both sides hehehehhe int mid = (sc + ec)/2; int left = query(sr, er, sc, mid, 2*index, tree); int right = query(sr, er, mid+1, ec, 2*index + 1, tree); return Integer.min(left, right); } //now we will do point update implementation //it should be simple then we expected for sure public void update(int index, int indexr, int increment, int[] tree, int s, int e){ if(lazy[index] != 0){ tree[index] += lazy[index]; if(s != e){ lazy[2*index+1] = lazy[index]; lazy[2*index] = lazy[index]; } lazy[index] = 0; } //no overlap if(indexr < s || indexr > e) return; //found the required index if(s == e){ tree[index] += increment; return; } //search for the index on both sides int mid = (s+e)/2; update(2*index, indexr, increment, tree, s, mid); update(2*index+1, indexr, increment, tree, mid+1, e); //now update the current range simply tree[index] = Math.min(tree[2*index+1], tree[2*index]); } public void rangeUpdate(int[] tree , int index, int s, int e, int sr, int er, int increment){ //if not at all in the same range if(e < sr || er < s) return; //complete then also move forward if(s == e){ tree[index] += increment; return; } //otherwise move in both subparts int mid = (s+e)/2; rangeUpdate(tree, 2*index, s, mid, sr, er, increment); rangeUpdate(tree, 2*index + 1, mid+1, e, sr, er, increment); //update current range too na //i always forget this step for some reasons hehehe, idiot tree[index] = Math.min(tree[2*index], tree[2*index + 1]); } public void rangeUpdateLazy(int[] tree, int index, int s, int e, int sr, int er, int increment){ //update lazy values //resolve lazy value before going down if(lazy[index] != 0){ tree[index] += lazy[index]; if(s != e){ lazy[2*index+1] += lazy[index]; lazy[2*index] += lazy[index]; } lazy[index] = 0; } //no overlap case if(sr > e || s > er) return; //complete overlap if(sr <= s && er >= e){ tree[index] += increment; if(s != e){ lazy[2*index+1] += increment; lazy[2*index] += increment; } return; } //otherwise go on both left and right side and do your shit int mid = (s + e)/2; rangeUpdateLazy(tree, 2*index, s, mid, sr, er, increment); rangeUpdateLazy(tree, 2*index + 1, mid+1, e, sr, er, increment); tree[index] = Math.min(tree[2*index+1], tree[2*index]); return; } } //prime sieve public static void primeSieve(int n){ BitSet bitset = new BitSet(n+1); for(long i = 0; i < n ; i++){ if (i == 0 || i == 1) { bitset.set((int) i); continue; } if(bitset.get((int) i)) continue; primeNumbers.add((int)i); for(long j = i; j <= n ; j+= i) bitset.set((int)j); } } //number of divisors public static int countDivisors(long number){ if(number == 1) return 1; List<Integer> primeFactors = new ArrayList<>(); int index = 0; long curr = primeNumbers.get(index); while(curr * curr <= number){ while(number % curr == 0){ number = number/curr; primeFactors.add((int) curr); } index++; curr = primeNumbers.get(index); } if(number != 1) primeFactors.add((int) number); int current = primeFactors.get(0); int totalDivisors = 1; int currentCount = 2; for (int i = 1; i < primeFactors.size(); i++) { if (primeFactors.get(i) == current) { currentCount++; } else { totalDivisors *= currentCount; currentCount = 2; current = primeFactors.get(i); } } totalDivisors *= currentCount; return totalDivisors; } //now adding next permutation function to java hehe public static boolean next_permutation(int[] p) { for (int a = p.length - 2; a >= 0; --a) if (p[a] < p[a + 1]) for (int b = p.length - 1;; --b) if (p[b] > p[a]) { int t = p[a]; p[a] = p[b]; p[b] = t; for (++a, b = p.length - 1; a < b; ++a, --b) { t = p[a]; p[a] = p[b]; p[b] = t; } return true; } return false; } //finding the value of NCR in O(RlogN) time and O(1) space public static long getNcR(int n, int r) { long p = 1, k = 1; if (n - r < r) r = n - r; if (r != 0) { while (r > 0) { p *= n; k *= r; long m = __gcd(p, k); p /= m; k /= m; n--; r--; } } else { p = 1; } return p; } //is vowel function public static boolean isVowel(char c) { return (c=='a' || c=='A' || c=='e' || c=='E' || c=='i' || c=='I' || c=='o' || c=='O' || c=='u' || c=='U'); } //to sort the array with better method public static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } //sort long public static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } //for calculating binomialCoeff public static int binomialCoeff(int n, int k) { int C[] = new int[k + 1]; // nC0 is 1 C[0] = 1; for (int i = 1; i <= n; i++) { // Compute next row of pascal // triangle using the previous row for (int j = Math.min(i, k); j > 0; j--) C[j] = C[j] + C[j - 1]; } return C[k]; } //Pair with int int public static class Pair{ public int a; public int b; Pair(int a , int b){ this.a = a; this.b = b; } @Override public String toString(){ return a + " -> " + b; } } //Triplet with int int int public static class Triplet{ public int a; public int b; public int c; Triplet(int a , int b, int c){ this.a = a; this.b = b; this.c = c; } @Override public String toString(){ return a + " -> " + b; } } //Shortcut function public static long lcm(long a , long b){ return a * (b/gcd(a,b)); } //let's make one for calculating lcm basically public static int lcm(int a , int b){ return (a * b)/gcd(a,b); } //int version for gcd public static int gcd(int a, int b){ if(b == 0) return a; return gcd(b , a%b); } //long version for gcd public static long gcd(long a, long b){ if(b == 0) return a; return gcd(b , a%b); } //for ncr calculator(ignore this code) public static long __gcd(long n1, long n2) { long gcd = 1; for (int i = 1; i <= n1 && i <= n2; ++i) { // Checks if i is factor of both integers if (n1 % i == 0 && n2 % i == 0) { gcd = i; } } return gcd; } //swapping two elements in an array public static void swap(int[] arr, int left , int right){ int temp = arr[left]; arr[left] = arr[right]; arr[right] = temp; } //for char array public static void swap(char[] arr, int left , int right){ char temp = arr[left]; arr[left] = arr[right]; arr[right] = temp; } //reversing an array public static void reverse(int[] arr){ int left = 0; int right = arr.length-1; while(left <= right){ swap(arr, left,right); left++; right--; } } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } //-------------------------------------------------------- }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
d107d4a0ee74e81c38ce26c4dbaf79e7
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.Comparator; import java.util.PriorityQueue; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws Exception { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(in, out); out.close(); } } class Task { int mod = 998244353; public void solve(InputReader in, PrintWriter out) throws Exception { int T = in.nextInt(); for (int tc = 1; tc <= T; tc++) { int n = in.nextInt(); Point[] ps = new Point[n]; PriorityQueue<Point> p1 = new PriorityQueue<>(new Comparator<Point>() { @Override public int compare(Point o1, Point o2) { return o2.a - o1.a; } }); PriorityQueue<Point> p2 = new PriorityQueue<>(new Comparator<Point>() { @Override public int compare(Point o1, Point o2) { return o2.b - o1.b; } }); char[] ans = new char[n]; Arrays.fill(ans, '0'); for (int i = 0; i < n; i++) { ps[i] = new Point(i); ps[i].a = in.nextInt(); } for (int i = 0; i < n; i++) { ps[i].b = in.nextInt(); } for (int i = 0; i < n; i++) { p1.add(ps[i]); p2.add(ps[i]); } Point p = p1.poll(); ans[p.id] = '1'; int mb = p.b; p = p2.poll(); ans[p.id] = '1'; int ma = p.a; while (true) { boolean flag = false; while (!p1.isEmpty() && (p1.peek().a > ma || p1.peek().b > mb)) { p = p1.poll(); ans[p.id] = '1'; ma = Math.min(ma, p.a); mb = Math.min(mb, p.b); flag = true; } while (!p2.isEmpty() && (p2.peek().a > ma || p2.peek().b > mb)) { p = p2.poll(); ans[p.id] = '1'; ma = Math.min(ma, p.a); mb = Math.min(mb, p.b); flag = true; } if (!flag) { break; } } out.println(ans); } } class Point { int a, b, id; public Point(int id) { this.id = id; } } } class InputReader { private final BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(nextLine()); } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
2806838b9d4023917776e37b0748f721
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class CF1562C extends PrintWriter { CF1562C() { super(System.out); } public static Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1562C o = new CF1562C(); o.main(); o.flush(); } static long calculate(long p, long q) { long mod = 1000000007, expo; expo = mod - 2; // Loop to find the value // until the expo is not zero while (expo != 0) { // Multiply p with q // if expo is odd if ((expo & 1) == 1) { p = (p * q) % mod; } q = (q * q) % mod; // Reduce the value of // expo by 2 expo >>= 1; } return p; } static String longestPalSubstr(String str) { // The result (length of LPS) int maxLength = 1; int start = 0; int len = str.length(); int low, high; // One by one consider every // character as center // point of even and length // palindromes for (int i = 1; i < len; ++i) { // Find the longest even // length palindrome with // center points as i-1 and i. low = i - 1; high = i; while (low >= 0 && high < len && str.charAt(low) == str.charAt(high)) { --low; ++high; } // Move back to the last possible valid palindrom substring // as that will anyway be the longest from above loop ++low; --high; if (str.charAt(low) == str.charAt(high) && high - low + 1 > maxLength) { start = low; maxLength = high - low + 1; } // Find the longest odd length // palindrome with center point as i low = i - 1; high = i + 1; while (low >= 0 && high < len && str.charAt(low) == str.charAt(high)) { --low; ++high; } // Move back to the last possible valid palindrom substring // as that will anyway be the longest from above loop ++low; --high; if (str.charAt(low) == str.charAt(high) && high - low + 1 > maxLength) { start = low; maxLength = high - low + 1; } } return str.substring(start, start + maxLength - 1); } long check(long a){ long ret=0; for(long k=2;(k*k*k)<=a;k++){ ret=ret+(a/(k*k*k)); } return ret; } /*public static int getFirstSetBitPos(int n) { return (int)((Math.log10(n & -n)) / Math.log10(2)) + 1; } public static int bfsq(int n, int m, HashMap<Integer,ArrayList<Integer>>h,boolean v ){ v[n]=true; if(n==m) return 1; else { int a=h.get(n).get(0); int b=h.get(n).get(1); if(b>m) return(m-n); else { int a1=bfsq(a,m,h,v); int b1=bfsq(b,m,h,v); return 1+Math.min(a1,b1); } } }*/ static long nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); } // Returns factorial of n static long fact(long n) { long res = 1; for (long i = 2; i <= n; i++) res = res * i; return res; } /*void bfs(int src, HashMap<Integer,ArrayList<Integer,Integer>>h,int deg, boolean v[] ){ a[src]=deg; Queue<Integer>= new LinkedList<Integer>(); q.add(src); while(!q.isEmpty()){ (int a:h.get(src)){ if() } } }*/ /* void dfs(int root, int par, HashMap<Integer,ArrayList<Integer>>h,int dp[], int child[]) { dp[root]=0; child[root]=1; for(int x: h.get(root)){ if(x == par) continue; dfs(x,root,h,in,dp); child[root]+=child[x]; } ArrayList<Integer> mine= new ArrayList<Integer>(); for(int x: h.get(root)) { if(x == par) continue; mine.add(x); } if(mine.size() >=2){ int y= Math.max(child[mine.get(0)] - 1 + dp[mine.get(1)] , child[mine.get(1)] -1 + dp[mine.get(0)]); dp[root]=y;} else if(mine.size() == 1) dp[root]=child[mine.get(0)] - 1; } */ class Pair implements Comparable<Pair>{ int i; int j; Pair (int a, int b){ i = a; j = b; } public int compareTo(Pair A){ return (int)(this.i-A.i); }} /*static class Pair { int i; int j; Pair() { } Pair(int i, int j) { this.i = i; this.j = j; } }*/ /*ArrayList<Integer> check(int a[], int b){ int n=a.length; long ans=0;int k=0; ArrayList<Integer>ab= new ArrayList<Integer>(); for(int i=0;i<n;i++){ if(a[i]%m==0) {k=a[i]; while(a[i]%m==0){ a[i]=a[i]/m; } for(int z=0;z<k/a[i];z++){ ab.add(a[i]); } } else{ ab.add(a[i]); } } return ab; } */ /*int check[]; int tree[]; static void build( int []arr) { // insert leaf nodes in tree for (int i = 0; i < n; i++) tree[n + i] = arr[i]; // build the tree by calculating // parents for (int i = n - 1; i > 0; --i){ int ans= Math.min(tree[i << 1], tree[i << 1 | 1]); int ans1=Math.max((tree[i << 1], tree[i << 1 | 1])); if(ans==0) } }*/ /*static void ab(long n) { // Note that this loop runs till square root for (long i=1; i<=Math.sqrt(n); i++) { if(i==1) { p.add(n/i); continue; } if (n%i==0) { // If divisors are equal, print only one if (n/i == i) p.add(i); else // Otherwise print both { p.add(i); p.add(n/i); } } } }*/ static int fin[]= new int[100001]; public static void dfs(int node,HashMap<Integer,HashSet<Integer>>ab, boolean v[]){ v[node]=true; for(int x:ab.get(node)){ if(!v[x]){ //System.out.println(x); fin[x]=1; dfs(x,ab,v); } } } void main() { int g=sc.nextInt(); int mod=1000000007; sc.nextLine(); for(int w=0;w<g;w++){ int n=sc.nextInt(); Arrays.fill(fin,0); int a[]= new int[n]; int b[]= new int[n]; for(int i=0;i<n;i++) a[i]=sc.nextInt(); for(int i=0;i<n;i++) b[i]=sc.nextInt(); ArrayList<Pair>x1= new ArrayList<Pair>(); ArrayList<Pair>x2= new ArrayList<Pair>(); for(int i=0;i<n;i++) x1.add(new Pair(a[i],i)); for(int i=0;i<n;i++) x2.add(new Pair(b[i],i)); Collections.sort(x1); Collections.sort(x2); int max1=x1.get(n-1).j; int max2=x2.get(n-1).j; // println(max1); // println(max2); HashMap<Integer,HashSet<Integer>>ab= new HashMap<Integer,HashSet<Integer>>(); for(int i=0;i<n;i++){ ab.put(i,new HashSet<Integer>()); } boolean v[]= new boolean[n]; for(int i=0;i<n-1;i++) ab.get(x1.get(i).j).add(x1.get(i+1).j); for(int i=0;i<n-1;i++) ab.get(x2.get(i).j).add(x2.get(i+1).j); //println(ab); fin[max1]=1; fin[max2]=1; v[max1]=true; v[max2]=true; dfs(max1,ab,v); dfs(max2,ab,v); for(int i=0;i<n;i++) print(fin[i]); println(""); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
d823a74cb79a89c9d162fc48f0538b23
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class Solution { public static long gcd(long a,long b) { if(a==0) return b; return gcd(b%a,a); } public static long lcm(long a,long b) { return (a*b)/gcd(a,b); } public static void main(String[] args) throws java.lang.Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); int testCases=Integer.parseInt(br.readLine()); while(testCases-->0) { int n=Integer.parseInt(br.readLine()); String input[]=br.readLine().split(" "); int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=Integer.parseInt(input[i]); } int b[]=new int[n]; input=br.readLine().split(" "); for(int i=0;i<n;i++) { b[i]=Integer.parseInt(input[i]); } List<int[]>list=new ArrayList<>(); for(int i=0;i<n;i++) { list.add(new int[] {a[i],b[i],i}); } Collections.sort(list,(c,d)->c[0]-d[0]); int ans[]=new int[n]; int left[]=new int[n]; int max=0; for(int i=0;i<n;i++) { max=Math.max(max, list.get(i)[1]); left[i]=max; } int min=list.get(n-1)[1]; ans[list.get(n-1)[2]]=1; for(int i=n-1;i>=0;i--) { if(left[i]>min) { ans[list.get(i)[2]]=1; min=Math.min(min, list.get(i)[1]); } } for(int i=0;i<n;i++) out.print(ans[i]); out.println(); } out.close(); } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
d441cdef2ca3efedffb46095ac9955f7
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); PrintWriter writer = new PrintWriter(System.out); long mod = 1000000007; int t = sc.nextInt(); while(t-->0) { int n =sc.nextInt(); ArrayList<ArrayList<Integer>> adj = new ArrayList<>(); for(int i = 0; i < n+1; i++)adj.add(new ArrayList<>()); ArrayList<Pair> list = new ArrayList<>(); for(int i = 1; i <= n; i++) { list.add(new Pair(i,sc.nextInt())); } ArrayList<Pair> list2 = new ArrayList<>(); for(int i = 1; i <= n; i++) { list2.add(new Pair(i,sc.nextInt())); } if(n==1)writer.println(1); else { Collections.sort(list, new Comparator<Pair>() { public int compare(Pair p1, Pair p2) { return Integer.compare(p2.b, p1.b); } }); Collections.sort(list2, new Comparator<Pair>() { public int compare(Pair p1, Pair p2) { return Integer.compare(p2.b, p1.b); } }); int max = 0; int maxInd = 0; for(int i = 1; i< n; i++) { Pair p1 = list.get(i-1); Pair p2 = list.get(i); Pair p3 = list2.get(i-1); Pair p4 = list2.get(i); adj.get(p2.a).add(p1.a); adj.get(p4.a).add(p3.a); if(max<p1.b) { max = p1.b; maxInd = p1.a; } if(max<p2.b) { max = p2.b; maxInd = p2.a; } if(max<p3.b) { max = p3.b; maxInd = p3.a; } if(max<p4.b) { max = p4.b; maxInd = p4.a; } } boolean visited[] = new boolean[n+1]; dfs(adj,maxInd,visited); for(int i = 1; i < n+1; i++) { if(visited[i])writer.print(1); else writer.print(0); } writer.println(); } } writer.flush(); writer.close(); } public static void dfs(ArrayList<ArrayList<Integer>> adj, int i, boolean visited[]) { visited[i]=true; for(int j : adj.get(i)) { if(!visited[j])dfs(adj,j,visited); } } private static long power (long a, long n, long p) { long res = 1; while(n!=0) { if(n%2==1) { res=(res*a)%p; n--; }else { a= (a*a)%p; n/=2; } } return res; } private static boolean isPrime(int c) { for (int i = 2; i*i <= c; i++) { if(c%i==0)return false; } return true; } private static int find(int a , int arr[]) { if(arr[a] != a) return arr[a] = find(arr[a], arr); return arr[a]; } private static void union(int a, int b, int arr[]) { int aa = find(a,arr); int bb = find(b, arr); arr[aa] = bb; } private static int gcd(int a, int b) { if(a==0)return b; return gcd(b%a, a); } public static int[] readIntArray(int size, FastReader s) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = s.nextInt(); } return array; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } // implements Comparable<Pair> // //class Pair1Comparator implements Comparator<Pair>{ // public int compare(Pair s1, Pair s2) { // return Integer.compare(s1.a, s2.a); // } //} // //class Pair2Comparator implements Comparator<Pair>{ // public int compare(Pair s1, Pair s2) { // return Integer.compare(s2.a, s1.a); // } //} class Node { int data,sum,total; Node left, right; Node(int data){ this.data = data; this.left = null; this.right = null; this.sum = 0; this.total = 0; } } class Pair implements Comparable<Pair>{ int a; int b; Pair(int a, int b){ this.a = a; this.b = b; } @Override public boolean equals(Object obj) { if(this == obj) return true; if(obj == null || obj.getClass()!= this.getClass()) return false; Pair pair = (Pair) obj; return (pair.a == this.a && pair.b == this.b); } @Override public int hashCode() { return Objects.hash(a,b); // return new Integer(a).hashCode() * 31 + new Integer(b).hashCode(); } @Override public int compareTo(Pair o) { // if(this.b == o.b) { // return Long.compare(this.a, o.a); // }else { // return Long.compare(o.b, this.b); // } return Long.compare(this.b - this.a, o.b-o.a); } @Override public String toString() { return this.a + " " + this.b; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
7dc3b5038a9b35ff5b1cfdf189d060e8
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; import java.util.Scanner; public class gamemaster { private static class pair implements Comparable<pair> { int low, high; pair(int low, int high) { this.low = low; this.high = high; } @Override public int hashCode() { // uses roll no to verify the uniqueness // of the object of Student class final int temp = 14; int ans = 1; ans = (temp * ans) + low +high; return ans; } public int compareTo(pair o) { return o.low-this.low; } // Equal objects must produce the same // hash code as long as they are equal @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null) { return false; } if (this.getClass() != o.getClass()) { return false; } pair other = (pair)o; if (this.low != other.low && this.high !=other.high) { return false; } return true; } } public static void main(String[] args) { InputReader in=new InputReader(System.in); PrintWriter out=new PrintWriter(System.out); int t=in.nextInt(); while(t--!=0) { int n=in.nextInt();int max=Integer.MIN_VALUE;int chka=0;int chkb=0; pair a[]=new pair[n+1];pair b[]=new pair[n+1]; a[0]=new pair(Integer.MIN_VALUE,-1); b[0]=new pair(Integer.MIN_VALUE,-1); for(int i=1;i<=n;i++) { a[i]=new pair(in.nextInt(),i); if(a[i].low>max) {max=a[i].low; chka=i; } } max=Integer.MIN_VALUE; for(int i=1;i<=n;i++) { b[i]=new pair(in.nextInt(),i); if(b[i].low>max) {max=b[i].low; chkb=i; } } Arrays.sort(a);Arrays.sort(b); ArrayList<ArrayList<Integer>>list=new ArrayList<>(); for(int i=0;i<=n;i++) { list.add(new ArrayList<Integer>()); } for(int i=0;i<n;i++) { if(a[i].high!=-1 && a[i+1].high!=-1) list.get(a[i].high).add(a[i+1].high); } for(int i=0;i<n;i++) { if(b[i].high!=-1 && b[i+1].high!=-1) list.get(b[i].high).add(b[i+1].high); } list=reverse(list,n); boolean vis[]=new boolean[n+1]; int ans[]=new int[n+1];dfs(chka,vis,list,ans); for(int i=1;i<=n;i++) { out.print(ans[i]); } out.println(); }out.close(); } private static void dfs(int i,boolean vis[],ArrayList<ArrayList<Integer>>list,int ans[]) { vis[i]=true;ans[i]=1; for(int k: list.get(i)) { if(!vis[k]) { dfs(k,vis,list,ans); }} } private static ArrayList<ArrayList<Integer>> reverse(ArrayList<ArrayList<Integer>>list,int n) { ArrayList<ArrayList<Integer>>rev=new ArrayList<ArrayList<Integer>>(); for(int i=0;i<=n;i++) { rev.add(new ArrayList<>()); } for(int i=1;i<=n;i++) { for(int temp : list.get(i)) { rev.get(temp).add(i); } } return rev; } static class InputReader { private InputStream stream; private byte[] buf = new byte[8192]; private int curChar, snumChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
262d9e32ab32fac030a4f07064112ce4
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.DataInputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.TreeMap; public class Main { private static int n; private static int[] a, b; private static TreeMap<Integer, Integer> a_map, b_map; private static boolean[] win; private static void run() throws IOException { n = in.nextInt(); a = new int[n]; b = new int[n]; win = new boolean[n]; a_map = new TreeMap<>(); b_map = new TreeMap<>(); for (int i = 0; i < n; i++) { a[i] = in.nextInt(); a_map.put(a[i], i); } for (int i = 0; i < n; i++) { b[i] = in.nextInt(); b_map.put(b[i], i); } win(a_map.lastEntry().getValue()); for (int i = 0; i < n; i++) { out.print(win[i] ? '1' : '0'); } out.println(); } private static void win(int pos) { win[pos] = true; a_map.remove(a[pos]); b_map.remove(b[pos]); while (true) { var last = a_map.lastEntry(); if (last == null || last.getKey() < a[pos]) { break; } win(last.getValue()); } while (true) { var last = b_map.lastEntry(); if (last == null || last.getKey() < b[pos]) { break; } win(last.getValue()); } } public static void main(String[] args) throws IOException { in = new Reader(); out = new PrintWriter(new OutputStreamWriter(System.out)); int t = in.nextInt(); for (int i = 0; i < t; i++) { run(); } out.flush(); in.close(); out.close(); } private static int gcd(int a, int b) { if (a == 0 || b == 0) return 0; while (b != 0) { int tmp; tmp = a % b; a = b; b = tmp; } return a; } static final long mod = 1000000007; static long pow_mod(long a, long b) { long result = 1; while (b != 0) { if ((b & 1) != 0) result = (result * a) % mod; a = (a * a) % mod; b >>= 1; } return result; } private static long add_mod(long... longs) { long ans = 0; for (long now : longs) { ans = (ans + now) % mod; } return ans; } private static long multiplied_mod(long... longs) { long ans = 1; for (long now : longs) { ans = (ans * now) % mod; } return ans; } @SuppressWarnings("FieldCanBeLocal") private static Reader in; private static PrintWriter out; private static int[] read_int_array(int len) throws IOException { int[] a = new int[len]; for (int i = 0; i < len; i++) { a[i] = in.nextInt(); } return a; } private static long[] read_long_array(int len) throws IOException { long[] a = new long[len]; for (int i = 0; i < len; i++) { a[i] = in.nextLong(); } return a; } private static void print_array(int[] array) { for (int now : array) { out.print(now); out.print(' '); } out.println(); } private static void print_array(long[] array) { for (long now : array) { out.print(now); out.print(' '); } out.println(); } static class Reader { private static final int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { final byte[] buf = new byte[1024]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { break; } buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextSign() throws IOException { byte c = read(); while ('+' != c && '-' != c) { c = read(); } return '+' == c ? 0 : 1; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } public int skip() throws IOException { int b; // noinspection ALL while ((b = read()) != -1 && isSpaceChar(b)) { ; } return b; } public char nc() throws IOException { return (char) skip(); } public String next() throws IOException { int b = skip(); final StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = read(); } return sb.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } public void close() throws IOException { din.close(); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
e7a9ba632254812928bca019c167588a
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class test { static StringBuilder sb; static long fact[]; static int mod = (int) (1e9 + 7); static class Pair implements Comparable<Pair> { int x; int y; Pair(int x, int y) { this.x = x; this.y = y; } public int compareTo(Pair o) { return (int) (this.y - o.y); } } // static void solve() { // int N = i(); // int[] arr1 = readArray(N); // int[] arr = new int[N + 1]; // for (int i = 1; i <= N; i++) { // arr[i] = arr1[i - 1]; // } // // fenwicktree(arr); // // int Q = i(); // for (int i = 0; i < Q; i++) { // String s = s(); // if (s.equals("q")) { // int l = i(); // int r = i(); // long val = query(l, r); // sb.append(val + "\n"); // } else { // int idx = i(); // int delta = i(); // arr[idx] += delta; // update(idx, delta); // } // } // } static void solve() { int n = i(); int[][] arr = new int[n][3]; for(int i=0 ; i<n ; i++) { arr[i][0] = i(); arr[i][2] = i; } for(int i=0 ; i<n ; i++) { arr[i][1] = i(); } Arrays.sort(arr, (int[] a, int[] b) -> a[0] - b[0]); boolean[] res = new boolean[n]; int min = arr[n-1][1]; res[arr[n-1][2]] = true; for(int i=n-2 ; i>=0 ; i--) { if(arr[i][1] > min) { for(int j=i ; j<n && res[arr[j][2]] == false ; j++) { min = Math.min(min, arr[j][1]); res[arr[j][2]] = true; } } } for(int i=0 ; i<n ; i++) { if(res[i] == true) sb.append(1); else sb.append(0); } sb.append("\n"); } public static void main(String[] args) { sb = new StringBuilder(); int test = i(); while (test-- > 0) { solve(); } System.out.println(sb); } /* * fact=new long[(int)1e6+10]; fact[0]=fact[1]=1; for(int i=2;i<fact.length;i++) * { fact[i]=((long)(i%mod)1L(long)(fact[i-1]%mod))%mod; } */ // **************NCR%P****************** static long p(long x, long y)// POWER FXN // { if (y == 0) return 1; long res = 1; while (y > 0) { if (y % 2 == 1) { res = (res * x) % mod; y--; } x = (x * x) % mod; y = y / 2; } return res; } static long ncr(int n, int r) { if (r > n) return (long) 0; long res = fact[n] % mod; // System.out.println(res); res = ((long) (res % mod) * (long) (p(fact[r], mod - 2) % mod)) % mod; res = ((long) (res % mod) * (long) (p(fact[n - r], mod - 2) % mod)) % mod; // System.out.println(res); return res; } // **************END****************** // *************Disjoint set // union*********// // ***************PRIME FACTORIZE // ***********************************// static TreeMap<Integer, Integer> prime(long n) { TreeMap<Integer, Integer> h = new TreeMap<>(); long num = n; for (int i = 2; i <= Math.sqrt(num); i++) { if (n % i == 0) { int nt = 0; while (n % i == 0) { n = n / i; nt++; } h.put(i, nt); } } if (n != 1) h.put((int) n, 1); return h; } // *****CLASS PAIR // ************************************************* // *****CLASS PAIR // *************************************************** static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int Int() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String String() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return String(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } static InputReader in = new InputReader(System.in); static OutputWriter out = new OutputWriter(System.out); public static long[] sort(long[] a2) { int n = a2.length; ArrayList<Long> l = new ArrayList<>(); for (long i : a2) l.add(i); Collections.sort(l); for (int i = 0; i < l.size(); i++) a2[i] = l.get(i); return a2; } public static long pow(long x, long y) { long res = 1; while (y > 0) { if (y % 2 != 0) { res = (res * x);// % modulus; y--; } x = (x * x);// % modulus; y = y / 2; } return res; } // GCD___+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public static long gcd(long x, long y) { if (x == 0) return y; else return gcd(y % x, x); } // ******LOWEST COMMON MULTIPLE // ********************************************* public static long lcm(long x, long y) { return (x * (y / gcd(x, y))); } // INPUT // PATTERN******************************************************** public static int i() { return in.Int(); } public static long l() { String s = in.String(); return Long.parseLong(s); } public static String s() { return in.String(); } public static int[] readArray(int n) { int A[] = new int[n]; for (int i = 0; i < n; i++) { A[i] = i(); } return A; } public static long[] readArray(long n) { long A[] = new long[(int) n]; for (int i = 0; i < n; i++) { A[i] = l(); } return A; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
69643d498811d5e5f304771f02ca50a9
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class Div21608C { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int t = Integer.parseInt(br.readLine()); while(t --> 0) { int n = Integer.parseInt(br.readLine()); HashMap<Integer, Integer> mapa = new HashMap<Integer, Integer>(); HashMap<Integer, Integer> mapb = new HashMap<Integer, Integer>(); HashMap<Integer, Integer> mapan = new HashMap<Integer, Integer>(); HashMap<Integer, Integer> mapbn = new HashMap<Integer, Integer>(); int[] arao = new int[n]; int[] arbo = new int[n]; int[] ara = new int[n]; int[] arb = new int[n]; boolean[] good = new boolean[n]; StringTokenizer st = new StringTokenizer(br.readLine()); for(int i = 0; i < n; i++) { ara[i] = arao[i] = Integer.parseInt(st.nextToken()); mapa.put(ara[i], i); } st = new StringTokenizer(br.readLine()); for(int i = 0; i < n; i++) { arb[i] = arbo[i] = Integer.parseInt(st.nextToken()); mapb.put(arb[i], i); } Arrays.parallelSort(ara); Arrays.parallelSort(arb); for(int i = 0; i < n; i++) { mapan.put(ara[i], i); mapbn.put(arb[i], i); } int plba = n; int plbb = n; int lba = mapan.get(arao[mapb.get(arb[n-1])]); int lbb = mapbn.get(arbo[mapa.get(ara[n-1])]); boolean change = true; while(change) { change = false; for(int i = lba; i < plba; i++) { if(mapbn.get(arbo[mapa.get(ara[i])]) < lbb) { lbb = mapbn.get(arbo[mapa.get(ara[i])]); change = true; } } plba = lba; for(int i = lbb; i < plbb; i++) { if(mapan.get(arao[mapb.get(arb[i])]) < lba) { lba = mapan.get(arao[mapb.get(arb[i])]); change = true; } } plbb = lbb; } for(int i = lba; i < n; i++) good[mapa.get(ara[i])] = true; for(int i = lbb; i < n; i++) good[mapb.get(arb[i])] = true; for(boolean g : good) pw.print((g ? "1":"0")); pw.println(); } pw.close(); } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
f726f7ef75842905960e263b165f2d5a
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class _758 { public static void main(String[] args) { MyScanner sc = new MyScanner(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); ArrayList<Pair> aa = new ArrayList<>(); ArrayList<Pair> bb = new ArrayList<>(); for (int i = 0; i < n; i++) aa.add(new Pair(i, sc.nextInt())); for (int i = 0; i < n; i++) bb.add(new Pair(i, sc.nextInt())); if (n == 1) { out.println(1); continue; } Collections.sort(aa, Comparator.comparingInt(x -> x.x)); Collections.sort(bb, Comparator.comparingInt(x -> x.x)); int [] a = new int[n]; int [] b = new int[n]; int [] posA = new int[n]; int [] posB = new int[n]; for (int i = 0; i < n; i++) { a[i] = aa.get(i).i; b[i] = bb.get(i).i; posA[a[i]] = i; posB[b[i]] = i; } int [] max = new int[n]; int [] min = new int[n]; max[n - 1] = n - 1; min[n - 1] = n - 1; min[n - 1] = Math.min(posB[a[n - 1]], posA[b[n - 1]]); for (int i = n - 2; i >= 0; i--) { max[i] = Math.max(i, max[i + 1]); min[i] = Math.min(i, min[i + 1]); int f = posA[b[i]]; int s = posB[a[i]]; max[i] = Math.max(max[i], Math.max(f, s)); min[i] = Math.min(min[i], Math.min(f, s)); } int [] res = new int[n]; Set<Integer> set = new HashSet<>(); for (int i = n - 1; i >= 0; i--) { set.add(a[i]); set.add(b[i]); if (min[i] == i) { break; } } for (Integer i: set) res[i] = 1; for (int i: res) out.print(i); out.println(); } out.close(); } static class Pair { int i; int x; Pair(int i, int x) { this.i = i; this.x = x; } } static void sort(int[] a) { ArrayList<Integer> q = new ArrayList<>(); for (int i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void sort(long[] a) { ArrayList<Long> q = new ArrayList<>(); for (long i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
686a07c1b5dff43cfa350564b1f32049
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class Main { // For fast input output static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { try {br = new BufferedReader( new FileReader("input.txt")); PrintStream out = new PrintStream(new FileOutputStream("output.txt")); System.setOut(out);} catch(Exception e) { br = new BufferedReader(new InputStreamReader(System.in));} } String next() { while (st == null || !st.hasMoreElements()) { try {st = new StringTokenizer(br.readLine());} catch (IOException e) { e.printStackTrace();} } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() {return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // end of fast i/o code public static void main(String[] args) { FastReader reader = new FastReader(); StringBuilder sb = new StringBuilder(""); int t = reader.nextInt(); while(t-->0){ int n = reader.nextInt(); int mp1[] = new int[n]; int mp2[] = new int[n]; PriorityQueue<Pl> pq1 = new PriorityQueue<>((o1, o2) -> o1.val-o2.val); PriorityQueue<Pl> pq2 = new PriorityQueue<>((o1, o2) -> o1.val-o2.val); for(int i=0; i<n; i++){ mp1[i] = reader.nextInt(); pq1.offer(new Pl(mp1[i], i)); } for(int i=0; i<n; i++){ mp2[i] = reader.nextInt(); pq2.offer(new Pl(mp2[i], i)); } TreeMap<Integer, Node> tm = new TreeMap<>(); Queue<Integer> done = new LinkedList<>(); int winners[] = new int[n]; int visited[] = new int[n]; Node prev = null; Node head1 = null; while(!pq1.isEmpty()){ int pos = pq1.poll().pos; Node current = new Node(pos); if(head1==null){ head1 = current; } tm.put(pos, current); if(prev!=null){ prev.m1_par = current; } prev = current; } winners[prev.val] = 1; done.offer(prev.val); prev = null; Node head2 = null; while(!pq2.isEmpty()){ int pos = pq2.poll().pos; Node current = tm.get(pos); if(head2==null){ head2 = current; } if(prev!=null){ prev.m2_par = current; } prev = current; } winners[prev.val] = 1; done.offer(prev.val); while(!done.isEmpty()){ int val = done.poll(); Node temp = tm.get(val); // sb.append((temp.val+1)+" "); if(visited[temp.val]==1){ continue; } visited[temp.val] = 1; Node it1 = temp.m1_par; while(it1!=null){ if(winners[it1.val]==1){ break; } done.offer(it1.val); winners[it1.val] = 1; it1 = it1.m1_par; } it1 = temp.m2_par; while(it1!=null){ if(winners[it1.val]==1){ break; } done.offer(it1.val); winners[it1.val] = 1; it1 = it1.m2_par; } } // sb.append("<--\n"); for(int i=0; i<n; i++){ sb.append(winners[i]); } sb.append("\n"); } System.out.println(sb); } static class Pl{ int val, pos; Pl(int a, int b){ val = a; pos = b; } } static class Node{ int val; Node m1_par, m2_par; Node(int a){ val = a; m1_par = null; m2_par = null; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
eec60261c561d9b9792d227fcd0f0268
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.PriorityQueue; public class Main { public static void main(String[] args) { new Main(); } public Main() { FastScanner fs = new FastScanner(); java.io.PrintWriter out = new java.io.PrintWriter(System.out); solve(fs, out); out.flush(); } public void solve(FastScanner fs, java.io.PrintWriter out) { int t = fs.nextInt(); while(t --> 0) { int n = fs.nextInt(); int[] a = new int[n], b = new int[n]; for (int i = 0;i < n;++ i) a[i] = fs.nextInt(); for (int i = 0;i < n;++ i) b[i] = fs.nextInt(); PriorityQueue<Integer> pqa = new PriorityQueue<>((l, r) -> Integer.compare(a[r], a[l])); PriorityQueue<Integer> pqb = new PriorityQueue<>((l, r) -> Integer.compare(b[r], b[l])); for (int i = 0;i < n;++ i) { pqa.add(i); pqb.add(i); } int amax = a[pqa.peek()], bmax = b[pqb.peek()]; while(!pqb.isEmpty() && b[pqb.peek()] >= bmax || !pqa.isEmpty() && a[pqa.peek()] >= amax) { while(!pqb.isEmpty() && b[pqb.peek()] >= bmax) { amax = Math.min(amax, a[pqb.poll()]); } while(!pqa.isEmpty() && a[pqa.peek()] >= amax) { bmax = Math.min(bmax, b[pqa.poll()]); } } for (int i = 0;i < n;++ i) { if (a[i] >= amax || b[i] >= bmax) out.print('1'); else out.print('0'); } out.println(); } } final int MOD = 998_244_353; int plus(int n, int m) { int sum = n + m; if (sum >= MOD) sum -= MOD; return sum; } int minus(int n, int m) { int sum = n - m; if (sum < 0) sum += MOD; return sum; } int times(int n, int m) { return (int)((long)n * m % MOD); } int divide(int n, int m) { return times(n, IntMath.pow(m, MOD - 2, MOD)); } int[] fact, invf; void calc(int len) { len += 2; fact = new int[len]; invf = new int[len]; fact[0] = fact[1] = invf[0] = invf[1] = 1; for (int i = 2;i < fact.length;++ i) fact[i] = times(fact[i - 1], i); invf[len - 1] = divide(1, fact[len - 1]); for (int i = len - 1;i > 1;-- i) invf[i - 1] = times(i, invf[i]); } int comb(int n, int m) { if (n < m) return 0; return times(fact[n], times(invf[n - m], invf[m])); } } class FastScanner { private final java.io.InputStream in = System.in; private final byte[] buffer = new byte[8192]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) return true; ptr = 0; try { buflen = in.read(buffer); } catch (java.io.IOException e) { e.printStackTrace(); } return buflen > 0; } private byte readByte() { return hasNextByte() ? buffer[ptr++ ] : -1; } private static boolean isPrintableChar(byte c) { return 32 < c || c < 0; } private static boolean isNumber(int c) { return '0' <= c && c <= '9'; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++ ; return hasNextByte(); } public String next() { if (!hasNext()) throw new java.util.NoSuchElementException(); StringBuilder sb = new StringBuilder(); byte b; while (isPrintableChar(b = readByte())) sb.appendCodePoint(b); return sb.toString(); } public final char nextChar() { if (!hasNext()) throw new java.util.NoSuchElementException(); return (char)readByte(); } public final long nextLong() { if (!hasNext()) throw new java.util.NoSuchElementException(); long n = 0; try { byte b = readByte(); if (b == '-') { while (isNumber(b = readByte())) n = n * 10 + '0' - b; return n; } else if (!isNumber(b)) throw new NumberFormatException(); do n = n * 10 + b - '0'; while (isNumber(b = readByte())); } catch (java.util.NoSuchElementException e) {} return n; } public final int nextInt() { if (!hasNext()) throw new java.util.NoSuchElementException(); int n = 0; try { byte b = readByte(); if (b == '-') { while (isNumber(b = readByte())) n = n * 10 + '0' - b; return n; } else if (!isNumber(b)) throw new NumberFormatException(); do n = n * 10 + b - '0'; while (isNumber(b = readByte())); } catch (java.util.NoSuchElementException e) {} return n; } public double nextDouble() { return Double.parseDouble(next()); } } class Arrays { public static void sort(final int[] array) { sort(array, 0, array.length); } public static void sort(final int[] array, int fromIndex, int toIndex) { if (toIndex - fromIndex <= 512) { java.util.Arrays.sort(array, fromIndex, toIndex); return; } sort(array, fromIndex, toIndex, 0, new int[array.length]); } private static final void sort(int[] a, final int from, final int to, final int l, final int[] bucket) { if (to - from <= 512) { java.util.Arrays.sort(a, from, to); return; } final int BUCKET_SIZE = 256; final int INT_RECURSION = 4; final int MASK = 0xff; final int shift = l << 3; final int[] cnt = new int[BUCKET_SIZE + 1]; final int[] put = new int[BUCKET_SIZE]; for (int i = from; i < to; i++) ++ cnt[(a[i] >>> shift & MASK) + 1]; for (int i = 0; i < BUCKET_SIZE; i++) cnt[i + 1] += cnt[i]; for (int i = from; i < to; i++) { int bi = a[i] >>> shift & MASK; bucket[cnt[bi] + put[bi]++] = a[i]; } for (int i = BUCKET_SIZE - 1, idx = from; i >= 0; i--) { int begin = cnt[i]; int len = cnt[i + 1] - begin; System.arraycopy(bucket, begin, a, idx, len); idx += len; } final int nxtL = l + 1; if (nxtL < INT_RECURSION) { sort(a, from, to, nxtL, bucket); if (l == 0) { int lft, rgt; lft = from - 1; rgt = to; while (rgt - lft > 1) { int mid = lft + rgt >> 1; if (a[mid] < 0) lft = mid; else rgt = mid; } reverse(a, from, rgt); reverse(a, rgt, to); } } } public static void sort(final long[] array) { sort(array, 0, array.length); } public static void sort(final long[] array, int fromIndex, int toIndex) { if (toIndex - fromIndex <= 512) { java.util.Arrays.sort(array, fromIndex, toIndex); return; } sort(array, fromIndex, toIndex, 0, new long[array.length]); } private static final void sort(long[] a, final int from, final int to, final int l, final long[] bucket) { final int BUCKET_SIZE = 256; final int LONG_RECURSION = 8; final int MASK = 0xff; final int shift = l << 3; final int[] cnt = new int[BUCKET_SIZE + 1]; final int[] put = new int[BUCKET_SIZE]; for (int i = from; i < to; i++) ++ cnt[(int) ((a[i] >>> shift & MASK) + 1)]; for (int i = 0; i < BUCKET_SIZE; i++) cnt[i + 1] += cnt[i]; for (int i = from; i < to; i++) { int bi = (int) (a[i] >>> shift & MASK); bucket[cnt[bi] + put[bi]++] = a[i]; } for (int i = BUCKET_SIZE - 1, idx = from; i >= 0; i--) { int begin = cnt[i]; int len = cnt[i + 1] - begin; System.arraycopy(bucket, begin, a, idx, len); idx += len; } final int nxtL = l + 1; if (nxtL < LONG_RECURSION) { sort(a, from, to, nxtL, bucket); if (l == 0) { int lft, rgt; lft = from - 1; rgt = to; while (rgt - lft > 1) { int mid = lft + rgt >> 1; if (a[mid] < 0) lft = mid; else rgt = mid; } reverse(a, from, rgt); reverse(a, rgt, to); } } } public static void reverse(int[] array) { reverse(array, 0, array.length); } public static void reverse(int[] array, int fromIndex, int toIndex) { for (-- toIndex;fromIndex < toIndex;++ fromIndex, -- toIndex) { int swap = array[fromIndex]; array[fromIndex] = array[toIndex]; array[toIndex] = swap; } } public static void reverse(long[] array) { reverse(array, 0, array.length); } public static void reverse(long[] array, int fromIndex, int toIndex) { for (-- toIndex;fromIndex < toIndex;++ fromIndex, -- toIndex) { long swap = array[fromIndex]; array[fromIndex] = array[toIndex]; array[toIndex] = swap; } } public static void shuffle(int[] array) { java.util.Random rnd = new java.util.Random(); for (int i = 0;i < array.length;++ i) { int j = rnd.nextInt(array.length - i) + i; int swap = array[i]; array[i] = array[j]; array[j] = swap; } } public static void shuffle(long[] array) { java.util.Random rnd = new java.util.Random(); for (int i = 0;i < array.length;++ i) { int j = rnd.nextInt(array.length - i) + i; long swap = array[i]; array[i] = array[j]; array[j] = swap; } } } class IntMath { public static int gcd(int a, int b) { while (a != 0) if ((b %= a) != 0) a %= b; else return a; return b; } public static int gcd(int... array) { int ret = array[0]; for (int i = 1; i < array.length; ++i) ret = gcd(ret, array[i]); return ret; } public static long gcd(long a, long b) { while (a != 0) if ((b %= a) != 0) a %= b; else return a; return b; } public static long gcd(long... array) { long ret = array[0]; for (int i = 1; i < array.length; ++i) ret = gcd(ret, array[i]); return ret; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static int pow(int a, int b) { int ans = 1; for (int mul = a; b > 0; b >>= 1, mul *= mul) if ((b & 1) != 0) ans *= mul; return ans; } public static long pow(long a, long b) { long ans = 1; for (long mul = a; b > 0; b >>= 1, mul *= mul) if ((b & 1) != 0) ans *= mul; return ans; } public static int pow(int a, long b, int mod) { if (b < 0) b = b % (mod - 1) + mod - 1; long ans = 1; for (long mul = a; b > 0; b >>= 1, mul = mul * mul % mod) if ((b & 1) != 0) ans = ans * mul % mod; return (int)ans; } public static int pow(long a, long b, int mod) { return pow((int)(a % mod), b, mod); } public static int floorsqrt(long n) { return (int)Math.sqrt(n + 0.1); } public static int ceilsqrt(long n) { return n <= 1 ? (int)n : (int)Math.sqrt(n - 0.1) + 1; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
feba59a11ccb187d44a2b5dd45410097
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class Main { static AReader scan = new AReader(); static int N = 100010; static Pair[] pairsa = new Pair[N]; static Pair[] pairsb = new Pair[N]; static int[] h = new int[N]; static int[] e = new int[2*N]; static int[] ne = new int[2*N]; static boolean[] st = new boolean[N]; static int idx; static void add(int a,int b){ e[idx] =b;ne[idx] = h[a];h[a] = idx++; } static void solve() { int n = scan.nextInt(); for(int i = 1;i<=n;i++){ h[i] = -1; st[i] = false; } idx = 0; for(int i = 1;i<=n;i++) pairsa[i] = new Pair(scan.nextInt(),i); for(int i = 1;i<=n;i++) pairsb[i] = new Pair(scan.nextInt(),i); Arrays.sort(pairsa,1,n+1,((o1, o2) -> o1.x - o2.x)); Arrays.sort(pairsb,1,n+1,((o1, o2) -> o1.x - o2.x)); for(int i = 1;i<n;i++) add(pairsa[i].y,pairsa[i+1].y); for(int i = 1;i<n;i++) add(pairsb[i].y,pairsb[i+1].y); Queue<Integer> queue = new LinkedList<>(); queue.offer(pairsa[n].y); queue.offer(pairsb[n].y); st[pairsa[n].y] = true; st[pairsb[n].y] = true; while(!queue.isEmpty()){ int t = queue.poll(); for(int i = h[t];i!=-1;i=ne[i]){ int j = e[i]; if(st[j]) continue; st[j] = true; queue.offer(j); } } StringBuffer sb = new StringBuffer(); for(int i = 1;i<=n;i++){ if(st[i]) sb.append(1); else sb.append(0); } System.out.println(sb.toString()); } public static void main(String[] args) { int T = scan.nextInt(); while (T-- > 0) { solve(); } } } class AReader { private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); private StringTokenizer tokenizer = new StringTokenizer(""); private String innerNextLine() { try { return reader.readLine(); } catch (IOException ex) { return null; } } public boolean hasNext() { while (!tokenizer.hasMoreTokens()) { String nextLine = innerNextLine(); if (nextLine == null) { return false; } tokenizer = new StringTokenizer(nextLine); } return true; } public String nextLine() { tokenizer = new StringTokenizer(""); return innerNextLine(); } public String next() { hasNext(); return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } class Pair { int x,y; public Pair(int x, int y) { this.x = x; this.y = y; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
31627e0929d4cd5042da1a433666de4e
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.util.*; public class Main { static InputReader2 sc=new InputReader2(System.in); /* static int MAXN=200005,n,m,a[]=new int[MAXN],dp[]=new int[MAXN],edge[][]=new int[MAXN][2]; static long k; static boolean vis[]=new boolean[MAXN],ok=false; static Vector<Integer> G[]=new Vector[MAXN],g[]=new Vector[MAXN];*/ static int MAXN=100005,ans[]=new int[MAXN]; static Vector<Integer> G[]=new Vector[MAXN]; public static void main(String args[]){ solve(); } private static void solve() { for(int i=1;i<=100000;i++){ G[i]=new Vector<>(); } int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); for(int i=1;i<=n;i++){ G[i].clear(); ans[i]=0; } int a[][]=new int[n+1][2]; int b[][]=new int[n+1][2]; int maxa[]={0,0},maxb[]={0,0}; for(int i=1;i<=n;i++){ a[i][0]=sc.nextInt(); a[i][1]=i; if(a[i][0]>maxa[0]){ maxa[1]=i; maxa[0]=a[i][0]; } } for(int i=1;i<=n;i++){ b[i][0]=sc.nextInt(); b[i][1]=i; if(b[i][0]>maxb[0]){ maxb[1]=i; maxb[0]=b[i][0]; } } Arrays.sort(a, (o1, o2) -> o1[0]-o2[0]); Arrays.sort(b, (o1, o2) -> o1[0]-o2[0]); for(int i=n;i>=2;i--){ G[a[i-1][1]].add(a[i][1]); G[b[i-1][1]].add(b[i][1]); } //System.out.println(maxa[1]+" "+maxb[1]); ans[maxa[1]]=ans[maxb[1]]=1; dfs(maxa[1]); dfs(maxb[1]); for(int i=1;i<=n;i++){ System.out.print(ans[i]); } System.out.println(); } } private static void dfs(int x) { for(int v:G[x]){ if(ans[v]==1)continue; //System.out.println(x+" "+v); ans[v]=1; dfs(v); } } } class InputReader2 { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader2(InputStream st) { this.stream = st; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
1d56ead54afada7002e6f8611fcd7eda
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class GameMaster { public static void main(String[] args) throws IOException{ BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); int t=Integer.parseInt(f.readLine()); while(t-->0) { int n=Integer.parseInt(f.readLine()); ArrayList<ArrayList<Integer>> arr=new ArrayList<ArrayList<Integer>>(); int[][] edge=new int[n][3]; StringTokenizer st=new StringTokenizer(f.readLine()); int max=0; int maxpos=0; for(int i=0;i<n;i++) { edge[i][0]=Integer.parseInt(st.nextToken()); if(edge[i][0]>max) { max=edge[i][0]; maxpos=i; } } st=new StringTokenizer(f.readLine()); for(int i=0;i<n;i++) { edge[i][1]=Integer.parseInt(st.nextToken()); edge[i][2]=i; arr.add(new ArrayList<Integer>()); } Arrays.sort(edge,(a,b)->b[0]-a[0]); for(int i=0;i<n-1;i++) { arr.get(edge[i+1][2]).add(edge[i][2]); } Arrays.sort(edge,(a,b)->b[1]-a[1]); for(int i=0;i<n-1;i++) { arr.get(edge[i+1][2]).add(edge[i][2]); } boolean[] visited=new boolean[n]; dfs(arr,maxpos,visited); for(int i=0;i<n;i++) { if(visited[i]) out.print(1); else out.print(0); } out.println(); } out.close(); f.close(); } public static void dfs(ArrayList<ArrayList<Integer>> arr,int i,boolean[] visited) { if(visited[i]) { return; } visited[i]=true; for(int x:arr.get(i)) { dfs(arr,x,visited); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
e64b7c7377bbc1f84cb7360f3b849219
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class GameMaster { public static void main(String[] args) throws IOException{ BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); int t=Integer.parseInt(f.readLine()); while(t-->0) { int n=Integer.parseInt(f.readLine()); ArrayList<ArrayList<Integer>> arr=new ArrayList<ArrayList<Integer>>(); int[][] edge=new int[n][3]; StringTokenizer st=new StringTokenizer(f.readLine()); int max=0; int maxpos=0; for(int i=0;i<n;i++) { edge[i][0]=Integer.parseInt(st.nextToken()); if(edge[i][0]>max) { max=edge[i][0]; maxpos=i; } } st=new StringTokenizer(f.readLine()); for(int i=0;i<n;i++) { edge[i][1]=Integer.parseInt(st.nextToken()); edge[i][2]=i; arr.add(new ArrayList<Integer>()); } Arrays.sort(edge,(a,b)->b[0]-a[0]); for(int i=0;i<n-1;i++) { arr.get(edge[i+1][2]).add(edge[i][2]); } Arrays.sort(edge,(a,b)->b[1]-a[1]); for(int i=0;i<n-1;i++) { arr.get(edge[i+1][2]).add(edge[i][2]); } boolean[] visited=new boolean[n]; dfs(arr,maxpos,visited); for(int i=0;i<n;i++) { if(visited[i]) out.print(1); else out.print(0); } out.println(); } out.close(); f.close(); } public static void dfs(ArrayList<ArrayList<Integer>> arr,int i,boolean[] visited) { if(visited[i]) { return; } visited[i]=true; for(int x:arr.get(i)) { dfs(arr,x,visited); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
75ebf421b9064cb3c1f81bc717f32077
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int k = input.nextInt(); Set<Integer> set = new HashSet<>(); while(k-- != 0){ int n = input.nextInt(); int[][] map_a = new int[n][2]; // value -> index int[][] map_b = new int[n][2]; for (int i = 0; i < n; i++) { map_a[i][0] = input.nextInt(); map_a[i][1] = i; } for (int i = 0; i < n; i++) { map_b[i][0] = input.nextInt(); map_b[i][1] = i; } boolean[] ans = new boolean[n]; Arrays.sort(map_a,(o1,o2) -> o1[0] - o2[0]); Arrays.sort(map_b,(o1,o2) -> o1[0] - o2[0]); for (int i = n-1; i >= 0; i--) { set.add(map_a[i][1]); set.add(map_b[i][1]); if(set.size() == n - i) break; } for (Integer integer : set) { ans[integer] = true; } set.clear(); for (int i = 0; i < n; i++) { if(ans[i]) System.out.print('1'); else System.out.print('0'); } System.out.println(); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
ea0bfd9b48d47d59e1c50bec261a78e9
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class Main { static class Pair implements Comparable<Pair>{ int i; int j; Pair(int i,int j){ this.i=i; this.j=j; } public int compareTo(Pair o){ if(this.j>o.j){ return(-1); } else if(this.j==o.j){ return(0); } else{ return(1); } } } public static void main(String[] args) throws IOException { Scanner scn = new Scanner(System.in); OutputWriter out = new OutputWriter(System.out); // Always print a trailing "\n" and close the OutputWriter as shown at the end of your output // example: int t = scn.nextInt(); for(int i1=0;i1<t;i1++){ int n=scn.nextInt(); int[] ans=new int[n]; ArrayList<Pair> arr1=new ArrayList<Pair>(); ArrayList<Pair> arr2=new ArrayList<Pair>(); for(int i=0;i<n;i++){ arr1.add(new Pair(i,scn.nextInt())); } for(int i=0;i<n;i++){ arr2.add(new Pair(i,scn.nextInt())); } Collections.sort(arr1);Collections.sort(arr2); int[][] pos=new int[n][2]; for(int i=0;i<n;i++){ pos[arr1.get(i).i][0]=i;pos[arr2.get(i).i][1]=i; } ArrayList<Integer> a1=new ArrayList<Integer>();ArrayList<Integer> a2=new ArrayList<Integer>(); a1.add(pos[arr1.get(0).i][1]);a2.add(pos[arr2.get(0).i][0]); for(int i=1;i<n;i++){ a1.add(Math.max(pos[arr1.get(i).i][1],a1.get(a1.size()-1))); a2.add(Math.max(pos[arr2.get(i).i][0],a2.get(a2.size()-1))); } int id1=0;int id2=0; /*out.print(a1+" "+a2+"\n");*/ while(true){ int id3=a1.get(id1);int id4=a2.get(id2); if((id2==id3)&&(id4==id1)){ break; } id2=id3;id1=id4; } for(int i=0;i<=id1;i++){ ans[arr1.get(i).i]=1; } for(int i=0;i<n;i++){ out.print(ans[i]+""); } out.print("\n"); } out.close(); } // fast input static class Scanner { public BufferedReader reader; public StringTokenizer tokenizer; public Scanner(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { String line = reader.readLine(); if (line == null) return null; tokenizer = new StringTokenizer(line); } catch (Exception e) { throw(new RuntimeException()); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } // fast output static class OutputWriter { BufferedWriter writer; public OutputWriter(OutputStream stream) { writer = new BufferedWriter(new OutputStreamWriter(stream)); } public void print(int i) throws IOException { writer.write(i); } public void print(String s) throws IOException { writer.write(s); } public void print(char[] c) throws IOException { writer.write(c); } public void close() throws IOException { writer.close(); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
bdbac73788db01a9aa86f9df90f2d381
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
/* 3 4 1 2 3 4 1 2 3 4 4 11 12 20 21 44 22 11 30 1 1000000000 1000000000 Put an edge from player a to player b iff a can defeat b, a player can win the tournament if you can reach all other players from it --> Can use DP from here to determine which of these players can win (if a player reaches a player that can reach all other players then that player can win the tournament, too --> graph not a tree, directed and potentially cyclic) --> over N^2 potential edges, sort players by descending ai, bi and add edges from player i to i + 1 --> player with maximum ai can reach all other players with less ai, find if there is a reverse path (where those players beat this one) from this max player to other players --> all those players win the tournament */ import java.util.*; import java.io.*; public class Main{ public static int n; public static Player[] players; public static boolean[] seen; public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int nc = Integer.parseInt(br.readLine()); for(int cc = 0; cc < nc; cc++){ n = Integer.parseInt(br.readLine()); StringTokenizer sa = new StringTokenizer(br.readLine()); StringTokenizer sb = new StringTokenizer(br.readLine()); players = new Player[n]; Pair[] sorta = new Pair[n]; Pair[] sortb = new Pair[n]; for(int a = 0; a < n; a++){ int ai = Integer.parseInt(sa.nextToken()); int bi = Integer.parseInt(sb.nextToken()); players[a] = new Player(a, ai, bi); sorta[a] = new Pair(a, ai); sortb[a] = new Pair(a, bi); } Arrays.sort(sorta); Arrays.sort(sortb); int strongest = sorta[n - 1].id; //this player can reach all other players for(int i = 0; i < n - 1; i++){ players[sorta[i].id].addEdge(true, sorta[i + 1].id); players[sorta[i + 1].id].addEdge(false, sorta[i].id); players[sortb[i].id].addEdge(true, sortb[i + 1].id); players[sortb[i + 1].id].addEdge(false, sortb[i].id); } seen = new boolean[n]; revDFS(strongest); StringBuilder f = new StringBuilder(); for(int a = 0; a < n; a++){ if(seen[a]) f.append("1"); else f.append("0"); } System.out.println(f.toString()); } br.close(); } public static void revDFS(int start){ Queue<Integer> q = new LinkedList<Integer>(); q.add(start); while(!q.isEmpty()){ int cur = q.poll(); if(!seen[cur]){ seen[cur] = true; for(int revE : players[cur].lose) q.add(revE); } } } } class Pair implements Comparable<Pair>{ int id; //what player this power value comes from int power; public Pair(int i, int p){ id = i; power = p; } public String toString(){ return id + " " + power; } public int compareTo(Pair p){ if(p.power != power) return power - p.power; return id - p.id; } } class Player{ int id; int ai; int bi; ArrayList<Integer> win = new ArrayList<Integer>(); //players this player can win against ArrayList<Integer> lose = new ArrayList<Integer>(); //players this player can lose against public Player(int i, int a, int b){ id = i; ai = a; bi = b; } public void addEdge(boolean w, int con){ //win is whether or not the connection will win against this edge if(w) lose.add(con); else win.add(con); } public String toString(){ return id + " id, a " + ai + " b " + bi; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
8529cf67ca75f9d55da6e75ac34331c3
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; public class Main{ public static void main(String args[]){ InputReader in=new InputReader(System.in); TASK solver = new TASK(); int t=1; t = in.nextInt(); for(int i=1;i<=t;i++) { solver.solve(in,i); } } static class TASK { static int mod = 1000000007; static char[] ans; static void solve(ArrayList<pair> al,int n) { Collections.sort(al, (o1, o2) -> o2.x-o1.x); int dp[] = new int[n]; dp[n-1]=al.get(n-1).y; for(int i=n-2;i>=0;i--) { dp[i]=Math.max(al.get(i).y,dp[i+1]); } ans[al.get(0).z]='1'; int min=al.get(0).y; for(int i=1;i<n;i++) { if(dp[i]>min) { ans[al.get(i).z]='1'; } if(ans[al.get(i).z]=='1' && min>al.get(i).y) { min=al.get(i).y; } } } static void solve(InputReader in, int testNumber) { int n = in.nextInt(); ans = new char[n]; Arrays.fill(ans,'0'); ArrayList<pair> al = new ArrayList<>(); ArrayList<pair> bl = new ArrayList<>(); for(int i=0;i<n;i++) { int x = in.nextInt(); al.add(new pair(x,0,i)); bl.add(new pair(0,x,i)); } for(int i=0;i<n;i++) { int y = in.nextInt(); al.get(i).y=y; bl.get(i).x=y; } solve(al,n); solve(bl,n); System.out.println(String.valueOf(ans)); } } static class pair{ int x; int y; int z; pair(int x,int y,int z) { this.x=x; this.y=y; this.z=z; } } static class Maths { static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static long factorial(int n) { long fact = 1; for (int i = 1; i <= n; i++) { fact *= i; } return fact; } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
41c101523abb8ca5dfb4810ff6abcc2e
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class cf1608c { public static void main(String[] args) throws IOException { int t = ri(); while (t --> 0) { int n = ri(), a[] = ria(n), b[] = ria(n), ai[][] = new int[n][2], bi[][] = new int[n][2]; for (int i = 0; i < n; ++i) { ai[i][0] = a[i]; ai[i][1] = i; bi[i][0] = b[i]; bi[i][1] = i; } sort(ai, (x, y) -> x[0] - y[0]); sort(bi, (x, y) -> x[0] - y[0]); Graph g = graph(n); for (int i = 1; i < n; ++i) { g.cto(ai[i][1], ai[i - 1][1]); g.cto(bi[i][1], bi[i - 1][1]); } List<Integer> winners = scc(g).get(0); char ans[] = new char[n]; fill(ans, '0'); for (int i : winners) { ans[i] = '1'; } prln(ans); } close(); } static List<List<Integer>> scc(Graph g) { List<Integer> ordered = new ArrayList<>(); int n = g.size(); boolean[] vis = new boolean[n]; for (int i = 0; i < n; ++i) { if (!vis[i]) { scc_dfs(g, i, vis, ordered); } } Graph transpose = graph(n); for (int i = 0; i < n; ++i) { for (int j : g.get(i)) { transpose.cto(j, i); } } for (int i = 0; i < n / 2; ++i) { int __swap = ordered.get(i); ordered.set(i, ordered.get(n - i - 1)); ordered.set(n - i - 1, __swap); } List<List<Integer>> scc = new ArrayList<>(); fill(vis, false); for (int i : ordered) { if (!vis[i]) { List<Integer> comp = new ArrayList<>(); scc_dfs(transpose, i, vis, comp); scc.add(comp); } } return scc; } static int[] scc_label(Graph g) { List<Integer> ordered = new ArrayList<>(); int n = g.size(); boolean[] vis = new boolean[n]; for (int i = 0; i < n; ++i) { if (!vis[i]) { scc_dfs(g, i, vis, ordered); } } Graph transpose = graph(n); for (int i = 0; i < n; ++i) { for (int j : g.get(i)) { transpose.cto(j, i); } } for (int i = 0; i < n / 2; ++i) { int __swap = ordered.get(i); ordered.set(i, ordered.get(n - i - 1)); ordered.set(n - i - 1, __swap); } int scc[] = new int[n], cur = 0; fill(vis, false); for (int i : ordered) { if (!vis[i]) { scc_dfs_label(transpose, i, vis, scc, cur++); } } return scc; } static void scc_dfs_label(Graph g, int i, boolean vis[], int label[], int id) { vis[i] = true; label[i] = id; for (int j : g.get(i)) { if (!vis[j]) { scc_dfs_label(g, j, vis, label, id); } } } static void scc_dfs(Graph g, int i, boolean vis[], List<Integer> ordered) { vis[i] = true; for (int j : g.get(i)) { if (!vis[j]) { scc_dfs(g, j, vis, ordered); } } ordered.add(i); } static Graph graph(int n) { Graph g = new Graph(); for (int i = 0; i < n; ++i) { g.add(new ArrayList<>()); } return g; } static Graph graph(int n, int m) throws IOException { Graph g = graph(n); for (int i = 0; i < m; ++i) { g.c(rni() - 1, ni() - 1); } return g; } static Graph digraph(int n, int m) throws IOException { Graph g = graph(n); for (int i = 0; i < m; ++i) { g.cto(rni() - 1, ni() - 1); } return g; } static Graph tree(int n) throws IOException { return graph(n, n - 1); } static Graph graph(List<? extends Collection<Integer>> g) { int n = g.size(); Graph h = graph(n); for (int i = 0; i < n; ++i) { for (int j : g.get(i)) { h.cto(i, j); } } return h; } static class Graph extends ArrayList<List<Integer>> { void cto(int u, int v) { get(u).add(v); } void c(int u, int v) { cto(u, v); cto(v, u); } } static BufferedReader __i = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter __o = new PrintWriter(new OutputStreamWriter(System.out)); static StringTokenizer input; static Random __r = new Random(); // references // IBIG = 1e9 + 7 // IMAX ~= 2e9 // LMAX ~= 9e18 // constants static final int IBIG = 1000000007; static final int IMAX = 2147483647; static final long LMAX = 9223372036854775807L; // math util static int minof(int a, int b, int c) {return min(a, min(b, c));} static int minof(int... x) {if (x.length == 1) return x[0]; if (x.length == 2) return min(x[0], x[1]); if (x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i]; return min;} static long minof(long a, long b, long c) {return min(a, min(b, c));} static long minof(long... x) {if (x.length == 1) return x[0]; if (x.length == 2) return min(x[0], x[1]); if (x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i]; return min;} static int maxof(int a, int b, int c) {return max(a, max(b, c));} static int maxof(int... x) {if (x.length == 1) return x[0]; if (x.length == 2) return max(x[0], x[1]); if (x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i]; return max;} static long maxof(long a, long b, long c) {return max(a, max(b, c));} static long maxof(long... x) {if (x.length == 1) return x[0]; if (x.length == 2) return max(x[0], x[1]); if (x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i]; return max;} static int powi(int a, int b) {if (a == 0) return 0; int ans = 1; while (b > 0) {if ((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;} static long powl(long a, int b) {if (a == 0) return 0; long ans = 1; while (b > 0) {if ((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;} static int fli(double d) {return (int) d;} static int cei(double d) {return (int) ceil(d);} static long fll(double d) {return (long) d;} static long cel(double d) {return (long) ceil(d);} static int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);} static long gcd(long a, long b) {return b == 0 ? a : gcd(b, a % b);} static int[] exgcd(int a, int b) {if (b == 0) return new int[] {1, 0}; int[] y = exgcd(b, a % b); return new int[] {y[1], y[0] - y[1] * (a / b)};} static long[] exgcd(long a, long b) {if (b == 0) return new long[] {1, 0}; long[] y = exgcd(b, a % b); return new long[] {y[1], y[0] - y[1] * (a / b)};} static int randInt(int min, int max) {return __r.nextInt(max - min + 1) + min;} static long mix(long x) {x += 0x9e3779b97f4a7c15L; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L; x = (x ^ (x >> 27)) * 0x94d049bb133111ebL; return x ^ (x >> 31);} // array util static void reverse(int[] a) {for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}} static void reverse(long[] a) {for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}} static void reverse(double[] a) {for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {double swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}} static void reverse(char[] a) {for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}} static void shuffle(int[] a) {int n = a.length - 1; for (int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void shuffle(long[] a) {int n = a.length - 1; for (int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void shuffle(double[] a) {int n = a.length - 1; for (int i = 0; i < n; ++i) {int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void rsort(int[] a) {shuffle(a); sort(a);} static void rsort(long[] a) {shuffle(a); sort(a);} static void rsort(double[] a) {shuffle(a); sort(a);} static int[] copy(int[] a) {int[] ans = new int[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;} static long[] copy(long[] a) {long[] ans = new long[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;} static double[] copy(double[] a) {double[] ans = new double[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;} static char[] copy(char[] a) {char[] ans = new char[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;} // input static void r() throws IOException {input = new StringTokenizer(rline());} static int ri() throws IOException {return Integer.parseInt(rline());} static long rl() throws IOException {return Long.parseLong(rline());} static double rd() throws IOException {return Double.parseDouble(rline());} static int[] ria(int n) throws IOException {int[] a = new int[n]; r(); for (int i = 0; i < n; ++i) a[i] = ni(); return a;} static void ria(int[] a) throws IOException {int n = a.length; r(); for (int i = 0; i < n; ++i) a[i] = ni();} static int[] riam1(int n) throws IOException {int[] a = new int[n]; r(); for (int i = 0; i < n; ++i) a[i] = ni() - 1; return a;} static void riam1(int[] a) throws IOException {int n = a.length; r(); for (int i = 0; i < n; ++i) a[i] = ni() - 1;} static long[] rla(int n) throws IOException {long[] a = new long[n]; r(); for (int i = 0; i < n; ++i) a[i] = nl(); return a;} static void rla(long[] a) throws IOException {int n = a.length; r(); for (int i = 0; i < n; ++i) a[i] = nl();} static double[] rda(int n) throws IOException {double[] a = new double[n]; r(); for (int i = 0; i < n; ++i) a[i] = nd(); return a;} static void rda(double[] a) throws IOException {int n = a.length; r(); for (int i = 0; i < n; ++i) a[i] = nd();} static char[] rcha() throws IOException {return rline().toCharArray();} static void rcha(char[] a) throws IOException {int n = a.length, i = 0; for (char c : rline().toCharArray()) a[i++] = c;} static String rline() throws IOException {return __i.readLine();} static String n() {return input.nextToken();} static int rni() throws IOException {r(); return ni();} static int ni() {return Integer.parseInt(n());} static long rnl() throws IOException {r(); return nl();} static long nl() {return Long.parseLong(n());} static double rnd() throws IOException {r(); return nd();} static double nd() {return Double.parseDouble(n());} // output static void pr(int i) {__o.print(i);} static void prln(int i) {__o.println(i);} static void pr(long l) {__o.print(l);} static void prln(long l) {__o.println(l);} static void pr(double d) {__o.print(d);} static void prln(double d) {__o.println(d);} static void pr(char c) {__o.print(c);} static void prln(char c) {__o.println(c);} static void pr(char[] s) {__o.print(new String(s));} static void prln(char[] s) {__o.println(new String(s));} static void pr(String s) {__o.print(s);} static void prln(String s) {__o.println(s);} static void pr(Object o) {__o.print(o);} static void prln(Object o) {__o.println(o);} static void prln() {__o.println();} static void pryes() {prln("yes");} static void pry() {prln("Yes");} static void prY() {prln("YES");} static void prno() {prln("no");} static void prn() {prln("No");} static void prN() {prln("NO");} static boolean pryesno(boolean b) {prln(b ? "yes" : "no"); return b;}; static boolean pryn(boolean b) {prln(b ? "Yes" : "No"); return b;} static boolean prYN(boolean b) {prln(b ? "YES" : "NO"); return b;} static void prln(int... a) {for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i); if (a.length > 0) prln(a[a.length - 1]); else prln();} static void prln(long... a) {for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i); if (a.length > 0) prln(a[a.length - 1]); else prln();} static void prln(double... a) {for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i); if (a.length > 0) prln(a[a.length - 1]); else prln();} static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for (int i = 0; i < n; pr(iter.next()), pr(' '), ++i); if (n >= 0) prln(iter.next()); else prln();} static void h() {prln("hlfd"); flush();} static void flush() {__o.flush();} static void close() {__o.close();} }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
0fc64e0dd467057a69424438b50c2c96
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.text.DecimalFormat; import java.util.*; public class Codeforces { static int time; static int mod= 998244353; static List<Integer> adj[]; static int v; static int sum[]; public static void main(String[] args) throws Exception { PrintWriter out=new PrintWriter(System.out); FastScanner fs=new FastScanner(); int t=fs.nextInt(); outer:while(t-->0) { v=fs.nextInt(); int n=v; time=0; int arr[]=fs.readArray(v); int brr[]=fs.readArray(v); adj=new ArrayList[v]; for(int i=0;i<n;i++) adj[i]=new ArrayList<>(); Integer ind[]=new Integer[v]; for(int i=0;i<n;i++) ind[i]=i; Arrays.sort(ind,new Comparator<Integer>() { public int compare(Integer a,Integer b) { return arr[a]-arr[b]; } }); for(int i=1;i<n;i++) { int u=ind[i], v=ind[i-1]; adj[u].add(v); } Arrays.sort(ind,new Comparator<Integer>() { public int compare(Integer a,Integer b) { return brr[a]-brr[b]; } }); for(int i=1;i<n;i++) { int u=ind[i], v=ind[i-1]; adj[u].add(v); } List<List<Integer>> list=new ArrayList<>(); TarjanSSCs(list); int cnt=list.size(); if(cnt==1) { for(int i=0;i<n;i++) { out.print(1); } out.println(); continue outer; } Map<Integer,Integer> map=new HashMap<>(); for(int i=0;i<cnt;i++) { for(int ele:list.get(i)) { map.put(ele, i); } } // Set<Integer> g[]=new HashSet[cnt]; // for(int i=0;i<cnt;i++) g[i]=new HashSet<>(); int in[]=new int[cnt]; for(int i=0;i<n;i++) { for(int e:adj[i]) { int ip=map.get(i), ep=map.get(e); if(ip!=ep) { in[ep]++; } } } int ans[]=new int[n]; for(int i=0;i<cnt;i++) { if(in[i]==0) { for(int ele:list.get(i)) { ans[ele]=1; } break; } } for(int i=0;i<n;i++) out.print(ans[i]); out.println(); } out.close(); } static void TarjanSSCs(List<List<Integer>> list) { int disc[]=new int[v]; Arrays.fill(disc, -1); int low[]=new int[v]; boolean []onst=new boolean[v]; Stack<Integer> st=new Stack<>(); for(int i=0;i<v;i++) { if(disc[i]==-1) { Tutill(i,disc,low,onst,st,list); } } } static void Tutill(int u,int disc[],int low[],boolean[] onst,Stack<Integer> st,List<List<Integer>>list) { disc[u]=low[u]=++time; onst[u]=true; st.push(u); for(int v:adj[u]) { if(disc[v]==-1) { Tutill(v,disc,low,onst,st,list); low[u]=Math.min(low[u],low[v]); } else if(onst[v]) { low[u]=Math.min(low[u], disc[v]); } } int w=-1; if(low[u]==disc[u]) { list.add(new ArrayList<>()); int ind=list.size()-1; while(w!=u) { w=st.pop(); onst[w]=false; list.get(ind).add(w); } } } static long pow(long a,long b) { if(b<0) return 1; long res=1; while(b!=0) { if((b&1)!=0) { res*=a; res%=mod; } a*=a; a%=mod; b=b>>1; } return res; } static int gcd(int a,int b) { if(b==0) return a; return gcd(b,a%b); } static long nck(int n,int k) { if(k>n) return 0; long res=1; res*=fact(n); res%=mod; res*=modInv(fact(k)); res%=mod; res*=modInv(fact(n-k)); res%=mod; return res; } static long fact(long n) { // return fact[(int)n]; long res=1; for(int i=2;i<=n;i++) { res*=i; res%=mod; } return res; } static long modInv(long n) { return pow(n,mod-2); } static void sort(int[] a) { //suffle int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { int oi=r.nextInt(n); int temp=a[i]; a[i]=a[oi]; a[oi]=temp; } //then sort Arrays.sort(a); } // Use this to input code since it is faster than a Scanner static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long[] lreadArray(int n) { long a[]=new long[n]; for(int i=0;i<n;i++) a[i]=nextLong(); return a; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
cf5993777fde0ddad5559e40aa1bdd33
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class GameMaster { public static void main(String[] args) throws Exception { FastIO in = new FastIO(); int t = in.nextInt(); for (int i=0; i<t; i++) { int n = in.nextInt(); ArrayList<ArrayList<Integer>> adj = new ArrayList<ArrayList<Integer>>(); Player[] mapA = new Player[n]; Player[] mapB = new Player[n]; for (int j=0; j<n; j++) { mapA[j] = new Player(j, in.nextInt()); adj.add(new ArrayList<Integer>()); } for (int j=0; j<n; j++) { mapB[j] = new Player(j, in.nextInt()); } Arrays.sort(mapA, (o1, o2) -> Integer.compare(o2.skill, o1.skill)); Arrays.sort(mapB, (o1, o2) -> Integer.compare(o2.skill, o1.skill)); for (int j=1; j<n; j++) { adj.get(mapA[j].id).add(mapA[j-1].id); adj.get(mapB[j].id).add(mapB[j-1].id); } boolean[] visited = new boolean[n]; dfs(mapA[0].id, adj, visited); dfs(mapB[0].id, adj, visited); for (int j=0; j<n; j++) { if (visited[j]) System.out.print(1); else System.out.print(0); } System.out.println(); } } public static void dfs(int node, ArrayList<ArrayList<Integer>> adj, boolean[] visited) { if (node>=visited.length) return; if (visited[node]) return; visited[node] = true; for (Integer next: adj.get(node)) { dfs(next, adj, visited); } } static class Player { int id, skill; public Player(int id, int skill) { this.id = id; this.skill = skill; } } static class FastIO { BufferedReader br; StringTokenizer st; public FastIO() throws IOException { br = new BufferedReader( new InputStreamReader(System.in)); } public String next() throws IOException { while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } public int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); } public long nextLong() throws NumberFormatException, IOException { return Long.parseLong(next()); } public double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(next()); } public String nextLine() throws IOException { String str = br.readLine(); return str; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
144cff3a43c9ddcda3c1c6728eb075c0
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.InputMismatchException; public class E1608C { public static void main(String[] args) { FastIO io = new FastIO(); int t = io.nextInt(); while (t-- > 0) { int n = io.nextInt(); Triple[] arr = new Triple[n]; int[] ans = new int[n]; for (int i = 0; i < n; i++) { arr[i] = new Triple(i, io.nextInt()); } for (int i = 0; i < n; i++) { arr[i].valB = io.nextInt(); } Arrays.sort(arr, (a, b) -> b.valA - a.valA); int last = 0; int implicitMin = arr[last].valB; int explicitMin = arr[last].valB; for (int i = 1; i < n; i++) { implicitMin = Math.min(implicitMin, arr[i].valB); if (arr[i].valB > explicitMin) { explicitMin = implicitMin; last = i; } } for (int i = 0; i <= last; i++) { ans[arr[i].ind] = 1; } for (int v : ans) io.print(v); io.println(); } io.flush(); } static class Triple { int ind, valA, valB; public Triple(int ind, int valA) { this.ind = ind; this.valA = valA; } } private static class FastIO extends PrintWriter { private InputStream stream; private byte[] buf = new byte[1 << 16]; private int curChar, numChars; // standard input public FastIO() { this(System.in, System.out); } public FastIO(InputStream i, OutputStream o) { super(o); stream = i; } // file input public FastIO(String i, String o) throws IOException { super(new FileWriter(o)); stream = new FileInputStream(i); } // throws InputMismatchException() if previously detected end of file private int nextByte() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars == -1) return -1; // end of file } return buf[curChar++]; } // to read in entire lines, replace c <= ' ' // with a function that checks whether c is a line break public String next() { int c; do { c = nextByte(); } while (c <= ' '); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nextByte(); } while (c > ' '); return res.toString(); } public int nextInt() { // nextLong() would be implemented similarly int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } public double nextDouble() { return Double.parseDouble(next()); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
ba7d74be24832a01307eef5c29210347
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class cf { static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws IOException, InterruptedException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t--> 0) { int n = sc.nextInt(); pair[] a = new pair[n]; pair[] b = new pair[n]; for (int i = 0; i < a.length; i++) { a[i] = new pair(sc.nextInt(),i); } for (int i = 0; i < b.length; i++) { b[i] = new pair(sc.nextInt(),i); } Arrays.sort(a); Arrays.sort(b); adjList = new ArrayList[n]; for (int i = 0; i < n; i++) { adjList[i] = new ArrayList<>(); } visited = new boolean[n]; for (int i = 0; i < n - 1; i++) { adjList[a[i].y].add(a[i + 1].y); adjList[b[i].y].add(b[i + 1].y); } dfs(a[n - 1].y); char[] ans = new char[n]; for (int i = 0; i < n; i++) { ans[i] = visited[i] ? '1' : '0'; } pw.println(ans); } pw.close(); } static ArrayList<Integer>[] adjList; static boolean[] visited; static void dfs(int u) { visited[u] = true; for (int v : adjList[u]) { if (!visited[v]) { dfs(v); } } } public static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) return this.z - other.z; return this.y - other.y; } else { return this.x - other.x; } } } public static class pair implements Comparable<pair> { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Integer(x).hashCode() * 31 + new Integer(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
60917ed6fe39cf041fc7d738a2462170
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.math.*; public class Final { static final Reader s = new Reader(); static final PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { int t = s.nextInt(); // int t=1; for(int i=1; i<=t; ++i) { // out.print("Case #"+i+": "); new Solver(); } out.close(); } static class Solver { static int[] vis = new int[(int)1e5+7]; static List<Integer> adj[]; static void dfs(int u) { if(vis[u]==1)return; vis[u]=1; List<Integer> a = adj[u]; for(int v:a) { dfs(v); } } Solver() { Arrays.fill(vis, 0); int n = s.nextInt(); long[] a = new long[n]; long[] b = new long[n]; TreeMap<Long,Integer> map1 = new TreeMap<>(); TreeMap<Long,Integer> map2 = new TreeMap<>(); adj = new ArrayList[n]; for(int i=0;i<n;i++)adj[i] = new ArrayList<>(); for(int i=0;i<n;i++) { a[i] = s.nextLong(); map1.put(a[i], i); } for(int i=0;i<n;i++) { b[i] = s.nextLong(); map2.put(b[i], i); } Arrays.sort(a); Arrays.sort(b); for(int i=0;i<n-1;i++) { adj[map1.get(a[i])].add(map1.get(a[i+1])); adj[map2.get(b[i])].add(map2.get(b[i+1])); } dfs(map1.get(a[n-1])); dfs(map2.get(b[n-1])); StringBuilder se = new StringBuilder(""); for(int i=0;i<n;i++) { se.append(vis[i]); } System.out.println(se); } } static class Reader { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; String next() { while(st==null||!st.hasMoreTokens()) { try { st=new StringTokenizer(in.readLine()); } catch(Exception e) {} } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
5332d11c0f4523d481f2780e53b371f8
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class C { static FastScanner fs = new FastScanner(); static PrintWriter pw = new PrintWriter(System.out); static StringBuilder sb = new StringBuilder(""); public static void main(String[] args) { int t = fs.nextInt(); for (int tt = 0; tt < t; tt++) { int n = fs.nextInt(); P[] a = new P[n+1]; P[] b = new P[n+1]; for (int i = 0; i < n+1; i++) { a[i] = new P(0, 0); b[i] = new P(0, 0); } int[] c = new int[n+1]; int[] d = new int[n+1]; for (int i = 1; i <= n; i++) { a[i].fi = fs.nextInt(); a[i].se = i; } for (int i = 1; i <= n; i++) { b[i].fi = fs.nextInt(); b[i].se = i; } Arrays.sort(a); Arrays.sort(b); for (int i = 1; i <= n; i++) c[b[i].se] = i; int min = n + 1; for (int i = n; i >= 1; i--) { min = Math.min(min, c[a[i].se]); d[a[i].se] = 1; if (min == i) { for (int j = 1; j <= n; j++) sb.append(d[j]); sb.append("\n"); break; } } } pw.print(sb.toString()); pw.close(); } static class P implements Comparable<P> { int fi, se; public P(int fi, int se) { this.fi = fi; this.se = se; } public int compareTo(P o) { return Integer.compare(fi, o.fi); } } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() {while (!st.hasMoreTokens())try {st = new StringTokenizer(br.readLine());} catch (IOException e) {}return st.nextToken();} int nextInt() {return Integer.parseInt(next());} long nextLong() {return Long.parseLong(next());} double nextDouble() {return Double.parseDouble(next());} int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) {a[i] = nextInt();} return a;} } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
9299655097f68ff9947ef10198f8b46d
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class Solution { static Scanner sc = new Scanner(System.in); // static Reader sc = new Reader(); static StringBuilder out = new StringBuilder(); static String testCase = "Case #"; static long mod = 998244353; public static void main(String[] args) throws IOException { // TODO Auto-generated method stub int t = sc.nextInt(); int tc = 0; while (tc++ < t) { Solution run = new Solution(); run.run(); } System.out.println(out); } static ArrayList<Integer> gr[]; public void run() throws IOException { int n=sc.nextInt(); int a[][]=new int [n][2]; int b[][]=new int [n][2]; gr=new ArrayList[n]; for(int i=0;i<n;i++) { a[i][0]=sc.nextInt(); a[i][1]=i; gr[i]=new ArrayList<Integer>(); } for(int i=0;i<n;i++) { b[i][0]=sc.nextInt(); b[i][1]=i; } Arrays.sort(a,(c,d)-> (d[0]-c[0])); Arrays.sort(b,(c,d)-> (d[0]-c[0])); for(int i=1;i<n;i++) { gr[a[i][1]].add(a[i-1][1]); gr[b[i][1]].add(b[i-1][1]); } int root=0; if(a[0][0]>=b[0][0]) { root=a[0][1]; } else root= b[0][1]; visit =new boolean [n]; dfs(root); for(int i=0;i<n;i++) { if(visit[i])out.append(1); else out.append(0); } out.append("\n"); } static boolean visit[]; static void dfs(int u) { visit[u]=true; for(int ch : gr[u]) { if(!visit[ch]) { dfs(ch); } } } static int bit[]; static void modify(int x, int val) { for (; x < bit.length; x += (x & -x)) bit[x] += val; } static int get(int x) { int sum = 0; for (; x > 0; x -= (x & -x)) sum += bit[x]; return sum; } static long modInverse(long a, long m) { long m0 = m; long y = 0, x = 1; if (m == 1) return 0; while (a > 1) { // q is quotient long q = a / m; long t = m; m = a % m; a = t; t = y; // Update x and y y = x - q * y; x = t; } // Make x positive if (x < 0) x += m0; return x; } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
b976f5d999a729e74a2cb33c0ede8181
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.InputMismatchException; import java.util.StringTokenizer; public class AA3 { void solve() { int n = cint(); int[] a = carr_int(n); int[] b = carr_int(n); P[] p = new P[n]; for (int i = 0; i < n; i++) { p[i] = new P(a[i], b[i]); } P[] byA = Arrays.copyOf(p, n); Arrays.sort(byA, Comparator.comparingInt((P o) -> o.a).reversed()); P[] byB = Arrays.copyOf(p, n); Arrays.sort(byB, Comparator.comparingInt((P o) -> o.b).reversed()); int ia = 0, ib = 0; int minA = byB[0].a; int minB = byA[0].b; boolean ok = true; while (ok) { ok = false; for (; ia < n && byA[ia].a >= minA; ia++) { byA[ia].win = true; minB = Math.min(minB, byA[ia].b); ok = true; } for (; ib < n && byB[ib].b >= minB; ib++) { byB[ib].win = true; minA = Math.min(minA, byB[ib].a); ok = true; } } StringBuilder s = new StringBuilder(); for (P x : p) { s.append(x.win ? '1' : '0'); } cout(s); } class P { final int a; final int b; boolean win; public P(int a, int b) { this.a = a; this.b = b; } } public static void main(String... args) { int t = in.nextInt(); for (int test = 0; test < t; test++) { new AA3().solve(); } out.flush(); } static final QuickReader in = new QuickReader(System.in); static final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, 131_072)); static int cint() { return in.nextInt(); } static long clong() { return in.nextLong(); } static String cstr() { return in.nextLine(); } static int[] carr_int(int n) { return in.nextInts(n); } static long[] carr_long(int n) { return in.nextLongs(n); } static void cout(int... a) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < a.length; i++) { if (i != 0) { buf.append(' '); } buf.append(a[i]); } out.println(buf); } static void cout(long... a) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < a.length; i++) { if (i != 0) { buf.append(' '); } buf.append(a[i]); } out.println(buf); } static void cout(Object o) { out.println(o); } static class QuickReader { BufferedReader in; StringTokenizer token; public QuickReader(InputStream ins) { in = new BufferedReader(new InputStreamReader(ins)); token = new StringTokenizer(""); } public boolean hasNext() { while (!token.hasMoreTokens()) { try { String s = in.readLine(); if (s == null) { return false; } token = new StringTokenizer(s); } catch (IOException e) { throw new InputMismatchException(); } } return true; } public String next() { hasNext(); return token.nextToken(); } public String nextLine() { try { String s = in.readLine(); token = new StringTokenizer(""); return s; } catch (IOException e) { throw new InputMismatchException(); } } public int nextInt() { return Integer.parseInt(next()); } public int[] nextInts(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = nextInt(); } return res; } public long nextLong() { return Long.parseLong(next()); } public long[] nextLongs(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) { res[i] = nextLong(); } return res; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
16b9a566697a2b7c86d55d0104c98730
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class Main { InputStream is; FastWriter out; String INPUT = ""; void run() throws Exception { is = System.in; out = new FastWriter(System.out); solve(); out.flush(); } public static void main(String[] args) throws Exception { new Main().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private int ni() { return (int)nl(); } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{return minus ? -num : num;} b = readByte(); } } private class Pair { int first; int second; Pair(int a, int b) { first = a; second = b; } } public static class FastWriter { private static final int BUF_SIZE = 1<<13; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastWriter(){out = null;} public FastWriter(OutputStream os) { this.out = os; } public FastWriter(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException("FastWriter"); } } public FastWriter write(byte b) { buf[ptr++] = b; if(ptr == BUF_SIZE)innerflush(); return this; } public FastWriter write(char c) { return write((byte)c); } public FastWriter write(char[] s) { for(char c : s){ buf[ptr++] = (byte)c; if(ptr == BUF_SIZE)innerflush(); } return this; } public FastWriter write(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte)c; if(ptr == BUF_SIZE)innerflush(); }); return this; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } public FastWriter write(int x) { if(x == Integer.MIN_VALUE){ return write((long)x); } if(ptr + 12 >= BUF_SIZE)innerflush(); if(x < 0){ write((byte)'-'); x = -x; } int d = countDigits(x); for(int i = ptr + d - 1;i >= ptr;i--){ buf[i] = (byte)('0'+x%10); x /= 10; } ptr += d; return this; } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } public FastWriter write(long x) { if(x == Long.MIN_VALUE){ return write("" + x); } if(ptr + 21 >= BUF_SIZE)innerflush(); if(x < 0){ write((byte)'-'); x = -x; } int d = countDigits(x); for(int i = ptr + d - 1;i >= ptr;i--){ buf[i] = (byte)('0'+x%10); x /= 10; } ptr += d; return this; } public FastWriter write(double x, int precision) { if(x < 0){ write('-'); x = -x; } x += Math.pow(10, -precision)/2; write((long)x).write("."); x -= (long)x; for(int i = 0;i < precision;i++){ x *= 10; write((char)('0'+(int)x)); x -= (int)x; } return this; } public FastWriter writeln(char c){ return write(c).writeln(); } public FastWriter writeln(int x){ return write(x).writeln(); } public FastWriter writeln(long x){ return write(x).writeln(); } public FastWriter writeln(double x, int precision){ return write(x, precision).writeln(); } public FastWriter write(int... xs) { boolean first = true; for(int x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter write(long... xs) { boolean first = true; for(long x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter writeln() { return write((byte)'\n'); } public FastWriter writeln(int... xs) { return write(xs).writeln(); } public FastWriter writeln(long... xs) { return write(xs).writeln(); } public FastWriter writeln(char[] line) { return write(line).writeln(); } public FastWriter writeln(char[]... map) { for(char[] line : map)write(line).writeln(); return this; } public FastWriter writeln(String s) { return write(s).writeln(); } private void innerflush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (IOException e) { throw new RuntimeException("innerflush"); } } public void flush() { innerflush(); try { out.flush(); } catch (IOException e) { throw new RuntimeException("flush"); } } public FastWriter print(byte b) { return write(b); } public FastWriter print(char c) { return write(c); } public FastWriter print(char[] s) { return write(s); } public FastWriter print(String s) { return write(s); } public FastWriter print(int x) { return write(x); } public FastWriter print(long x) { return write(x); } public FastWriter print(double x, int precision) { return write(x, precision); } public FastWriter println(char c){ return writeln(c); } public FastWriter println(int x){ return writeln(x); } public FastWriter println(long x){ return writeln(x); } public FastWriter println(double x, int precision){ return writeln(x, precision); } public FastWriter print(int... xs) { return write(xs); } public FastWriter print(long... xs) { return write(xs); } public FastWriter println(int... xs) { return writeln(xs); } public FastWriter println(long... xs) { return writeln(xs); } public FastWriter println(char[] line) { return writeln(line); } public FastWriter println(char[]... map) { return writeln(map); } public FastWriter println(String s) { return writeln(s); } public FastWriter println() { return writeln(); } } void solve() { int t = ni(); while(t --> 0) { int n = ni(); int[] a = new int[n], b = new int[n]; for (int i = 0;i < n;i++) a[i] = ni(); for (int i = 0;i < n;i++) b[i] = ni(); PriorityQueue<Integer> pqa = new PriorityQueue<>((l, r) -> Integer.compare(a[r], a[l])); PriorityQueue<Integer> pqb = new PriorityQueue<>((l, r) -> Integer.compare(b[r], b[l])); for(int i = 0;i < n;i++) { pqa.add(i); pqb.add(i); } int amax = a[pqa.peek()], bmax = b[pqb.peek()]; while(!pqb.isEmpty() && b[pqb.peek()] >= bmax || !pqa.isEmpty() && a[pqa.peek()] >= amax) { while(!pqb.isEmpty() && b[pqb.peek()] >= bmax) { amax = Math.min(amax, a[pqb.poll()]); } while(!pqa.isEmpty() && a[pqa.peek()] >= amax) { bmax = Math.min(bmax, b[pqa.poll()]); } } for(int i = 0;i < n;i++) { if(a[i] >= amax || b[i] >= bmax) out.print('1'); else out.print('0'); } out.println(); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
0cadd8381a78b6ad0cfe8a0acf85c095
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class c { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int numcases = Integer.parseInt(in.readLine()); StringBuilder b = new StringBuilder(); for (int casenum = 0; casenum < numcases; casenum++) { int n = Integer.parseInt(in.readLine()); int[][] data = new int[2][n]; for (int i = 0; i < 2; i++) { StringTokenizer tokenizer = new StringTokenizer(in.readLine()); for (int j = 0; j < n; j++) { data[i][j] = Integer.parseInt(tokenizer.nextToken()); } } tuple m1 = null; tuple m2 = null; tuple[] t = new tuple[n]; tuple[] t1 = new tuple[n]; tuple[] t2 = new tuple[n]; for (int i = 0; i < n; i++) { t[i] = t2[i] = t1[i] = new tuple(i, data[0][i], data[1][i]); if (m1 == null || t[i].first > m1.first) m1 = t[i]; if (m2 == null || t[i].second > m2.second) m2 = t[i]; } Arrays.sort(t1, new comp1()); Arrays.sort(t2, new comp2()); for (int i = 0; i < t1.length; i++) { t1[i].a1 = i; t2[i].a2 = i; } int i1 = m1.a1; int i2 = m2.a2; LinkedList<Integer> l1 = new LinkedList<>(); LinkedList<Integer> l2 = new LinkedList<>(); l1.addFirst(m1.a1); l2.addFirst(m2.a2); l1.addFirst(m2.a1); l2.addFirst(m1.a2); while (l1.get(0) < l1.get(1) || l2.get(0) < l2.get(1)) { i1 = l1.get(0); i2 = l1.get(1); int mindex = l2.get(0); for (int i = i1; i <= i2; i++) { mindex = Math.min(mindex, t1[i].a2); } i1 = l2.get(0); i2 = l2.get(1); l2.addFirst(mindex); mindex = l1.get(0); for (int i = i1; i <= i2; i++) { mindex = Math.min(mindex, t2[i].a1); } l1.addFirst(mindex); } // System.out.println("case " + casenum); // System.out.println("min 1: " + t1[l1.get(0)].first + " min 2: " + // t2[l2.get(0)].second); int min1 = t1[l1.get(0)].first; int min2 = t2[l2.get(0)].second; for (int i = 0; i < t.length; i++) { b.append(t[i].first >= min1 || t[i].second >= min2 ? 1 : 0); } b.append("\n"); } System.out.print(b); in.close(); out.close(); } public static class comp1 implements Comparator<tuple> { @Override public int compare(c.tuple o1, c.tuple o2) { return o1.first - o2.first; } } public static class comp2 implements Comparator<tuple> { @Override public int compare(c.tuple o1, c.tuple o2) { return o1.second - o2.second; } } public static class tuple { int id; int first; int second; int a1; int a2; @Override public String toString() { return this.id + " " + first + " " + second + " " + a1 + " " + a2; } public tuple(int id, int first, int second) { this.id = id; this.first = first; this.second = second; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
19ae7cc884adfc9716b4fb00faedfac2
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; // THIS TEMPLATE MADE BY AKSH BANSAL. public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static void sort(int a[]){ // int -> long ArrayList<Integer> arr=new ArrayList<>(); // Integer -> Long for(int i=0;i<a.length;i++) arr.add(a[i]); Collections.sort(arr); for(int i=0;i<a.length;i++) a[i]=arr.get(i); } private static long gcd(long a, long b){ if(b==0)return a; return gcd(b,a%b); } private static long pow(long x,long y){ if(y==0)return 1; long temp = pow(x, y/2); if(y%2==1){ return x*temp*temp; } else{ return temp*temp; } } static int log(long n){ int res = 0; while(n>0){ res++; n/=2; } return res; } static int mod = (int)1e9+7; static PrintWriter out; static FastReader sc ; public static void main(String[] args) throws IOException { sc = new FastReader(); out = new PrintWriter(System.out); // primes(); // ________________________________ int test = sc.nextInt(); StringBuilder output = new StringBuilder(); while (test-- > 0) { int n = sc.nextInt(); int[][]arr = new int[n][3]; for(int i=0;i<n;i++){ arr[i][1] = sc.nextInt(); arr[i][0] = i; } for(int i=0;i<n;i++){ arr[i][2] = sc.nextInt(); } solver(arr, n); } out.print(output); // _______________________________ // int n = sc.nextInt(); // out.println(solver()); // ________________________________ out.flush(); } public static void solver(int[][] one, int n) { int[][] two = one.clone(); Arrays.sort(one, (a,b)->b[1]-a[1]); Arrays.sort(two, (a,b)->b[2]-a[2]); boolean[]vis = new boolean[n]; int pos1 = 1; int pos2 = 0; int a = one[0][1]; int b = one[0][2]; vis[one[0][0]] = true; while((pos1<n && pos2<n) ){ // System.out.println(a+" "+b+"__"+one[pos1][0]+ "__"+two[pos2][0]); if(one[pos1][1]>a){ if(vis[one[pos1][0]]){ pos1++; continue; } b = Math.min(b, one[pos1][2]); vis[one[pos1][0]] = true; pos1++; } else if (two[pos2][2]>b){ if(vis[two[pos2][0]]){ pos2++; continue; } a = Math.min(a, two[pos2][1]); vis[two[pos2][0]] = true; pos2++; } else break; } for(int i=0;i<n;i++){ if(vis[i]) out.print(1); else out.print(0); } out.println(); } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
009d5b5ee5072787128f084511c8d9db
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class solve { static boolean[]ans; static ArrayList<Integer>[]graph; static void dfs(int node) { ans[node]=true; for(int i:graph[node]) { if(!ans[i])dfs(i); } } public static void main(String[] args) throws Exception { int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); Integer[][]a=new Integer[n][2]; for(int i=0;i<n;i++) { a[i][0]=sc.nextInt(); a[i][1]=i; } Arrays.sort(a,(x,y)->x[0]-y[0]); Integer[][]b=new Integer[n][2]; for(int i=0;i<n;i++) { b[i][0]=sc.nextInt(); b[i][1]=i; } Arrays.sort(b,(x,y)->x[0]-y[0]); ans=new boolean[n]; graph=new ArrayList[n]; for(int i=0;i<n;i++)graph[i]=new ArrayList<Integer>(); for(int i=1;i<n;i++) { graph[a[i-1][1]].add(a[i][1]); graph[b[i-1][1]].add(b[i][1]); } dfs(a[n-1][1]); for(boolean i:ans) pw.print(i?1:0); pw.println(); } pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } static class pair implements Comparable<pair> { long x; long y; public pair(long x, long y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Long(x).hashCode() * 31 + new Long(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) { return this.z - other.z; } return this.y - other.y; } else { return this.x - other.x; } } } static long mod = 1000000007; static Random rn = new Random(); static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
4f1c4256f5cc2b654f46524201002162
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class CMain { private boolean[] used; public static void main(String[] args) { QuickReader in = new QuickReader(System.in); try(PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));) { new CMain().solve(in, out); } } public void solve(QuickReader in, PrintWriter out) { int T = in.nextInt(); while(T-->0) { int n = in.nextInt(); final int[] a = in.nextInts(n); final int[] b = in.nextInts(n); Integer[] id = new Integer[n]; for(int i=0;i<n;i++) id[i] = i; ArrayList<ArrayList<Integer> > g = new ArrayList<ArrayList<Integer>>(); ArrayList<ArrayList<Integer> > gr = new ArrayList<ArrayList<Integer>>(); for(int i=0;i<n;i++) { g.add(new ArrayList<>()); gr.add(new ArrayList<>()); } Arrays.sort(id, new Comparator<Integer>() { @Override public int compare(Integer arg0, Integer arg1) { return Integer.compare(a[arg0], a[arg1]); } }); for(int i=1;i<n;i++) { g.get(id[i]).add(id[i-1]); gr.get(id[i-1]).add(id[i]); } Arrays.sort(id, new Comparator<Integer>() { @Override public int compare(Integer arg0, Integer arg1) { return Integer.compare(b[arg0], b[arg1]); } }); for(int i=1;i<n;i++) { g.get(id[i]).add(id[i-1]); gr.get(id[i-1]).add(id[i]); } used = new boolean[n]; ArrayList<Integer> order = new ArrayList<>(); for(int i=0;i<n;i++) if(!used[i]) dfs(i, g, order); for(int i=0;i<n;i++) used[i] = false; dfs(order.get(n-1), gr, null); for(int i=0;i<n;i++) out.print(used[i]?'1':'0'); out.println(); } } private void dfs(int cur, ArrayList<ArrayList<Integer>> g, ArrayList<Integer> output) { if(used[cur]) return; used[cur] = true; for(int to: g.get(cur)) dfs(to, g, output); if(output != null) output.add(cur); } } class QuickReader { BufferedReader in; StringTokenizer token; public QuickReader(InputStream ins) { in=new BufferedReader(new InputStreamReader(ins)); token=new StringTokenizer(""); } public boolean hasNext() { while (!token.hasMoreTokens()) { try { String s = in.readLine(); if (s == null) return false; token = new StringTokenizer(s); } catch (IOException e) { throw new InputMismatchException(); } } return true; } public String next() { hasNext(); return token.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public int[] nextInts(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } public long nextLong() { return Long.parseLong(next()); } public long[] nextLongs(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
68c69aeb1b21274a72a7ed54ba7525d0
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(); PrintWriter out = new PrintWriter(System.out); int tc=sc.nextInt(); while (tc-->0){ int n=sc.nextInt(); TreeMap<Integer,Integer>mapA=new TreeMap<>(),mapB=new TreeMap<>(); int[]a=new int [n],b=new int [n]; for(int i=0;i<n;i++){ int x=sc.nextInt(); a[i]=x; mapA.put(x,i); } for(int i=0;i<n;i++){ int x=sc.nextInt(); b[i]=x; mapB.put(x,i); } Map.Entry<Integer, Integer> maxA=mapA.pollLastEntry(); boolean[]ans=new boolean[n]; ans[maxA.getValue()]=true; int thresh = b[maxA.getValue()]; for(int i=0;!mapA.isEmpty() || !mapB.isEmpty();i=1-i){ TreeMap<Integer,Integer>map=i==0?mapB:mapA; int []otherValues = i==0?a:b; int min=Integer.MAX_VALUE; boolean enter=false; ArrayList<Integer> tmp=new ArrayList<>(); for (Map.Entry<Integer, Integer> entry:map.subMap(thresh, Integer.MAX_VALUE).entrySet()){ enter = true; int currIndex = entry.getValue(); min=Math.min(min, otherValues[currIndex]); ans[currIndex]=true; tmp.add(entry.getKey()); } for(int x:tmp) map.remove(x); if(!enter) break; thresh = min; } for(boolean bool:ans) out.print(bool?1:0); out.println(); } out.close(); } static class Scanner { BufferedReader br; StringTokenizer st; Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); } Scanner(String fileName) throws FileNotFoundException { br = new BufferedReader(new FileReader(fileName)); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } String nextLine() throws IOException { return br.readLine(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws NumberFormatException, IOException { return Long.parseLong(next()); } double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(next()); } boolean ready() throws IOException { return br.ready() || st.hasMoreTokens(); } int[] nxtArr(int n) throws IOException { int[] ans = new int[n]; for (int i = 0; i < n; i++) ans[i] = nextInt(); return ans; } } static void sort(int[] a) { shuffle(a); Arrays.sort(a); } static void shuffle(int[] a) { int n = a.length; Random rand = new Random(); for (int i = 0; i < n; i++) { int tmpIdx = rand.nextInt(n); int tmp = a[i]; a[i] = a[tmpIdx]; a[tmpIdx] = tmp; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 11
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
e9a283587114ab85f593984e3b93fc52
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
/* Goal: Become better in CP! Key: Consistency and Discipline Desire: SDE @ Google USA Motto: Do what i Love <=> Love what i do If you don't use your brain 100%, it deteriorates gradually */ import java.util.*; import java.io.*; import java.math.*; public class Code { static StringBuffer str=new StringBuffer(); static BufferedReader bf; static PrintWriter pw; static long a[], b[]; static int n; static long smn[][]; static long [][]smx; // Sparse min and max static void build(){ int sz=(int)(Math.log(n)/Math.log(2)); smn=new long[n][sz+1]; smx=new long[n][sz+1]; for(int i=0;i<n;i++){smn[i][0]=b[i];smx[i][0]=b[i];} for(int j=1;j<=sz;j++){ for(int i=0;(i+(1<<j)-1)<n;i++){ smn[i][j]=Math.min(smn[i][j-1], smn[i+(1<<(j-1))][j-1]); smx[i][j]=Math.max(smx[i][j-1], smx[i+(1<<(j-1))][j-1]); } } } static long queryMin(int l, int r){ int len=r-l+1; int p=(int)(Math.log(len)/Math.log(2)); int k=(int)Math.pow(2, p); return Math.min(smn[l][p], smn[r-k+1][p]); } static long queryMax(int l, int r){ int len=r-l+1; int p=(int)(Math.log(len)/Math.log(2)); int k=(int)Math.pow(2, p); return Math.max(smx[l][p], smx[r-k+1][p]); } static void solve(int te) throws Exception{ List<long []> l=new ArrayList<>(); for(int i=0;i<n;i++){ l.add(new long[]{a[i], b[i], i}); } Collections.sort(l, (p, q)->{ if(p[0]>q[0]) return -1; else if(p[0]<q[0]) return 1; return 0; }); int idx[]=new int[n]; int ans[]=new int[n]; for(int i=0;i<n;i++){ a[i]=l.get(i)[0]; b[i]=l.get(i)[1]; idx[i]=(int)l.get(i)[2]; } build(); ans[idx[0]]=1; for(int i=1;i<n;i++){ if(queryMin(0, i-1)<queryMax(i, n-1)) ans[idx[i]]=1; else break; } for(int i=0;i<n;i++) str.append(ans[i]); str.append("\n"); } public static void main(String[] args) throws java.lang.Exception { boolean lenv=false; if(lenv){ bf = new BufferedReader( new FileReader("input.txt")); pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); }else{ bf = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new OutputStreamWriter(System.out)); } int q1 = Integer.parseInt(bf.readLine().trim()); for(int te=1;te<=q1;te++) { n=Integer.parseInt(bf.readLine().trim()); a=new long[n]; b=new long[n]; String []s=bf.readLine().trim().split("\\s+"); for(int i=0;i<n;i++) a[i]=Long.parseLong(s[i]); s=bf.readLine().trim().split("\\s+"); for(int i=0;i<n;i++) b[i]=Long.parseLong(s[i]); solve(te); } pw.print(str); pw.flush(); // System.out.println(str); } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
4932caffc40b5be2f17db7b125a860f5
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
/* Goal: Become better in CP! Key: Consistency and Discipline Desire: SDE @ Google USA Motto: Do what i Love <=> Love what i do If you don't use your brain 100%, it deteriorates gradually */ import java.util.*; import java.io.*; import java.math.*; public class Code { static StringBuffer str=new StringBuffer(); static BufferedReader bf; static PrintWriter pw; static long a[], b[]; static int n; static long smn[][]; static long [][]smx; // Sparse min and max static void build(){ int sz=(int)(Math.log(n)/Math.log(2)); smx=new long[n][sz+1]; smn=new long[n][sz+1]; for(int i=0;i<n;i++){smx[i][0]=b[i];smn[i][0]=b[i];} for(int j=1;j<=sz;j++){ for(int i=0;(i+(1<<j)-1)<n;i++){ smx[i][j]=Math.max(smx[i][j-1], smx[i+(1<<(j-1))][j-1]); smn[i][j]=Math.max(smn[i][j-1], smn[i+(1<<(j-1))][j-1]); } } } static long queryMax(int l, int r){ int len=r-l+1; int p=(int)(Math.log(len)/Math.log(2)); int k=(int)Math.pow(2, p); return Math.max(smx[l][p], smx[r-k+1][p]); } static long queryMin(int l, int r){ int len=r-l+1; int p=(int)(Math.log(len)/Math.log(2)); int k=(int)Math.pow(2, p); return Math.min(smn[l][p], smn[r-k+1][p]); } static void solve(int te) throws Exception{ List<long []> l=new ArrayList<>(); for(int i=0;i<n;i++){ l.add(new long[]{a[i], b[i], i}); } Collections.sort(l, (p, q)->{ if(p[0]>q[0]) return -1; else if(p[0]<q[0]) return 1; return 0; }); int idx[]=new int[n]; int ans[]=new int[n]; for(int i=0;i<n;i++){ a[i]=l.get(i)[0]; b[i]=l.get(i)[1]; idx[i]=(int)l.get(i)[2]; } long max[]=new long[n]; max[n-1]=b[n-1]; for(int i=n-2;i>=0;i--) max[i]=Math.max(max[i+1], b[i]); long min=b[0]; ans[idx[0]]=1; for(int i=1;i<n;i++){ if(min<max[i]) ans[idx[i]]=1; else break; min=Math.min(min, b[i]); } for(int i=0;i<n;i++) str.append(ans[i]); str.append("\n"); } public static void main(String[] args) throws java.lang.Exception { boolean lenv=false; if(lenv){ bf = new BufferedReader( new FileReader("input.txt")); pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); }else{ bf = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new OutputStreamWriter(System.out)); } int q1 = Integer.parseInt(bf.readLine().trim()); for(int te=1;te<=q1;te++) { n=Integer.parseInt(bf.readLine().trim()); a=new long[n]; b=new long[n]; String []s=bf.readLine().trim().split("\\s+"); for(int i=0;i<n;i++) a[i]=Long.parseLong(s[i]); s=bf.readLine().trim().split("\\s+"); for(int i=0;i<n;i++) b[i]=Long.parseLong(s[i]); solve(te); } pw.print(str); pw.flush(); // System.out.println(str); } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
7690e0ff011dc49874b4f140c536cd94
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
/* Challenge 1: Newbie to CM in 1year (Dec 2021 - Nov 2022) 🔥 5* Codechef Challenge 2: CM to IM in 1 year (Dec 2022 - Nov 2023) 🔥🔥 6* Codechef Challenge 3: IM to GM in 1 year (Dec 2023 - Nov 2024) 🔥🔥🔥 7* Codechef Goal: Become better in CP! Key: Consistency! */ import java.util.*; import java.io.*; import java.math.*; public class Coder { static StringBuffer str=new StringBuffer(); static int n; static int []a; static int []b; static void solve(){ List<int []> l=new ArrayList<>(); for(int i=0;i<n;i++){ l.add(new int[]{a[i], b[i], i}); } Collections.sort(l, (p, q) -> p[0]-q[0]); int pmax[]=new int[n]; pmax[0]=l.get(0)[1]; for(int i=1;i<n;i++){ pmax[i]=Math.max(pmax[i-1], l.get(i)[1]); } int res[]=new int[n]; res[l.get(n-1)[2]]=1; int min=l.get(n-1)[1]; for(int i=n-2;i>=0;i--){ if(pmax[i]>min){ res[l.get(i)[2]]=1; }else break; min=Math.min(min, l.get(i)[1]); } for(int i=0;i<n;i++) str.append(res[i]); str.append("\n"); } public static void main(String[] args) throws java.lang.Exception { BufferedReader bf; PrintWriter pw; boolean lenv=false; if(lenv){ bf = new BufferedReader( new FileReader("input.txt")); pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); }else{ bf = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new OutputStreamWriter(System.out)); } int t = Integer.parseInt(bf.readLine().trim()); while (t-- > 0) { String []st=bf.readLine().trim().split("\\s+"); n=Integer.parseInt(st[0]); st=bf.readLine().trim().split("\\s+"); a=new int[n]; b=new int[n]; for(int i=0;i<n;i++) a[i]=Integer.parseInt(st[i]); st=bf.readLine().trim().split("\\s+"); for(int i=0;i<n;i++) b[i]=Integer.parseInt(st[i]); solve(); } pw.print(str); pw.flush(); // System.outin.print(str); } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
e828e9fe152235072af3969d0bcbb2f0
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class new1{ public static void dfs(ArrayList<ArrayList<Integer>> aList, int u, int[] vis) { vis[u] = 1; for(Integer x : aList.get(u)) { if(vis[x] == 0) { dfs(aList, x, vis); } } } public static void main(String[] args) throws IOException{ BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); FastReader s = new FastReader(); int t = s.nextInt(); for(int z = 0; z < t; z++) { int n = s.nextInt(); ArrayList<int[]> aList1 = new ArrayList<int[]>(); ArrayList<int[]> aList2 = new ArrayList<int[]>(); for(int i = 0; i < n; i++) { int[] aa = {s.nextInt(), i + 1}; aList1.add(aa); } for(int i = 0; i < n; i++) { int[] aa = {s.nextInt(), i + 1}; aList2.add(aa); } aList1.sort(new Comparator<int[]>() { public int compare(int[] a, int[] b) { return -Integer.compare(a[0], b[0]); } }); aList2.sort(new Comparator<int[]>() { public int compare(int[] a, int[] b) { return -Integer.compare(a[0], b[0]); } }); ArrayList<ArrayList<Integer> > aList = new ArrayList<ArrayList<Integer> >(n + 1); for (int j = 1; j <= n + 1; j++) { ArrayList<Integer> list = new ArrayList<>(); aList.add(list); } for(int i = 0; i < n - 1; i++) { int a = aList1.get(i)[1]; int b = aList1.get(i + 1)[1]; int c = aList2.get(i)[1]; int d = aList2.get(i + 1)[1]; aList.get(b).add(a); aList.get(d).add(c); } int par = aList1.get(0)[1]; int[] vis = new int[n + 1]; dfs(aList, par, vis); StringBuilder str = new StringBuilder(""); for(int i = 1; i <= n; i++) { if(vis[i] == 1) str = str.append("1"); else str = str.append("0"); } System.out.println(str.toString()); } // output.flush(); } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; }}
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
79f3796714788ce0ffd5e11b3cc1f222
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class A { //--------------------------INPUT READER---------------------------------// static class fs { public BufferedReader br; StringTokenizer st = new StringTokenizer(""); public fs() { this(System.in); } public fs(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } long nl() { return Long.parseLong(next()); } double nd() { return Double.parseDouble(next()); } String ns() { return next(); } int[] na(long nn) { int n = (int) nn; int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } long[] nal(long nn) { int n = (int) nn; long[] l = new long[n]; for(int i = 0; i < n; i++) l[i] = nl(); return l; } } //-----------------------------------------------------------------------// //---------------------------PRINTER-------------------------------------// static class Printer { static PrintWriter w; public Printer() {this(System.out);} public Printer(OutputStream os) { w = new PrintWriter(os); } public void p(int i) {w.println(i);} public void p(long l) {w.println(l);} public void p(double d) {w.println(d);} public void p(String s) { w.println(s);} public void pr(int i) {w.print(i);} public void pr(long l) {w.print(l);} public void pr(double d) {w.print(d);} public void pr(String s) { w.print(s);} public void pl() {w.println();} public void close() {w.close();} } //-----------------------------------------------------------------------// //--------------------------VARIABLES------------------------------------// static fs sc = new fs(); static OutputStream outputStream = System.out; static Printer w = new Printer(outputStream); static long lma = Long.MAX_VALUE, lmi = Long.MIN_VALUE; static long ima = Integer.MAX_VALUE, imi = Integer.MIN_VALUE; static long mod = 1000000007; //-----------------------------------------------------------------------// //--------------------------ADMIN_MODE-----------------------------------// private static void ADMIN_MODE() throws IOException { if (System.getProperty("ONLINE_JUDGE") == null) { w = new Printer(new FileOutputStream("output.txt")); sc = new fs(new FileInputStream("input.txt")); } } //-----------------------------------------------------------------------// //----------------------------START--------------------------------------// public static void main(String[] args) throws IOException { ADMIN_MODE(); int t = sc.ni();while(t-->0) solve(); w.close(); } static void solve() throws IOException { int n = sc.ni(); pr[] sortA = new pr[n]; pr[] sortB = new pr[n]; for(int i = 0; i < n; i++) { int curr = sc.ni(); sortA[i] = new pr(curr, -1, i); sortB[i] = new pr(curr, -1, i); } for(int i = 0; i < n; i++) { int curr = sc.ni(); sortA[i].b = curr; sortB[i].b = curr; } Arrays.sort(sortA, (a,b)->-1*Integer.compare(a.a, b.a)); Arrays.sort(sortB, (a,b)->-1*Integer.compare(a.b, b.b)); HashSet<Integer> hs = new HashSet<>(); hs.add(sortA[0].id); hs.add(sortB[0].id); int amin = Math.min(sortA[0].a, sortB[0].a); int bmin = Math.min(sortA[0].b, sortB[0].b); int pt1 = 1, pt2 = 1; while(pt1 < n || pt2 < n) { int one = pt1, two = pt2; if(pt1 < n && sortA[pt1].a > amin) { bmin = Math.min(bmin, sortA[pt1].b); amin = Math.min(amin, sortA[pt1].a); hs.add(sortA[pt1].id); pt1++; } if(pt2 < n && sortB[pt2].b > bmin) { amin = Math.min(amin, sortB[pt2].a); bmin = Math.min(bmin, sortB[pt2].b); hs.add(sortB[pt2].id); pt2++; } if(one == pt1 && two == pt2) break; } for(int i = 0; i < n; i++) { w.pr(hs.contains(i)?"1":"0"); } w.pl(); } static class pr { int a, b, id; public pr(int a, int b, int id) { this.a = a; this.b = b; this.id = id; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
59cf0b525ed9cac2e74916d95e65f79f
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-->0) { int n=sc.nextInt(); Player[] a=new Player[n+1]; Player[] b=new Player[n+1]; for(int i=1;i<=n;i++) { a[i]=new Player(i); b[i]=new Player(i); long t=sc.nextLong(); a[i].setA(t); b[i].setA(t); } for(int i=1;i<=n;i++) { long t=sc.nextLong(); a[i].setB(t); b[i].setB(t); } Arrays.sort(a,1,n+1,new Comparator<Player>() { @Override public int compare(Player o1,Player o2) { if(o1.getA()>o2.getA()) return -1; else if(o1.getA()<o2.getA()) return 1; else return 0; } }); Arrays.sort(b,1,n+1,new Comparator<Player>() { @Override public int compare(Player o1,Player o2) { if(o1.getB()>o2.getB()) return -1; else if(o1.getB()<o2.getB()) return 1; else return 0; } }); long minA=b[1].getA(),minB=a[1].getB(); boolean[] ans=new boolean[n+1]; ans[a[1].getIndex()]=true; ans[b[1].getIndex()]=true; for(int i=2;i<=n;i++) { if(a[i].getA()>minA || a[i].getB()>minB) { ans[a[i].getIndex()]=true; minB=Math.min(minB,a[i].getB()); } if(b[i].getA()>minA || b[i].getB()>minB) { ans[b[i].getIndex()]=true; minA=Math.min(minA,b[i].getA()); } } for(int i=1;i<=n;i++) System.out.print(ans[i] ? "1" : "0"); System.out.println(); } sc.close(); } } class Player { private final int index; private long a; private long b; public Player(int index) { this.index=index; } public void setA(long a) { this.a=a; } public void setB(long b) { this.b=b; } public int getIndex() { return index; } public long getA() { return a; } public long getB() { return b; } @Override public String toString() { return "Player{" + "index=" + index + ", a=" + a + ", b=" + b + '}'; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
fe03005786ff7b55f5aefa5c6f689b20
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-->0) { int n=sc.nextInt(); Player[] a=new Player[n+1]; Player[] b=new Player[n+1]; for(int i=1;i<=n;i++) { a[i]=new Player(i); b[i]=new Player(i); long t=sc.nextLong(); a[i].setA(t); b[i].setA(t); } for(int i=1;i<=n;i++) { long t=sc.nextLong(); a[i].setB(t); b[i].setB(t); } Arrays.sort(a,1,n+1,new Comparator<Player>() { @Override public int compare(Player o1,Player o2) { if(o1.getA()>o2.getA()) return -1; else if(o1.getA()<o2.getA()) return 1; else return 0; } }); Arrays.sort(b,1,n+1,new Comparator<Player>() { @Override public int compare(Player o1,Player o2) { if(o1.getB()>o2.getB()) return -1; else if(o1.getB()<o2.getB()) return 1; else return 0; } }); long minA=b[1].getA(),minB=a[1].getB(); boolean[] ans=new boolean[n+1]; ans[a[1].getIndex()]=true; ans[b[1].getIndex()]=true; for(int i=2;i<=n;i++) { if(a[i].getA()>minA || a[i].getB()>minB) { ans[a[i].getIndex()]=true; minA=Math.min(minA,a[i].getA()); minB=Math.min(minB,a[i].getB()); } if(b[i].getA()>minA || b[i].getB()>minB) { ans[b[i].getIndex()]=true; minA=Math.min(minA,b[i].getA()); minB=Math.min(minB,b[i].getB()); } } for(int i=1;i<=n;i++) System.out.print(ans[i] ? "1" : "0"); System.out.println(); } sc.close(); } } class Player { private final int index; private long a; private long b; public Player(int index) { this.index=index; } public void setA(long a) { this.a=a; } public void setB(long b) { this.b=b; } public int getIndex() { return index; } public long getA() { return a; } public long getB() { return b; } @Override public String toString() { return "Player{" + "index=" + index + ", a=" + a + ", b=" + b + '}'; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
7de47ba01e1a46a9a1de94149d29fd21
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class Main { static FastScanner sc = new FastScanner(System.in); static PrintWriter pw = new PrintWriter(System.out); static StringBuilder sb = new StringBuilder(); static long mod = (long) 1e9 + 7; public static void main(String[] args) throws Exception { int n = sc.nextInt(); for(int i = 0; i < n; i++) solve(); pw.flush(); } static ArrayList<ArrayList<Integer>> arr; static boolean[] usedA,usedB; public static void solve() { int n = sc.nextInt(); int[] a = sc.nextIntArray(n); int[] b = sc.nextIntArray(n); ArrayList<int[]> arrA = new ArrayList<>(); ArrayList<int[]> arrB = new ArrayList<>(); for(int i = 0; i < n; i++){ arrA.add(new int[]{a[i],i}); arrB.add(new int[]{b[i],i}); } Collections.sort(arrA, new ArrayComparator()); Collections.sort(arrB, new ArrayComparator()); arr = new ArrayList<>(); for(int i = 0; i < n; i++){ arr.add(new ArrayList<Integer>()); } for(int i = 0; i < n-1; i++){ int v1 = arrA.get(i)[1]; int v2 = arrA.get(i+1)[1]; arr.get(v2).add(v1); } for(int i = 0; i < n-1; i++){ int v1 = arrB.get(i)[1]; int v2 = arrB.get(i+1)[1]; arr.get(v2).add(v1); } usedA = new boolean[n]; usedB = new boolean[n]; int s1 = arrA.get(0)[1]; int s2 = arrB.get(0)[1]; usedA[s1] = true; usedB[s2] = true; dfs1(s1); dfs2(s2); for(int i = 0; i < n; i++){ //pw.println(usedA[i] + " " + usedB[i]); if(usedA[i] || usedB[i]){ sb.append(1); }else{ sb.append(0); } } pw.println(sb.toString()); sb.setLength(0); } static void dfs1(int now){ for(int next : arr.get(now)){ if(!usedA[next]){ usedA[next] = true; dfs1(next); } } } static void dfs2(int now){ for(int next : arr.get(now)){ if(!usedB[next]){ usedB[next] = true; dfs2(next); } } } static class ArrayComparator implements Comparator<int[]> { @Override public int compare(int[] a1, int[] a2) { for (int i = 0; i < a1.length; i++) { if (a1[i] > a2[i]) { return -1; } else if (a1[i] < a2[i]) { return 1; } } return 0; } } static class GeekInteger { public static void save_sort(int[] array) { shuffle(array); Arrays.sort(array); } public static int[] shuffle(int[] array) { int n = array.length; Random random = new Random(); for (int i = 0, j; i < n; i++) { j = i + random.nextInt(n - i); int randomElement = array[j]; array[j] = array[i]; array[i] = randomElement; } return array; } public static void save_sort(long[] array) { shuffle(array); Arrays.sort(array); } public static long[] shuffle(long[] array) { int n = array.length; Random random = new Random(); for (int i = 0, j; i < n; i++) { j = i + random.nextInt(n - i); long randomElement = array[j]; array[j] = array[i]; array[i] = randomElement; } return array; } } } class FastScanner { private BufferedReader reader = null; private StringTokenizer tokenizer = null; public FastScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } public FastScanner(FileReader in) { reader = new BufferedReader(in); tokenizer = null; } public String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String[] nextArray(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) a[i] = next(); return a; } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
61a2eb59caae524f2f5fa2437b7aaf8d
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class E{ static FastScanner fs = null; static int vis[]; static int mx = -1; static ArrayList<ArrayList<Integer>> list; static ArrayList<ArrayList<Integer>> rev; public static void main(String[] args) { fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); while (t-->0) { int n = fs.nextInt(); vis = new int[n]; Arrays.fill(vis,-1); Pair a[] = new Pair[n]; Pair b[] = new Pair[n]; list = new ArrayList<>(); rev = new ArrayList<>(); for(int i=0;i<n;i++){ list.add(new ArrayList<Integer>()); rev.add(new ArrayList<Integer>()); a[i] = new Pair(fs.nextInt(),i); } for(int i=0;i<n;i++){ b[i] = new Pair(fs.nextInt(),i); } Arrays.sort(a,(o2,o1)->{ return o1.x-o2.x; }); Arrays.sort(b,(o2,o1)->{ return o1.x-o2.x; }); for(int i=1;i<n;i++){ int u = a[i-1].y; int v = a[i].y; // out.println(u+" "+v); list.get(u).add(v); rev.get(v).add(u); u = b[i-1].y; v = b[i].y; // out.println(u+" "+v); list.get(u).add(v); rev.get(v).add(u); } mx = a[0].y; vis[mx] = 1; // out.println(mx+" "); for(int i=0;i<n;i++){ if(vis[i]!=-1) continue; dfs(i,-1,0); } boolean res[] = new boolean[n]; Queue<Integer> queue = new LinkedList<>(); for(int i=0;i<n;i++){ if(vis[i]==1){ queue.add(i); res[i] = true; } } while (!queue.isEmpty()) { int num = queue.remove(); for(Integer p : rev.get(num)){ if(!res[p]){ res[p] = true; queue.add(p); vis[p] = 1; } } } for(int i=0;i<n;i++){ out.print(vis[i]); } out.println(); } out.close(); } static int dfs(int node,int par,int c){ if(node==mx) return 1; if(vis[node]!=-1) return vis[node]; int num = 0; vis[node] = 0; for(Integer p : list.get(node)){ if(p==par) continue; if(vis[p]!=-1){ if(vis[p]==1){ num = 1; } continue; } int x = dfs(p,node,0); if(x==1) num = 1; } if(num==1){ for(Integer p : rev.get(node)){ vis[p] = 1; } } return vis[node] = num; } static class Pair{ int x; int y; Pair(int x,int y){ this.x = x; this.y = y; } } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
abddfd58c8e19656315a6eff7fdbbb2e
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
/* I am dead inside Do you like NCT, sKz, BTS? 5 4 3 2 1 Moonwalk Imma knock it down like domino Is this what you want? Is this what you want? Let's ttalkbocky about that :() */ import static java.lang.Math.*; import java.util.*; import java.io.*; public class x1608C { static ArrayDeque<Integer>[] edges; public static void main(String omkar[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(infile.readLine()); int T = Integer.parseInt(st.nextToken()); StringBuilder sb = new StringBuilder(); while(T-->0) { st = new StringTokenizer(infile.readLine()); int N = Integer.parseInt(st.nextToken()); int[] crr = readArr(N, infile, st); int[] brr = readArr(N, infile, st); Player[] arr = new Player[N]; for(int i=0; i < N; i++) arr[i] = new Player(crr[i], brr[i], i); Arrays.sort(arr); edges = new ArrayDeque[N]; for(int i=0; i < N; i++) edges[i] = new ArrayDeque<Integer>(); for(int i=1; i < N; i++) { int a = arr[i-1].id; int b = arr[i].id; edges[a].add(b); } int best1 = arr[N-1].id; Arrays.sort(arr, (x, y) -> { return x.b-y.b; }); for(int i=1; i < N; i++) { int a = arr[i-1].id; int b = arr[i].id; edges[a].add(b); } int best2 = arr[N-1].id; boolean[] seen = new boolean[N]; ArrayDeque<Integer> q = new ArrayDeque<Integer>(); q.add(best1); seen[best1] = true; if(best1 != best2) { q.add(best2); seen[best2] = true; } while(q.size() > 0) { int curr = q.poll(); for(int next: edges[curr]) if(!seen[next]) { seen[next] = true; q.add(next); } } for(int i=0; i < N; i++) { if(seen[i]) sb.append(1); else sb.append(0); } sb.append("\n"); } System.out.print(sb); } public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception { int[] arr = new int[N]; st = new StringTokenizer(infile.readLine()); for(int i=0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken()); return arr; } } /* guess: player cannot win if and only if there exists some player that beats them on both maps challenge this player with everything if C kills A, but B can defeat C, and if A can defeat B, then A can defeat C c1 > a1, c2 > a2 c1 < b1 or c2 < b2 b1 < a1 or b2 < a2 is this possible? assume c1 < b1 then c1 < b1 implies a1 < b1, this means that a2 > b2 (2, 2) a (3, 3) c (1, 4) b consider list sorted by first value (11, 44) a (12, 22) b (20, 11) c (21, 30) d (25, 10) e (27, 23) f consider player i, i can win if all "right" players can be beaten by a "left" (or itself) player (19, 120) (20, 40) (21, 15) (27, 23) a b a+1 c if b > c, then consider c if b < c, then have to consider c 1 5 2 3 4 6 4 1 5 2 3 */ class Player implements Comparable<Player> { public int a; public int b; public int id; public Player(int c, int d, int i) { a = c; b = d; id = i; } public int compareTo(Player oth) { return a-oth.a; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
68119e12a55d29c47fef05ef5de10a95
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
/* || श्री राम समर्थ || || जय जय रघुवीर समर्थ || */ import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.util.*; import static java.util.Arrays.sort; public class CodeforcesTemp { static Reader scan = new Reader(); static FastPrinter out = new FastPrinter(); static int[] a,b; static int n; public static void main(String[] args) throws IOException { int tt = scan.nextInt(); // int tt = 1; for (int tc = 1; tc <= tt; tc++) { n=scan.nextInt(); Map<Integer,Integer> inda=new HashMap<>(); Map<Integer,Integer> indb=new HashMap<>(); List<Pair> p1=new ArrayList<>(); List<Pair> p2=new ArrayList<>(); for (int i = 0; i < n; i++) { int v= scan.nextInt(); p1.add(new Pair(v,i)); } for (int i = 0; i < n; i++) { int v= scan.nextInt(); p2.add(new Pair(v,i)); } Collections.sort(p1,new SortByval()); Collections.sort(p2,new SortByval()); for (int i = 0; i < n; i++) { inda.put(p1.get(i).b,i); indb.put(p2.get(i).b,i); } a=new int[n]; b=new int[n]; a[0]=indb.get(p1.get(0).b); b[0]=inda.get(p2.get(0).b); for (int i = 1; i < n; i++) { a[i]=Math.max(indb.get(p1.get(i).b),a[i-1]); b[i]=Math.max(inda.get(p2.get(i).b),b[i-1]); } StringBuilder sb=new StringBuilder(); int taken_small_a=Integer.MAX_VALUE; int taken_small_b=Integer.MAX_VALUE; for (int i = 0; i < n; i++) { if(inda.get(i)>taken_small_a || indb.get(i)>taken_small_b){ sb.append(1); continue; } boolean ans1=reachable(a[inda.get(i)],false); if(ans1){ taken_small_a=Math.min(taken_small_a,inda.get(i)); taken_small_b=Math.min(taken_small_b,indb.get(i)); sb.append(1); continue; } boolean ans2=reachable(b[indb.get(i)],true); if(ans2){ taken_small_a=Math.min(taken_small_a,inda.get(i)); taken_small_b=Math.min(taken_small_b,indb.get(i)); sb.append(1); continue; } sb.append(0); } String ans1=sb.toString(); out.println(ans1); out.flush(); } out.close(); } static class Pair{ int a; int b; Pair(int a,int b){ this.a=a; this.b=b; } } private static boolean reachable(int st,boolean a_st){ int start=st; int last=-1; boolean a_s=a_st; if(start==n-1){ return true; } while (start>last){ last=start; if(a_s){ start=a[start]; a_s=false; }else{ start=b[start]; a_s=true; } if(start==n-1){ return true; } } return false; } static class SortByval implements Comparator<Pair>{ @Override public int compare(Pair o1, Pair o2) { return o1.a-o2.a; } } static class Reader { private final InputStream in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private static final long LONG_MAX_TENTHS = 922337203685477580L; private static final int LONG_MAX_LAST_DIGIT = 7; private static final int LONG_MIN_LAST_DIGIT = 8; public Reader(InputStream in) { this.in = in; } public Reader() { this(System.in); } private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { int digit = b - '0'; if (n >= LONG_MAX_TENTHS) { if (n == LONG_MAX_TENTHS) { if (minus) { if (digit <= LONG_MIN_LAST_DIGIT) { n = -n * 10 - digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("not number")); } } } else { if (digit <= LONG_MAX_LAST_DIGIT) { n = n * 10 + digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("not number")); } } } } throw new ArithmeticException( String.format(" overflows long.")); } n = n * 10 + digit; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } public long[] nextLongArray(long length) { long[] array = new long[(int) length]; for (int i = 0; i < length; i++) array[i] = this.nextLong(); return array; } public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map) { long[] array = new long[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsLong(this.nextLong()); return array; } public int[] nextIntArray(int length) { int[] array = new int[length]; for (int i = 0; i < length; i++) array[i] = this.nextInt(); return array; } public int[][] nextIntArrayMulti(int length, int width) { int[][] arrays = new int[width][length]; for (int i = 0; i < length; i++) { for (int j = 0; j < width; j++) arrays[j][i] = this.nextInt(); } return arrays; } public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map) { int[] array = new int[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsInt(this.nextInt()); return array; } public double[] nextDoubleArray(int length) { double[] array = new double[length]; for (int i = 0; i < length; i++) array[i] = this.nextDouble(); return array; } public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map) { double[] array = new double[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsDouble(this.nextDouble()); return array; } public long[][] nextLongMatrix(int height, int width) { long[][] mat = new long[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextLong(); } return mat; } public int[][] nextIntMatrix(int height, int width) { int[][] mat = new int[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextInt(); } return mat; } public double[][] nextDoubleMatrix(int height, int width) { double[][] mat = new double[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextDouble(); } return mat; } public char[][] nextCharMatrix(int height, int width) { char[][] mat = new char[height][width]; for (int h = 0; h < height; h++) { String s = this.next(); for (int w = 0; w < width; w++) { mat[h][w] = s.charAt(w); } } return mat; } } static class FastPrinter extends PrintWriter { public FastPrinter(PrintStream stream) { super(stream); } public FastPrinter() { super(System.out); } private static String dtos(double x, int n) { StringBuilder sb = new StringBuilder(); if (x < 0) { sb.append('-'); x = -x; } x += Math.pow(10, -n) / 2; sb.append((long) x); sb.append("."); x -= (long) x; for (int i = 0; i < n; i++) { x *= 10; sb.append((int) x); x -= (int) x; } return sb.toString(); } @Override public void print(float f) { super.print(dtos(f, 20)); } @Override public void println(float f) { super.println(dtos(f, 20)); } @Override public void print(double d) { super.print(dtos(d, 20)); } @Override public void println(double d) { super.println(dtos(d, 20)); } public void printArray(int[] array, String separator) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(array[i]); super.print(separator); } super.println(array[n - 1]); } public void printArray(int[] array) { this.printArray(array, " "); } public void printArray(int[] array, String separator, java.util.function.IntUnaryOperator map) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(map.applyAsInt(array[i])); super.print(separator); } super.println(map.applyAsInt(array[n - 1])); } public void printArray(int[] array, java.util.function.IntUnaryOperator map) { this.printArray(array, " ", map); } public void printArray(long[] array, String separator) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(array[i]); super.print(separator); } super.println(array[n - 1]); } public void printArray(long[] array) { this.printArray(array, " "); } public void printArray(long[] array, String separator, java.util.function.LongUnaryOperator map) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(map.applyAsLong(array[i])); super.print(separator); } super.println(map.applyAsLong(array[n - 1])); } public void printArray(long[] array, java.util.function.LongUnaryOperator map) { this.printArray(array, " ", map); } public void printMatrix(int[][] arr) { for (int i = 0; i < arr.length; i++) { this.printArray(arr[i]); } } public void printCharMatrix(char[][] arr, int n, int m) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { this.print(arr[i][j] + " "); } this.println(); } } } static Random __r = new Random(); static int randInt(int min, int max) { return __r.nextInt(max - min + 1) + min; } static void reverse(int[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(long[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(double[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { double swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(char[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(char[] arr, int i, int j) { while (i < j) { char temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; i++; j--; } } static void reverse(int[] arr, int i, int j) { while (i < j) { int temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; i++; j--; } } static void reverse(long[] arr, int i, int j) { while (i < j) { long temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; i++; j--; } } static void shuffle(int[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void shuffle(long[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } private static int getlowest(int l) { if (l >= 1000000000) return 1000000000; if (l >= 100000000) return 100000000; if (l >= 10000000) return 10000000; if (l >= 1000000) return 1000000; if (l >= 100000) return 100000; if (l >= 10000) return 10000; if (l >= 1000) return 1000; if (l >= 100) return 100; if (l >= 10) return 10; return 1; } static void shuffle(double[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void rsort(int[] a) { shuffle(a); sort(a); } static void rsort(long[] a) { shuffle(a); sort(a); } static void rsort(double[] a) { shuffle(a); sort(a); } static int[] copy(int[] a) { int[] ans = new int[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static long[] copy(long[] a) { long[] ans = new long[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static double[] copy(double[] a) { double[] ans = new double[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static char[] copy(char[] a) { char[] ans = new char[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
9ef58846ce41d616abca0e0d292b5352
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String args[]) { FastReader input=new FastReader(); PrintWriter out=new PrintWriter(System.out); int T=input.nextInt(); while(T-->0) { int n=input.nextInt(); ArrayList<int []> list1=new ArrayList<>(); ArrayList<int []> list2=new ArrayList<>(); for(int i=0;i<n;i++) { int a=input.nextInt(); list1.add(new int[]{a,i+1}); } for(int i=0;i<n;i++) { int b=input.nextInt(); list2.add(new int[]{b,i+1}); } Collections.sort(list1, new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2) { return o1[0]-o2[0]; } }); Collections.sort(list2, new Comparator<int[]>() { @Override public int compare(int[] o1, int[] o2) { return o1[0]-o2[0]; } }); int a1[]=new int[n+1]; int a2[]=new int[n+1]; for(int i=0;i<n;i++) { a1[list1.get(i)[1]]=i; a2[list2.get(i)[1]]=i; } HashSet<Integer> set=new HashSet<>(); Queue<int []> q=new LinkedList<>(); q.add(new int[]{list1.get(n-1)[1],0}); int x=n-1,y=n; while(!q.isEmpty()) { int a[]=q.poll(); set.add(a[0]); if(a[1]==0) { int v=a[0]; int ind=a2[v]; if(ind<y) { for(int i=ind+1;i<y;i++) { q.add(new int[]{list2.get(i)[1],1}); } y=ind; } } else { int v=a[0]; int ind=a1[v]; if(ind<x) { for(int i=ind+1;i<x;i++) { q.add(new int[]{list1.get(i)[1],0}); } x=ind; } } } StringBuilder sb=new StringBuilder(); for(int i=1;i<=n;i++) { if(set.contains(i))sb.append("1"); else sb.append("0"); } out.println(sb); } out.close(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str=""; try { str=br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
c6bae21dfd59e517cc42daff9b778f16
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.*; import java.util.concurrent.ThreadLocalRandom; public class a729 { public static void main(String[] args) throws IOException { // try { BufferedWriter out = new BufferedWriter( new OutputStreamWriter(System.out)); BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); PrintWriter pt = new PrintWriter(System.out); FastReader sc = new FastReader(); int t = sc.nextInt(); for(int o = 0 ; o<t;o++){ int n = sc.nextInt(); trip[] arr = new trip[n]; int[] arr1 = new int[n]; int[] arr2 = new int[n]; for(int i = 0 ; i<n;i++) { arr1[i] = sc.nextInt(); } for(int i = 0 ; i<n;i++) { arr2[i] = sc.nextInt(); } for(int i = 0 ; i<n;i++) { arr[i] = new trip(arr1[i], arr2[i],i); } Arrays.sort(arr,new Comparator<trip>() { @Override public int compare(trip o1, trip o2) { return o1.b - o2.b; } }); int[] dp = new int[n]; int max = Integer.MIN_VALUE; for(int i = 0 ; i<n;i++) { int v = arr[i].a; max = Math.max(max, v); dp[i] = max; } int tmin = arr[n-1].a; int id = n-1; int cmin = Integer.MAX_VALUE; int[] ans = new int[n]; for(int i = n-2 ; i>=0;i--) { if(arr[i].a>tmin) { tmin = Math.min(tmin, cmin); id = i; } cmin = Math.min(cmin, arr[i].a); } for(int i = id ; i<n;i++) { ans[arr[i].c] = 1; } StringBuilder sb = new StringBuilder(""); for(int i = 0 ; i<n;i++) { sb.append(ans[i]); } System.out.println(sb); } //out.flush(); // }catch(Exception e) { // return; // } } //------------------------------------------------------------------------------------------------------------------------------------------------ static int cntDivisors(int n){ int cnt = 0; for (int i=1; i<=Math.sqrt(n); i++) { if (n%i==0) { if (n/i == i) cnt++; else cnt+=2; } } return cnt; } static long power(long x, long y, long p){ long res = 1; x = x % p; if (x == 0) return 0; while (y > 0){ if ((y & 1) != 0) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } public static long findgcd(long[] arr) { int n = arr.length; long g = 0; int id = 0; g = arr[id]; // System.out.println(g); for(int i = id+1 ; i<n;i++) { if(arr[i] == 0) { continue; } g = gcd(g, arr[i]); // System.out.println(g + " " + arr[i]); } return g; } public static long ncr(long[] fac, int n , int r , long m) { return fac[n]*(modInverse(fac[r], m))%m *(modInverse(fac[n-r], m))%m; } public static void build(int [][] seg,char []arr,int idx, int lo , int hi) { if(lo == hi) { // seg[idx] = arr[lo]; seg[idx][(int)arr[lo]-'a'] = 1; return; } int mid = (lo + hi)/2; build(seg,arr,2*idx+1, lo, mid); build(seg,arr,idx*2+2, mid +1, hi); //seg[idx] = Math.min(seg[2*idx+1],seg[2*idx+2]); for(int i = 0 ; i<27;i++) { seg[idx][i] = seg[2*idx+1][i] + seg[2*idx + 2][i]; } } //for f/inding minimum in range public static void query(int[][]seg,int[]ans,int idx , int lo , int hi , int l , int r) { if(lo>=l && hi<=r) { for(int i = 0 ; i<27;i++) { ans[i]+= seg[idx][i]; } return ; } if(hi<l || lo>r) { return; } int mid = (lo + hi)/2; query(seg,ans,idx*2 +1, lo, mid, l, r); query(seg,ans,idx*2 + 2, mid + 1, hi, l, r); //return Math.min(left, right); } //// for sum // public static void update(int[][]seg,char[]arr,int idx, int lo , int hi , int node , char val) { if(lo == hi) { // seg[idx] += val; seg[idx][val-'a']++; seg[idx][arr[node]-'a']--; }else { int mid = (lo + hi )/2; if(node<=mid && node>=lo) { update(seg,arr, idx * 2 +1, lo, mid, node, val); }else { update(seg,arr, idx*2 + 2, mid + 1, hi, node, val); } //seg[idx] = seg[idx*2 + 1] + seg[idx*2 + 2]; for(int i = 0 ; i<27;i++) { seg[idx][i] = seg[2*idx+1][i] + seg[2*idx + 2][i]; } } } public static int lower_bound(int array[], int low, int high, int key){ // Base Case if (low > high) { return low; } // Find the middle index int mid = low + (high - low) / 2; // If key is lesser than or equal to // array[mid] , then search // in left subarray if (key <= array[mid]) { return lower_bound(array, low, mid - 1, key); } // If key is greater than array[mid], // then find in right subarray return lower_bound(array, mid + 1, high, key); } public static int upper_bound(int arr[], int low, int high, int key){ // Base Case if (low > high || low == arr.length) return low; // Find the value of middle index int mid = low + (high - low) / 2; // If key is greater than or equal // to array[mid], then find in // right subarray if (key >= arr[mid]) { return upper_bound(arr, mid + 1, high, key); } // If key is less than array[mid], // then find in left subarray return upper_bound(arr, low, mid - 1, key); } // ----------------------------------------------------------------------------------------------------------------------------------------------- public static long gcd(long a, long b){ if (a == 0) return b; return gcd(b % a, a); } //-------------------------------------------------------------------------------------------------------------------------------------------------------- public static long modInverse(long a, long m){ long m0 = m; long y = 0, x = 1; if (m == 1) return 0; while (a > 1) { // q is quotient long q = a / m; long t = m; // m is remainder now, process // same as Euclid's algo m = a % m; a = t; t = y; // Update x and y y = x - q * y; x = t; } // Make x positive if (x < 0) x += m0; return x; } //----------------------------------------------------------------------------------------------------------------------------------- //segment tree //for finding minimum in range // public static void build(int [] seg,int []arr,int idx, int lo , int hi) { // if(lo == hi) { // seg[idx] = arr[lo]; // return; // } // int mid = (lo + hi)/2; // build(seg,arr,2*idx+1, lo, mid); // build(seg,arr,idx*2+2, mid +1, hi); // seg[idx] = Math.min(seg[2*idx+1],seg[2*idx+2]); // } ////for finding minimum in range //public static int query(int[]seg,int idx , int lo , int hi , int l , int r) { // if(lo>=l && hi<=r) { // return seg[idx]; // } // if(hi<l || lo>r) { // return Integer.MAX_VALUE; // } // int mid = (lo + hi)/2; // int left = query(seg,idx*2 +1, lo, mid, l, r); // int right = query(seg,idx*2 + 2, mid + 1, hi, l, r); // return Math.min(left, right); //} // // for sum // //public static void update(int[]seg,int idx, int lo , int hi , int node , int val) { // if(lo == hi) { // seg[idx] += val; // }else { //int mid = (lo + hi )/2; //if(node<=mid && node>=lo) { // update(seg, idx * 2 +1, lo, mid, node, val); //}else { // update(seg, idx*2 + 2, mid + 1, hi, node, val); //} //seg[idx] = seg[idx*2 + 1] + seg[idx*2 + 2]; // //} //} //--------------------------------------------------------------------------------------------------------------------------------------- static void shuffleArray(long[] ar) { // If running on Java 6 or older, use `new Random()` on RHS here Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap long a = ar[index]; ar[index] = ar[i]; ar[i] = a; } } //----------------------------------------------------------------------------------------------------------------------------------------------------------- } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } //------------------------------------------------------------------------------------------------------------------------------------------------------------ class SegmentTree{ int n; public SegmentTree(int[] arr,int n) { this.arr = arr; this.n = n; } int[] arr = new int[n]; // int n = arr.length; int[] seg = new int[4*n]; void build(int idx, int lo , int hi) { if(lo == hi) { seg[idx] = arr[lo]; return; } int mid = (lo + hi)/2; build(2*idx+1, lo, mid); build(idx*2+2, mid +1, hi); seg[idx] = Math.min(seg[2*idx+1],seg[2*idx+2]); } int query(int idx , int lo , int hi , int l , int r) { if(lo<=l && hi>=r) { return seg[idx]; } if(hi<l || lo>r) { return Integer.MAX_VALUE; } int mid = (lo + hi)/2; int left = query(idx*2 +1, lo, mid, l, r); int right = query(idx*2 + 2, mid + 1, hi, l, r); return Math.min(left, right); } } //----------------------------------------------------------------------------------------------------------------------------------------------------------- class coup{ int a; int b; public coup(int a , int b) { this.a = a; this.b = b; } } class trip{ int a , b, c; public trip(int a , int b, int c) { this.a = a; this.b = b; this.c = c; } } //---------------------------------------------------------------------------------------------------------------------------------------------------------------
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
5c593032c985394229670ad352083faa
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Arrays; public class ybg{ public static void main(String[]args) { FastScanner c = new FastScanner(); int a = c.nextInt(); for(int aa=0;aa<a;aa++){ int b = c.nextInt(); p []z = new p[b]; p []x = new p[b]; int g =b-1; int h =b-1; int [] gg =new int[b]; int [] hh = new int [b]; for(int q =0;q<b;q++) gg[q]=c.nextInt(); for(int q =0;q<b;q++) hh[q] = c.nextInt(); for(int q =0;q<b;q++) z[q] = new p(gg[q],q,hh[q]); for(int q =0;q<b;q++) x[q] = new p(hh[q],q,gg[q]); int []v = new int[b]; Arrays.sort(z); Arrays.sort(x); int l1=x[g].l; int l2 =z[g].l; boolean u = true; while(u){ u = false; while(g>=0&&z[g].j>=l1){ v[z[g].k]=1; if(z[g].l<l2){ l2=z[g].l; } g--; } while(h>=0&&x[h].j>=l2){ v[x[h].k]=1; if(x[h].l<l1){ l1= x[h].l; u = true; } h--; } } for(int q=0;q<b;q++) System.out.print(v[q]); System.out.println(); } System.out.close(); } static class p implements Comparable<p>{ int j,k,l; p(int j, int k,int l){ this.j = j; this.k =k; this.l=l; } public int compareTo(p o) { return Integer.compare(j, o.j); } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(br.readLine()); } catch (Exception e){e.printStackTrace();} } public String next() { if (st.hasMoreTokens()) return st.nextToken(); try {st = new StringTokenizer(br.readLine());} catch (Exception e) {e.printStackTrace();} return st.nextToken(); } public int nextInt() {return Integer.parseInt(next());} public long nextLong() {return Long.parseLong(next());} public double nextDouble() {return Double.parseDouble(next());} public String nextLine() { String line = ""; if(st.hasMoreTokens()) line = st.nextToken(); else try {return br.readLine();}catch(IOException e){e.printStackTrace();} while(st.hasMoreTokens()) line += " "+st.nextToken(); return line; } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
7b8b9decf2d5d7a55fc5abd43001f042
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; import static java.lang.Math.PI; import static java.lang.System.in; import static java.lang.System.out; import static java.lang.System.err; public class C { static ArrayList<ArrayList<Integer>> adj; static void dfs(int s, boolean vis[]) { vis[s] = true; for(int i : adj.get(s)) { if(!vis[i]) { dfs(i, vis); } } } public static void main(String[] args) throws Exception { Foster sc = new Foster(); PrintWriter p = new PrintWriter(out); /* * Is that extra condition needed * Check overflow in pow function or in general * Check indices of read array functions * Think of an easier solution because the problems you solve are always easy * Check the iterator of loop */ int t = sc.nextInt(); while(t--!=0) { int n = sc.nextInt(); int a[] = sc.intArray(n); int b[] = sc.intArray(n); adj = new ArrayList<>(); for(int i = 0; i < n; i++) { adj.add(new ArrayList<>()); } int largeA = 0, largeB = 0; int idxA = -1, idxB = -1; HashMap<Integer, Integer> mapA = new HashMap<>(); HashMap<Integer, Integer> mapB = new HashMap<>(); for(int i = 0; i < n; i++) { mapA.put(a[i], i); mapB.put(b[i], i); if(largeA < a[i]) { largeA = Math.max(largeA, a[i]); idxA = i; } if(largeB < b[i]) { largeB = Math.max(largeB, b[i]); idxB = i; } } a = sort(a); b = sort(b); for(int i = 1; i < n; i++) { int u = mapA.get(a[i]); int v = mapA.get(a[i-1]); adj.get(v).add(u); u = mapB.get(b[i]); v = mapB.get(b[i-1]); adj.get(v).add(u); } boolean vis2[] = new boolean[n]; boolean vis1[] = new boolean[n]; dfs(idxA, vis1); dfs(idxB, vis2); for(int i = 0; i < n; i++) { if(vis1[i] || vis2[i]) { p.print("1"); } else { p.print("0"); } } p.println(); } p.close(); } static long[] sort(long a[]) { ArrayList<Long> arr = new ArrayList<>(); for(long i : a) { arr.add(i); } Collections.sort(arr); for(int i = 0; i < arr.size(); i++) { a[i] = arr.get(i); } return a; } static int[] sort(int a[]) { ArrayList<Integer> arr = new ArrayList<>(); for(int i : a){ arr.add(i); } Collections.sort(arr); // Collections.reverse(arr); for(int i = 0; i < arr.size(); i++){ a[i] = arr.get(i); } return a; } static class Foster { BufferedReader br = new BufferedReader(new InputStreamReader(in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] intArray(int n) { int arr[] = new int[n]; for(int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } long[] longArray(int n) { long arr[] = new long[n]; for(int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } static long pow(long... a) { long mod = Long.MAX_VALUE; if(a.length == 3) mod = a[2]; long res = 1; while(a[1] > 0) { if((a[1] & 1) == 1) res = (res * a[0]) % mod; a[1] /= 2; a[0] = (a[0] * a[0]) % mod; } return res; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
68b4081fdb1950926c640b9d7815c103
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class solution { public static void main(String[] args) { FScanner sc = new FScanner(); //Arrays.fill(prime, true); //sieve(); int t=sc.nextInt(); StringBuilder sb = new StringBuilder(); while(t-->0) { int n=sc.nextInt(); ArrayList<pair> a=new ArrayList<>(); ArrayList<pair> b=new ArrayList<>(); for(int i=0;i<n;i++) { a.add(new pair(sc.nextInt(),i)); } for(int i=0;i<n;i++) { b.add(new pair(sc.nextInt(),i)); } Collections.sort(a,new Comparator<pair>() { public int compare(pair p1,pair p2) { return p1.val-p2.val; } }); Collections.sort(b,new Comparator<pair>() { public int compare(pair p1,pair p2) { return p1.val-p2.val; } }); HashSet<Integer> hs=new HashSet<>(); hs.add(a.get(n-1).ind);hs.add(b.get(n-1).ind); for(int i=n-2;i>=0;i--) { if(hs.size()>=n-i) {hs.add(b.get(i).ind); hs.add(a.get(i).ind);} else break; } char c[]=new char[n]; for(int i=0;i<n;i++) { if(hs.contains(i)) c[i]='1'; else c[i]='0'; } sb.append(String.valueOf(c)+"\n"); } System.out.println(sb.toString()); } /* public static void sieve() { prime[0]=prime[1]=false; int n=1000000; for(int p = 2; p*p <=n; p++) { if(prime[p] == true) { for(int i = p*p; i <= n; i += p) prime[i] = false; } } */ } class pair { int val;int ind; pair(int val,int ind) { this.val=val; this.ind=ind; } } class FScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer sb = new StringTokenizer(""); String next(){ while(!sb.hasMoreTokens()){ try{ sb = new StringTokenizer(br.readLine()); } catch(IOException e){ } } return sb.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return ""; } int nextInt(){ return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } float nextFloat(){ return Float.parseFloat(next()); } double nextDouble(){ return Double.parseDouble(next()); } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
7903d2d7f18444014c838176936c2824
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; public class GameMaster { static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int T = scanner.nextInt(); while (T -- > 0) { int n = scanner.nextInt(); Pair[] ps1 = new Pair[n]; Pair[] ps2 = new Pair[n]; for (int i = 0; i < n; ++i) { ps1[i] = new Pair(); ps2[i] = new Pair(); ps1[i].idx = i; ps2[i].idx = i; ps1[i].a = scanner.nextInt(); ps2[i].b = ps1[i].a; } for (int i = 0; i < n; ++i) { ps1[i].b = scanner.nextInt(); ps2[i].a = ps1[i].b; } Set<Integer> can1 = solve(ps1); Set<Integer> can2 = solve(ps2); StringBuilder res = new StringBuilder(); for (int i = 0; i < n; ++i) { res.append(can1.contains(i) || can2.contains(i)? 1:0); } System.out.println(res.toString()); } } static Set<Integer> solve(Pair[] ps) { int n = ps.length; Arrays.sort(ps, Comparator.comparingInt(a -> a.a)); int[] rightmin = new int[ps.length]; int[] leftmax = new int[ps.length]; int min = ps[n - 1].b; for (int i = n - 2; i >= 0; --i) { rightmin[i] = min; min = Math.min(ps[i].b, min); } int max = 0; for (int i = 0; i < n; ++i) { max = Math.max(max, ps[i].b); leftmax[i] = max; } Set<Integer> can = new HashSet<>(); for (int i = n - 1; i >= 0; --i) { if (leftmax[i] > rightmin[i]) { can.add(ps[i].idx); } else { break; } } return can; } static class Pair { int a; int b; int idx; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
5a3ff6d196b51c0d9aca87a111ca7c08
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; // import java.lang.*; // import java.math.*; public class Main { static FastReader sc=new FastReader(); static PrintWriter out=new PrintWriter(System.out); static long mod=1000000007; // static long mod=998244353; static int MAX=Integer.MAX_VALUE; static int MIN=Integer.MIN_VALUE; static long MAXL=Long.MAX_VALUE; static long MINL=Long.MIN_VALUE; static ArrayList<Integer> graph[]; static long fact[]; static StringBuffer sb; static int seg[]; static int lazy[];//lazy propagation is used in case of range updates. static long dp[][]; public static void main (String[] args) throws java.lang.Exception { // code goes here int t=I(); outer:while(t-->0) { int n=I(); int a[]=new int[n]; int b[]=new int[n]; HashMap<Integer,Integer> hm=new HashMap<>(); PriorityQueue<Integer> sorter=new PriorityQueue<>(); for(int i=0;i<n;i++){ a[i]=I(); } for(int i=0;i<n;i++){ b[i]=I(); hm.put(b[i],0); sorter.add(b[i]); } int z=1; while(!sorter.isEmpty()){ hm.put(sorter.poll(),z++); } PriorityQueue<pair> pq=new PriorityQueue<>(new myComp()); for(int i=0;i<n;i++){ pair p=new pair(a[i],hm.get(b[i]),i); pq.add(p); } int temp[][]=new int[n][3]; int max[]=new int[n]; for(int i=0;i<n;i++){ pair p=pq.poll(); temp[i][0]=p.a; temp[i][1]=p.b; temp[i][2]=p.c; max[i]=p.b; if(i>0)max[i]=max(max[i-1],max[i]); } FenwickTree ft=new FenwickTree(n); int ans[]=new int[n]; ans[temp[n-1][2]]=1; ft.update(temp[n-1][1],1); for(int i=n-2;i>=0;i--){ if(ft.get(max[i])>0){ ans[temp[i][2]]=1; ft.update(temp[i][1],1); } } for(int i:ans){ out.print(i); }out.println(); } out.close(); } public static class pair { int a; int b; int c; public pair(int aa,int bb,int cc) { a=aa; b=bb; c=cc; } } public static class myComp implements Comparator<pair> { //sort in ascending order. public int compare(pair p1,pair p2) { if(p1.a==p2.a) return 0; else if(p1.a<p2.a) return -1; else return 1; } // sort in descending order. // public int compare(pair p1,pair p2) // { // if(p1.a==p2.a) // return 0; // else if(p1.a<p2.a) // return 1; // else // return -1; // } } public static void DFS(int s,boolean visited[],int dis) { visited[s]=true; for(int i:graph[s]){ if(!visited[i]){ DFS(i,visited,dis+1); } } } public static void setGraph(int n,int m)throws IOException { graph=new ArrayList[n+1]; for(int i=0;i<=n;i++){ graph[i]=new ArrayList<>(); } for(int i=0;i<m;i++){ int u=I(),v=I(); graph[u].add(v); graph[v].add(u); } } //LOWER_BOUND and UPPER_BOUND functions //It returns answer according to zero based indexing. public static int lower_bound(int arr[],int X,int start, int end) //start=0,end=n-1 { if(start>end)return -1; if(arr[arr.length-1]<X)return end; if(arr[0]>X)return -1; int left=start,right=end; while(left<right){ int mid=(left+right)/2; // if(arr[mid]==X){ //Returns last index of lower bound value. // if(mid<end && arr[mid+1]==X){ // left=mid+1; // }else{ // return mid; // } // } if(arr[mid]==X){ //Returns first index of lower bound value. if(mid>start && arr[mid-1]==X){ right=mid-1; }else{ return mid; } } else if(arr[mid]>X){ if(mid>start && arr[mid-1]<X){ return mid-1; }else{ right=mid-1; } }else{ if(mid<end && arr[mid+1]>X){ return mid; }else{ left=mid+1; } } } return left; } //It returns answer according to zero based indexing. public static int upper_bound(ArrayList<Integer> arr,int X,int start,int end) //start=0,end=n-1 { if(arr.get(0)>=X)return start; if(arr.get(arr.size()-1)<X)return -1; int left=start,right=end; while(left<right){ int mid=(left+right)/2; if(arr.get(mid)==X){ //returns first index of upper bound value. if(mid>start && arr.get(mid-1)==X){ right=mid-1; }else{ return mid; } } // if(arr[mid]==X){ //returns last index of upper bound value. // if(mid<end && arr[mid+1]==X){ // left=mid+1; // }else{ // return mid; // } // } else if(arr.get(mid)>X){ if(mid>start && arr.get(mid-1)<X){ return mid; }else{ right=mid-1; } }else{ if(mid<end && arr.get(mid+1)>X){ return mid+1; }else{ left=mid+1; } } } return left; } //END //Segment Tree Code public static void buildTree(int si,int ss,int se) { if(ss==se){ seg[si]=0; return; } int mid=(ss+se)/2; buildTree(2*si+1,ss,mid); buildTree(2*si+2,mid+1,se); seg[si]=(int)add(seg[2*si+1],seg[2*si+2]); } public static void merge(ArrayList<Integer> f,ArrayList<Integer> a,ArrayList<Integer> b) { int i=0,j=0; while(i<a.size() && j<b.size()){ if(a.get(i)<=b.get(j)){ f.add(a.get(i)); i++; }else{ f.add(b.get(j)); j++; } } while(i<a.size()){ f.add(a.get(i)); i++; } while(j<b.size()){ f.add(b.get(j)); j++; } } public static void update(int si,int ss,int se,int pos,int val) { if(ss==se){ seg[si]=(int)add(seg[si],val); return; } int mid=(ss+se)/2; if(pos<=mid){ update(2*si+1,ss,mid,pos,val); }else{ update(2*si+2,mid+1,se,pos,val); } seg[si]=(int)add(seg[2*si+1],seg[2*si+2]); } public static int query(int si,int ss,int se,int qs,int qe) { if(qs>se || qe<ss)return 0; if(ss>=qs && se<=qe)return seg[si]; int mid=(ss+se)/2; return (int)add(query(2*si+1,ss,mid,qs,qe),query(2*si+2,mid+1,se,qs,qe)); } //Segment Tree Code end //Prefix Function of KMP Algorithm public static int[] KMP(char c[],int n) { int pi[]=new int[n]; for(int i=1;i<n;i++){ int j=pi[i-1]; while(j>0 && c[i]!=c[j]){ j=pi[j-1]; } if(c[i]==c[j])j++; pi[i]=j; } return pi; } public static long nPr(int n,int r) { long ans=divide(fact(n),fact(n-r),mod); return ans; } public static long nCr(int n,int r) { long ans=divide(fact[n],mul(fact[n-r],fact[r]),mod); return ans; } public static long kadane(long a[],int n) //largest sum subarray { long max_sum=Long.MIN_VALUE,max_end=0; for(int i=0;i<n;i++){ max_end+=a[i]; if(max_sum<max_end){max_sum=max_end;} if(max_end<0){max_end=0;} } return max_sum; } public static boolean isSorted(int a[]) { int n=a.length; for(int i=0;i<n-1;i++){ if(a[i]>a[i+1])return false; } return true; } public static boolean isSorted(long a[]) { int n=a.length; for(int i=0;i<n-1;i++){ if(a[i]>a[i+1])return false; } return true; } public static int computeXOR(int n) //compute XOR of all numbers between 1 to n. { if (n % 4 == 0) return n; if (n % 4 == 1) return 1; if (n % 4 == 2) return n + 1; return 0; } public static int np2(int x) { x--; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; x++; return x; } public static int hp2(int x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } public static long hp2(long x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } public static ArrayList<Integer> primeSieve(int n) { ArrayList<Integer> arr=new ArrayList<>(); boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int i = 2; i <= n; i++) { if (prime[i] == true) arr.add(i); } return arr; } // Fenwick / BinaryIndexed Tree USE IT - FenwickTree ft1=new FenwickTree(n); public static class FenwickTree { int farr[]; int n; public FenwickTree(int c) { n=c+1; farr=new int[n]; } // public void update_range(int l,int r,long p) // { // update(l,p); // update(r+1,(-1)*p); // } public void update(int x,int p) { for(;x<n;x+=x&(-x)) { farr[x]+=p; } } public long get(int x) { long ans=0; for(;x>0;x-=x&(-x)) { ans=ans+farr[x]; } return ans; } } //Disjoint Set Union public static class DSU { int par[],rank[]; public DSU(int c) { par=new int[c+1]; rank=new int[c+1]; for(int i=0;i<=c;i++) { par[i]=i; rank[i]=0; } } public int find(int a) { if(a==par[a]) return a; return par[a]=find(par[a]); } public void union(int a,int b) { int a_rep=find(a),b_rep=find(b); if(a_rep==b_rep) return; if(rank[a_rep]<rank[b_rep]) par[a_rep]=b_rep; else if(rank[a_rep]>rank[b_rep]) par[b_rep]=a_rep; else { par[b_rep]=a_rep; rank[a_rep]++; } } } public static HashSet<Long> primeFact(long a) { HashSet<Long> arr=new HashSet<>(); // HashMap<Long,Integer> hm=new HashMap<>(); while(a%2==0){ arr.add(2L); // hm.put(2L,hm.getOrDefault(2L,0)+1); a=a/2; } for(long i=3;i*i<=a;i+=2){ while(a%i==0){ arr.add(i); // hm.put(i,hm.getOrDefault(i,0)+1); a=a/i; } } if(a>2){ arr.add(a); // hm.put(a,hm.getOrDefault(a,0)+1); } return arr; // return hm; } public static boolean isInteger(double N) { int X = (int)N; double temp2 = N - X; if (temp2 > 0) { return false; } return true; } public static boolean isPalindrome(String s,int n) { for(int i=0;i<=n/2;i++){ if(s.charAt(i)!=s.charAt(n-i-1)){ return false; } } return true; } public static int gcd(int a,int b) { if(b==0) return a; else return gcd(b,a%b); } public static long gcd(long a,long b) { if(b==0) return a; else return gcd(b,a%b); } public static long lcm(long a,long b){return (a*b)/gcd(a,b);} public static long fact(long n) { long fact=1; for(long i=2;i<=n;i++){ fact=((fact%mod)*(i%mod))%mod; } return fact; } public static long fact(int n) { long fact=1; for(int i=2;i<=n;i++){ fact=((fact%mod)*(i%mod))%mod; } return fact; } public static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static boolean isPrime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static void printArray(long a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]+" "); } out.println(); } public static void printArray(int a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]+" "); } out.println(); } public static void printArray(char a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]); } out.println(); } public static void printArray(String a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]+" "); } out.println(); } public static void printArray(boolean a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]+" "); } out.println(); } public static void printArray(pair a[]) { for(pair p:a){ out.println(p.a+"->"+p.b); } } public static void printArray(int a[][]) { for(int i=0;i<a.length;i++){ for(int j=0;j<a[i].length;j++){ out.print(a[i][j]+" "); }out.println(); } } public static void printArray(long a[][]) { for(int i=0;i<a.length;i++){ for(int j=0;j<a[i].length;j++){ out.print(a[i][j]+" "); }out.println(); } } public static void printArray(char a[][]) { for(int i=0;i<a.length;i++){ for(int j=0;j<a[i].length;j++){ out.print(a[i][j]+" "); }out.println(); } } public static void printArray(ArrayList<?> arr) { for(int i=0;i<arr.size();i++){ out.print(arr.get(i)+" "); } out.println(); } public static void printMapInt(HashMap<?,?> hm){ for(Map.Entry<?,?> e:hm.entrySet()){ out.println(e.getKey()+"->"+e.getValue()); }out.println(); } //Modular Arithmetic public static long add(long a,long b) { a+=b; if(a>=mod)a-=mod; return a; } public static long sub(long a,long b) { a-=b; if(a<0)a+=mod; return a; } public static long mul(long a,long b) { return ((a%mod)*(b%mod))%mod; } public static long divide(long a,long b,long m) { a=mul(a,modInverse(b,m)); return a; } public static long modInverse(long a,long m) { int x=0,y=0; own p=new own(x,y); long g=gcdExt(a,m,p); if(g!=1){ out.println("inverse does not exists"); return -1; }else{ long res=((p.a%m)+m)%m; return res; } } public static long gcdExt(long a,long b,own p) { if(b==0){ p.a=1; p.b=0; return a; } int x1=0,y1=0; own p1=new own(x1,y1); long gcd=gcdExt(b,a%b,p1); p.b=p1.a - (a/b) * p1.b; p.a=p1.b; return gcd; } public static long pwr(long m,long n) { long res=1; if(m==0) return 0; while(n>0) { if((n&1)!=0) { res=(res*m); } n=n>>1; m=(m*m); } return res; } public static long modpwr(long m,long n) { long res=1; m=m%mod; if(m==0) return 0; while(n>0) { if((n&1)!=0) { res=(res*m)%mod; } n=n>>1; m=(m*m)%mod; } return res; } public static class own { long a; long b; public own(long val,long index) { a=val; b=index; } } //Modular Airthmetic public static void sort(int[] A) { int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i) { int tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } public static void sort(char[] A) { int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i) { char tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } public static void sort(long[] A) { int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i) { long tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } //max & min public static int max(int a,int b){return Math.max(a,b);} public static int min(int a,int b){return Math.min(a,b);} public static int max(int a,int b,int c){return Math.max(a,Math.max(b,c));} public static int min(int a,int b,int c){return Math.min(a,Math.min(b,c));} public static long max(long a,long b){return Math.max(a,b);} public static long min(long a,long b){return Math.min(a,b);} public static long max(long a,long b,long c){return Math.max(a,Math.max(b,c));} public static long min(long a,long b,long c){return Math.min(a,Math.min(b,c));} //end public static int I(){return sc.I();} public static long L(){return sc.L();} public static String S(){return sc.S();} public static double D(){return sc.D();} } class FastReader { BufferedReader br; StringTokenizer st; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } String next(){ while (st == null || !st.hasMoreElements()){ try { st = new StringTokenizer(br.readLine()); } catch (IOException e){ e.printStackTrace(); } } return st.nextToken(); } int I(){ return Integer.parseInt(next()); } long L(){ return Long.parseLong(next()); } double D(){ return Double.parseDouble(next()); } String S(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
b8c7c62fced34bc48737c7d04a5c450e
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
// Main Code at the Bottom import java.util.*; import java.io.*; import java.sql.Time; public class Main implements Runnable{ //Fast IO class static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { boolean env=System.getProperty("ONLINE_JUDGE") != null; //env=true; if(!env) { try { br=new BufferedReader(new FileReader("src\\input.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } } else br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static long MOD=(long)1e9+7; //debug static void debug(Object... o) { System.out.println(Arrays.deepToString(o)); } static FastReader sc=new FastReader(); static PrintWriter out=new PrintWriter(System.out); //Global variables and functions //Main function(The main code starts from here) public void run() { int test=1; test=sc.nextInt(); while(test-->0) { int n = sc.nextInt(); int a[][] = new int[n][3]; int max = 0; for(int i = 0; i < n; i++) { a[i][0] = sc.nextInt(); a[i][2] = i; if(a[i][0] > a[max][0]) max = i; } for(int i = 0; i < n; i++) { a[i][1] = sc.nextInt(); } int ans[] = new int[n]; int x[][] = Arrays.copyOf(a, n); int y[][] = Arrays.copyOf(a, n); Arrays.sort(x, (x1, x2) -> Integer.compare(x1[0], x2[0])); Arrays.sort(y, (y1, y2) -> Integer.compare(y1[1], y2[1])); HashMap<Integer, Integer> m1 = new HashMap<>(), m2 = new HashMap<>(); for(int i = 0; i < n; i++) { m1.put(x[i][0], i); m2.put(y[i][1], i); } Queue<Integer> q = new LinkedList<>(); int f = 1; q.add(m2.get(a[max][1])); ans[a[max][2]] = 1; x[m1.get(a[max][0])][2] = -1; y[m2.get(a[max][1])][2] = -1; while(!q.isEmpty()) { // debug(q); int len = q.size(); for(int i = 0; i < len; i++) { int j = q.poll() + 1; if(f == 1) { while(j < n && y[j][2] != -1) { int v[] = y[j]; ans[v[2]] = 1; q.add(m1.get(v[0])); x[m1.get(v[0])][2] = -1; y[j][2] = -1; j++; } } else { while(j < n && x[j][2] != -1) { int v[] = x[j]; ans[v[2]] = 1; q.add(m2.get(v[1])); y[m2.get(v[1])][2] = -1; x[j][2] = -1; j++; } } } f ^= 1; } for(int v: ans) out.print(v); out.println(); } out.flush(); out.close(); } public static void main (String[] args) throws java.lang.Exception { new Thread(null, new Main(), "anything", (1<<28)).start(); } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
31d038e4c6efa878752b47dc228dab41
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); int t; t = in.nextInt(); //t = 1; while (t > 0) { solver.call(in,out); t--; } out.close(); } static class TaskA { public void call(InputReader in, PrintWriter out) { int n, c, index, maxA, maxB, val; n = in.nextInt(); int[] arr = new int[n]; answer[] a = new answer[n]; answer[] b = new answer[n]; Map<Integer, Integer> mapA = new HashMap<>(); Map<Integer, Integer> mapB = new HashMap<>(); for (int i = 0; i < n; i++) { a[i] = new answer(in.nextInt(), 0,i); } for (int i = 0; i < n; i++) { c = in.nextInt(); a[i].b = c; b[i] = new answer(c, a[i].a, i); } Arrays.sort(a); Arrays.sort(b); for (int i = 0; i < n; i++) { mapA.put(a[i].a, i); mapB.put(b[i].a, i); } val = a[0].b; index = mapB.get(val); maxB = index; val = b[0].b; index = mapA.get(val); maxA = index; for(int i = 0; i <= Math.max(maxB, maxA); i++){ if(i <= maxA){ arr[a[i].c] = 1; val = a[i].b; index = mapB.get(val); maxB = Math.max(maxB, index); } if(i <= maxB){ arr[b[i].c] = 1; val = b[i].b; index = mapA.get(val); maxA = Math.max(maxA, index); } } StringBuilder s = new StringBuilder(""); for(Integer i: arr){ s.append(i); } out.println(s); } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static class answer implements Comparable<answer>{ int a, b, c; public answer(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } @Override public int compareTo(answer o) { return o.a - this.a; } } static class arrayListClass { ArrayList<Integer> arrayList2 ; public arrayListClass(ArrayList<Integer> arrayList) { this.arrayList2 = arrayList; } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static final Random random=new Random(); static void shuffleSort(int[] a) { int n=a.length; for (int i=0; i<n; i++) { int oi=random.nextInt(n), temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } 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 double nextDouble() { return Double.parseDouble(next()); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
d9c30b20fd5eddf704ea2652d299a753
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); int t; t = in.nextInt(); //t = 1; while (t > 0) { solver.call(in,out); t--; } out.close(); } static class TaskA { public void call(InputReader in, PrintWriter out) { int n; n = in.nextInt(); answer[] a = new answer[n]; answer[] b = new answer[n]; int[] array =new int[n]; int[] array1 =new int[n]; Map<Integer, Integer> mapA = new HashMap<>(); Map<Integer, Integer> mapB = new HashMap<>(); for (int i = 0; i < n; i++) { array[i]= in.nextInt(); } for (int i = 0; i < n; i++) { array1[i]= in.nextInt(); } for (int i = 0; i < n; i++) { a[i] = new answer(array[i], array1[i], i); b[i] = new answer(array1[i], array[i], i); } Arrays.sort(a); Arrays.sort(b); for (int i = 0; i < n; i++) { mapA.put(a[i].a, i); mapB.put(b[i].a, i); } int[] arr = new int[n]; int index, maxA, maxB, val; val = a[0].b; index = mapB.get(val); maxB = index; val = b[0].b; index = mapA.get(val); maxA = index; for(int i = 0; i <= Math.max(maxB, maxA); i++){ if(i <= maxA){ arr[a[i].c] = 1; val = a[i].b; index = mapB.get(val); maxB = Math.max(maxB, index); } if(i <= maxB){ arr[b[i].c] = 1; val = b[i].b; index = mapA.get(val); maxA = Math.max(maxA, index); } } StringBuilder s = new StringBuilder(""); for(Integer i: arr){ s.append(i); } out.println(s); } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static class answer implements Comparable<answer>{ int a, b, c; public answer(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } @Override public int compareTo(answer o) { return o.a - this.a; } } static class arrayListClass { ArrayList<Integer> arrayList2 ; public arrayListClass(ArrayList<Integer> arrayList) { this.arrayList2 = arrayList; } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static final Random random=new Random(); static void shuffleSort(int[] a) { int n=a.length; for (int i=0; i<n; i++) { int oi=random.nextInt(n), temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } 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 double nextDouble() { return Double.parseDouble(next()); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
b29926353fb01802eaa5eadfb612e553
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); int t; t = in.nextInt(); //t = 1; while (t > 0) { solver.call(in,out); t--; } out.close(); } static class TaskA { public void call(InputReader in, PrintWriter out) { int n; n = in.nextInt(); answer[] a = new answer[n]; answer[] b = new answer[n]; int[] array =new int[n]; int[] array1 =new int[n]; Map<Integer, Integer> mapA = new HashMap<>(); Map<Integer, Integer> mapB = new HashMap<>(); Map<Integer, Integer> mapA1 = new HashMap<>(); Map<Integer, Integer> mapB1 = new HashMap<>(); for (int i = 0; i < n; i++) { array[i]= in.nextInt(); } for (int i = 0; i < n; i++) { array1[i]= in.nextInt(); } for (int i = 0; i < n; i++) { a[i] = new answer(array[i], array1[i], i); b[i] = new answer(array1[i], array[i], i); } Arrays.sort(a); Arrays.sort(b); for (int i = 0; i < n; i++) { mapA.put(a[i].a, i); mapB.put(b[i].a, i); } int[] arr = new int[n]; int index, maxA, maxB; int val = a[0].b; index = mapB.get(val); maxB = index; val = b[0].b; index = mapA.get(val); maxA = index; for(int i = 0; i <= Math.max(maxB, maxA); i++){ if(i <= maxA){ arr[a[i].c] = 1; val = a[i].b; index = mapB.get(val); maxB = Math.max(maxB, index); } if(i <= maxB){ arr[b[i].c] = 1; val = b[i].b; index = mapA.get(val); maxA = Math.max(maxA, index); } } for (int i = 0; i <= maxA; i++) { arr[a[i].c] = 1; } for (int i = 0; i <= maxB; i++) { arr[b[i].c] = 1; } StringBuilder s = new StringBuilder(""); for(Integer i: arr){ s.append(i); } out.println(s); } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static class answer implements Comparable<answer>{ int a, b, c; public answer(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } @Override public int compareTo(answer o) { return o.a - this.a; } } static class arrayListClass { ArrayList<Integer> arrayList2 ; public arrayListClass(ArrayList<Integer> arrayList) { this.arrayList2 = arrayList; } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static final Random random=new Random(); static void shuffleSort(int[] a) { int n=a.length; for (int i=0; i<n; i++) { int oi=random.nextInt(n), temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } 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 double nextDouble() { return Double.parseDouble(next()); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
ebfee4429a55ec6ec9742278d4eb2bb3
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class C { public static void main(String[] args) { for (int t = IO.nextInt(), i = 0; i < t; i++) new SolC().solve(); IO.close(); } } class SolC { int n; int[] a, b; Integer[] id; Map<Integer, int[]> graph; boolean[] visited; SolC() { n = IO.nextInt(); a = new int[n]; b = new int[n]; for (int i = 0; i < n; i++) a[i] = IO.nextInt(); for (int i = 0; i < n; i++) b[i] = IO.nextInt(); graph = new HashMap<>(); visited = new boolean[n]; } void solve() { id = new Integer[n]; for (int i = 0; i < n; i++) id[i] = i; Arrays.sort(id, (x, y) -> Integer.compare(a[y], a[x])); int aMaxId = id[0]; for (int i = 0; i < n-1; i++) graph.put(id[i+1], new int[] {id[i], id[i]}); for (int i = 0; i < n; i++) id[i] = i; Arrays.sort(id, (x, y) -> Integer.compare(b[y], b[x])); for (int i = 0; i < n-1; i++) { int[] nxt = graph.getOrDefault(id[i+1], new int[] {id[i], id[i]}); nxt[1] = id[i]; graph.put(id[i+1], nxt); } dfs(id[0]); dfs(aMaxId); for (int i = 0; i < n; i++) { if (visited[i]) IO.writer.print(1); else IO.writer.print(0); } IO.writer.println(); } void dfs(int u) { if (visited[u]) return; visited[u] = true; int[] nxt = graph.getOrDefault(u, new int[] {u, u}); dfs(nxt[0]); dfs(nxt[1]); } } class IO { static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); static final PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); static StringTokenizer tokens; static String readLine() { try { return reader.readLine(); } catch (Exception e) { throw new RuntimeException(e); } } static void initializeTokens() { while (null == tokens || !tokens.hasMoreTokens()) tokens = new StringTokenizer(readLine()); } static String next() { initializeTokens(); return tokens.nextToken(); } static String next(String delim) { initializeTokens(); return tokens.nextToken(delim); } static int nextInt() { return Integer.parseInt(next()); } static long nextLong() { return Long.parseLong(next()); } static void close() { try { reader.close(); writer.close(); } catch (Exception e) { throw new RuntimeException(e); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
b28392ca267eee1e7c72c82b72a8113f
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class GameMaster { public static PrintWriter out; public static void main(String[] args)throws IOException { JS sc=new JS(); out = new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } int b[]=new int[n]; for(int i=0;i<n;i++) { b[i]=sc.nextInt(); } Pair p[]=new Pair[n]; for(int i=0;i<n;i++) { p[i]=new Pair(a[i], b[i], i); } Arrays.sort(p); int min=p[n-1].y; int id=n-1; int cmin=Integer.MAX_VALUE; for(int i=n-2;i>=0;i--) { if(p[i].y>min) { min=Math.min(min, cmin); id=i; } cmin=Math.min(cmin, p[i].y); } int ans[]=new int[n]; for(int i=id;i<n;i++) { ans[p[i].id]=1; } StringBuilder sb=new StringBuilder(); for(int i=0;i<n;i++) { sb.append(ans[i]); } out.println(sb.toString()); } out.close(); } static class Pair implements Comparable<Pair>{ int x, y, id; public Pair(int x, int y, int id) { this.x=x;this.y=y;this.id=id; } public int compareTo(Pair p) { return Integer.compare(x, p.x); } } static class JS { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+nextLong()/num; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
1d67560a6217e813f2478465e0fd28b3
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class GameMaster{ static long mod = 1000000007L; static MyScanner sc = new MyScanner(); static void solve() { int n = sc.nextInt(); PriorityQueue<Pairs> pq1 = new PriorityQueue<>(); PriorityQueue<Pairs> pq2 = new PriorityQueue<>(); int arr1[] = sc.readIntArray(n); int arr2[] = sc.readIntArray(n); for(int i = 0;i<n;i++){ pq1.add(new Pairs(arr1[i],i)); } for(int i = 0;i<n;i++){ pq2.add(new Pairs(arr2[i],i)); } HashSet<Integer> set = new HashSet<>(); set.add(pq1.peek().ind); set.add(pq2.peek().ind); if(set.size()==1){ for(int i = 0;i<n;i++){ if(set.contains(i)){ out.print(1); }else{ out.print(0); } } out.println(); return; } HashSet<Integer> s1 = new HashSet<>(); HashSet<Integer> s2 = new HashSet<>(); s1.add(pq1.remove().ind); s2.add(pq2.remove().ind); for(int i = 1;i<n && s1.size()>0;i++){ int a = pq1.remove().ind; int b = pq2.remove().ind; if(s2.contains(a)){ s2.remove(a); set.add(a); } else s1.add(a); if(s1.contains(b)){ s1.remove(b); set.add(b); } else s2.add(b); } for(int i = 0;i<n;i++){ if(set.contains(i)){ out.print(1); }else{ out.print(0); } } out.println(); } static class Pairs implements Comparable<Pairs>{ int ind; int val; Pairs(int v,int i){ val = v; ind = i; } public int compareTo(Pairs p){ return p.val - this.val; } } static long lcm(long a,long b){ return (a*b)/gcd(a,b); } static long comb(long n,long k,long mod){ return factorial(n,mod) * pow(factorial(k,mod), mod-2) % mod * pow(factorial(n-k,mod), mod-2) % mod; } static long factorial(long n,long mod){ long ret = 1; while(n > 0){ ret = ret * n % mod; n--; } return ret; } static class Pair implements Comparable<Pair>{ long a; long b; Pair(long aa,long bb){ a = aa; b = bb; } public int compareTo(Pair p){ return Long.compare(this.b,p.b); } } static void reverse(int arr[]){ int i = 0;int j = arr.length-1; while(i<j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; j--; } } static long pow(long a, long b) { if (b == 0) return 1; long res = pow(a, b / 2); res = (res * res) % 1_000_000_007; if (b % 2 == 1) { res = (res * a) % 1_000_000_007; } return res; } static int lis(int arr[],int n){ int lis[] = new int[n]; lis[0] = 1; for(int i = 1;i<n;i++){ lis[i] = 1; for(int j = 0;j<i;j++){ if(arr[i]>arr[j]){ lis[i] = Math.max(lis[i],lis[j]+1); } } } int max = Integer.MIN_VALUE; for(int i = 0;i<n;i++){ max = Math.max(lis[i],max); } return max; } static boolean isPali(String str){ int i = 0; int j = str.length()-1; while(i<j){ if(str.charAt(i)!=str.charAt(j)){ return false; } i++; j--; } return true; } static long gcd(long a,long b){ if(b==0) return a; return gcd(b,a%b); } static String reverse(String str){ char arr[] = str.toCharArray(); int i = 0; int j = arr.length-1; while(i<j){ char temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; j--; } String st = new String(arr); return st; } static boolean isprime(int n){ if(n==1) return false; if(n==3 || n==2) return true; if(n%2==0 || n%3==0) return false; for(int i = 5;i*i<=n;i+= 6){ if(n%i== 0 || n%(i+2)==0){ return false; } } return true; } public static void main(String[] args) { out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); // int t= 1; while(t-- >0){ solve(); // solve2(); // solve3(); } // Stop writing your solution here. ------------------------------------- out.close(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int[] readIntArray(int n){ int arr[] = new int[n]; for(int i = 0;i<n;i++){ arr[i] = Integer.parseInt(next()); } return arr; } int[] reverse(int arr[]){ int n= arr.length; int i = 0; int j = n-1; while(i<j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; j--;i++; } return arr; } long[] readLongArray(int n){ long arr[] = new long[n]; for(int i = 0;i<n;i++){ arr[i] = Long.parseLong(next()); } return arr; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } private static void sort(int[] arr) { List<Integer> list = new ArrayList<>(); for (int i=0; i<arr.length; i++){ list.add(arr[i]); } Collections.sort(list); // collections.sort uses nlogn in backend for (int i = 0; i < arr.length; i++){ arr[i] = list.get(i); } } private static void sort(long[] arr) { List<Long> list = new ArrayList<>(); for (int i=0; i<arr.length; i++){ list.add(arr[i]); } Collections.sort(list); // collections.sort uses nlogn in backend for (int i = 0; i < arr.length; i++){ arr[i] = list.get(i); } } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
1120326b32be1f2568487f42ffab9f67
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class Main{ static Scanner sc = new Scanner(new BufferedInputStream(System.in)); static int sc(){return sc.nextInt();} static long scl(){return sc.nextLong();} static double scd(){return sc.nextDouble();}; static String scs(){return sc.next();}; static char scf(){return scs().charAt(0);} static char[] carr(){return sc.next().toCharArray();}; static char[] chars(){ char[] s = carr(); char[] c = new char[s.length+1]; System.arraycopy(s,0,c,1,s.length); return c; } static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); static void println (Object o) {out.println(o);} static void println() {out.println();} static void print(Object o) {out.print(o);} static int[] dx = new int[]{-1,0,1,0},dy = new int[]{0,-1,0,1}; static final int N = (int)2e6+10,M = 2010,INF = 0x3f3f3f3f,P = 131,MOD = (int)1e9+7; static int n; static int[] h = new int[N],e = new int[N],ne = new int[N],w = new int[N]; static int idx; static D[] a = new D[N]; static Queue<D> q = new PriorityQueue<D>((o1,o2)->o2.y-o1.y); static boolean[] st = new boolean[N]; static void add(int a,int b){ e[idx] = b; ne[idx] = h[a]; h[a] = idx++; } static void dfs(int u){ if(st[u]) return; st[u] = true; for(int i = h[u];i!=-1;i = ne[i]){ int k = e[i]; dfs(k); } } public static void main(String[] args) throws Exception{ int t = sc(); while(t-->0){ n = sc(); idx = 0; for(int i = 0;i<n;i++){ h[i] = -1; st[i] = false; } for(int i = 0;i<n;i++) a[i] = new D(sc(),0,i); for(int i = 0;i<n;i++) a[i].y = sc(); Arrays.sort(a,0,n,(o1,o2)->o2.x - o1.x); for(int i = 1;i<n;i++){ add(a[i].p,a[i-1].p); } D d1 = a[0]; Arrays.sort(a,0,n,(o1,o2)->o2.y - o1.y); for(int i = 1;i<n;i++){ add(a[i].p,a[i-1].p); } dfs(a[0].p); dfs(d1.p); for(int i = 0;i<n;i++) print(st[i]?1:0); println(); } out.close(); } static class D{ int x,y,p; D(int x,int y,int p){this.x = x;this.y = y;this.p = p;} } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
ad5e55d832b8ce8512c671fae6313ee5
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.io.*; public class Main{ static Scanner sc = new Scanner(new BufferedInputStream(System.in)); static int sc(){return sc.nextInt();} static long scl(){return sc.nextLong();} static double scd(){return sc.nextDouble();}; static String scs(){return sc.next();}; static char scf(){return scs().charAt(0);} static char[] carr(){return sc.next().toCharArray();}; static char[] chars(){ char[] s = carr(); char[] c = new char[s.length+1]; System.arraycopy(s,0,c,1,s.length); return c; } static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); static void println (Object o) {out.println(o);} static void println() {out.println();} static void print(Object o) {out.print(o);} static int[] dx = new int[]{-1,0,1,0},dy = new int[]{0,-1,0,1}; static final int N = (int)2e6+10,M = 2010,INF = 0x3f3f3f3f,P = 131,MOD = (int)1e9+7; static int n; static int[] h = new int[N],e = new int[N],ne = new int[N],w = new int[N]; static int idx; static D[] a = new D[N]; static D[] b = new D[N]; static boolean[] st = new boolean[N]; static Queue<Integer> q = new LinkedList(); static void add(int a,int b){ e[idx] = b; ne[idx] = h[a]; h[a] = idx++; } public static void main(String[] args) throws Exception{ int t = sc(); while(t-->0){ n = sc(); idx = 0; for(int i = 0;i<n;i++) a[i] = new D(sc(),i); for(int i = 0;i<n;i++) b[i] = new D(sc(),i); for(int i = 0;i<n;i++) h[i] = -1; for(int i = 0;i<n;i++) st[i] = false; Arrays.sort(a,0,n,(o1,o2)->o1.x - o2.x); Arrays.sort(b,0,n,(o1,o2)->o1.x - o2.x); for(int i = 0;i<n-1;i++){ D d1 = a[i],d2 = b[i]; add(d1.y,a[i+1].y); add(d2.y,b[i+1].y); } q.clear(); q.offer(a[n-1].y); q.offer(b[n-1].y); while(q.size()>0){ int u = q.poll(); if(st[u]) continue; st[u] = true; for(int i = h[u];i!=-1;i = ne[i]){ int k = e[i]; q.offer(k); } } for(int i = 0;i<n;i++) { if(st[i]) print(1); else print(0); } println(); } out.close(); } static class D{ int x,y; D(int x,int y){this.x = x;this.y = y;} } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
d3ba235814fe6b7790b860b112231c8a
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.io.*; import java.util.*; public class C1608{ public static void main(String[] args)throws IOException{ BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(f.readLine()); for(int q = 1; q <= t; q++){ int n = Integer.parseInt(f.readLine()); StringTokenizer st1 = new StringTokenizer(f.readLine()); StringTokenizer st2 = new StringTokenizer(f.readLine()); int[] a = new int[n]; int[] b = new int[n]; Integer[] sort = new Integer[n]; for(int k = 0; k < n; k++){ a[k] = Integer.parseInt(st1.nextToken()); b[k] = Integer.parseInt(st2.nextToken()); sort[k] = k; } Arrays.sort(sort, new Comparator<Integer>(){ public int compare(Integer i1, Integer i2){ return a[(int)i1] - a[(int)i2]; } }); int[] answer = new int[n]; int min = b[sort[n-1]]; int curmin = min; int last = n-1; for(int k = n-2; k >= 0; k--){ curmin = Math.min(curmin,b[sort[k]]); if(b[sort[k]] > min){ min = curmin; last = k; } } for(int k = last; k < n; k++){ answer[sort[k]] = 1; } StringJoiner sj = new StringJoiner(""); for(int k = 0; k < n; k++){ sj.add("" + answer[k]); } out.println(sj.toString()); } out.close(); } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output
PASSED
4404fefa7e0b1119846627a53a134c83
train_109.jsonl
1639217100
$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Codechef { static long fans[] = new long[200001]; static long inv[] = new long[200001]; static long mod = 1000000007; static void init() { fans[0] = 1; inv[0] = 1; fans[1] = 1; inv[1] = 1; for (int i = 2; i < 200001; i++) { fans[i] = ((long) i * fans[i - 1]) % mod; inv[i] = power(fans[i], mod - 2); } } static long ncr(int n, int r) { return (((fans[n] * inv[n - r]) % mod) * (inv[r])) % mod; } public static void main(String[] args) throws java.lang.Exception { FastReader in = new FastReader(System.in); StringBuilder sb = new StringBuilder(); int t = 1; t = in.nextInt(); while (t > 0) { --t; int n = in.nextInt(); int arr[][] = new int[n][3]; for(int i = 0;i<n;i++) { arr[i][0] = in.nextInt(); } for(int i = 0;i<n;i++) { arr[i][1] = in.nextInt(); arr[i][2] = i; } Arrays.sort(arr,(a,b)->{ return Integer.compare(a[0], b[0]); }); int ans[] = new int[n]; int max[] = new int[n]; for(int i = 0;i<n;i++) { if(i == 0) max[i] = arr[i][1]; else max[i] = Math.max(max[i-1], arr[i][1]); } ans[arr[n-1][2]] = 1; int cur = arr[n-1][1]; for(int i = n-2;i>=0;i--) { if(max[i]>cur) { ans[arr[i][2]] = 1; cur = Math.min(cur, arr[i][1]); } } for(int i = 0;i<n;i++) sb.append(ans[i]+""); sb.append("\n"); } System.out.print(sb); } static long power(long x, long y) { long res = 1; // Initialize result while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = ((res % mod) * (x % mod)) % mod; // y must be even now y = y >> 1; // y = y/2 x = ((x % mod) * (x % mod)) % mod; // Change x to x^2 } return res; } static long[] generateArray(FastReader in, int n) throws IOException { long arr[] = new long[n]; for (int i = 0; i < n; i++) arr[i] = in.nextLong(); return arr; } static long[][] generatematrix(FastReader in, int n, int m) throws IOException { long arr[][] = new long[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { arr[i][j] = in.nextLong(); } } return arr; } static long gcd(long a, long b) { if (a == 0) return b; else return gcd(b % a, a); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } } class FastReader { byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } String nextLine() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c != 10 && c != 13; c = scan()) { sb.append((char) c); } return sb.toString(); } char nextChar() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; return (char) c; } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } }
Java
["3\n4\n1 2 3 4\n1 2 3 4\n4\n11 12 20 21\n44 22 11 30\n1\n1000000000\n1000000000"]
1 second
["0001\n1111\n1"]
NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.
Java 8
standard input
[ "data structures", "dfs and similar", "dp", "graphs", "greedy", "two pointers" ]
f9cf1a6971a7003078b63195198e5a51
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,700
For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.
standard output