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 | 5579f61dc87860e2455645bbf2693273 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
for(int i=1;i<=m;i++){
int l = sc.nextInt()-1;
int r = sc.nextInt()-1;
int ind = sc.nextInt()-1;
int temparr[] = new int[n];
// System.out.println(l + " l " + r +" R " + ind+ " ind ");
int temp = arr[ind];
temparr = arr.clone();
int less=l;
for(int j=l; j<=r;j++){
if(temparr[j]<arr[ind]) less++;
}
// Arrays.sort(temparr , l , r+1 );
// for(int k=0;k<n;k++){
// System.out.print(temparr[k]+" ");
// }
// int temp1 = temparr[ind];
if(less==ind)
System.out.println("Yes");
else
System.out.println("No");
}
}
} | Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | 71aaea2de1100434b12b4b1f735c7b48 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes |
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.lang.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[] a = new int[10000];
for (int i = 0;i<n;i++){
a[i] = sc.nextInt();
}
for (int i = 0;i<m;i++){
int l = sc.nextInt()-1;
int r = sc.nextInt()-1;
int k = sc.nextInt();
k = a[k-1];
int md = 0;
int k1 = 0;
for (int j = l;j<=r;j++){
if(a[j]==k){k1++;}
else if(k1 == 0){
if(a[j]>k){md++;}
}else{if(a[j]<k){md--;}
}
}
if (md == 0){System.out.println("Yes");}else{System.out.println("No");}
}
}
}
| Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | 26245be88f5733860cfee91c1f945411 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.io.*;
import java.util.*;
public class Problem811B {
public static void main(String args[]) throws IOException {
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
String n_and_m = buf.readLine();
String ar[] = n_and_m.split(" ");
int n = Integer.parseInt(ar[0]);
int m = Integer.parseInt(ar[1]);
int i,j;
ArrayList<Integer> original_page_numbers = new ArrayList<Integer>();
ar = buf.readLine().split(" ");
for(i = 0; i < n; i++) {
original_page_numbers.add(Integer.parseInt(ar[i]));
//System.out.println(ar[i]);
}
for(i = 0; i < m; i++) {
ar = buf.readLine().split(" ");
int sort_start_index = Integer.parseInt(ar[0])-1;
int sort_end_index = Integer.parseInt(ar[1])-1;
int fav_page_index = Integer.parseInt(ar[2])-1;
ArrayList<Integer> new_page_numbers = new ArrayList<Integer>(original_page_numbers.subList(sort_start_index, sort_end_index+1));
int larger_elements_on_lower_index = 0;
int smaller_elements_on_higher_index = 0;
int fav_page_number = new_page_numbers.get(fav_page_index-sort_start_index);
for(j = 0; j < fav_page_index-sort_start_index; j++)
if(new_page_numbers.get(j) > fav_page_number)
larger_elements_on_lower_index++;
for(j = fav_page_index-sort_start_index+1; j < new_page_numbers.size(); j++)
if(new_page_numbers.get(j) < fav_page_number)
smaller_elements_on_higher_index++;
//System.out.println(fav_page_index + ":" + sort_start_index);
if(smaller_elements_on_higher_index == larger_elements_on_lower_index)
System.out.println("Yes");
else
System.out.println("No");
}
}
} | Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | 12a5e699655d2588875d6474f82c79a5 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | //package codeforces;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* Created by Abhilash on 27-05-2017.
*/
public class VladikAndComplicatedBook {
public static void main (String[] args) throws Exception {
BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
String[] vals = br.readLine().split( " " );
int n = Integer.parseInt( vals[0] );
int s = Integer.parseInt( vals[1] );
vals = br.readLine().split( " " );
int[] p = new int[n];
for ( int i = 0; i < n; i++ )
p[i] = Integer.parseInt( vals[i] );
for ( int i = 0; i < s; i++ ) {
vals = br.readLine().split( " " );
int start = Integer.parseInt( vals[0] );
int end = Integer.parseInt( vals[1] );
int index = Integer.parseInt( vals[2] );
System.out.println( check( p, start - 1, end - 1, index - 1 ) ? "Yes" : "No" );
}
}
public static boolean check (int[] p, int start, int end, int index) {
int left = 0;
for ( int i = start; i < index; i++ )
if ( p[i] > p[index] )
left++;
int right = 0;
for ( int i = index + 1; i <= end; i++ )
if ( p[i] < p[index] )
right++;
return left == right;
}
}
| Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | 5d5601209e5076bfc709347ead79399e | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
static int INF = (int) 1e9;
static Integer[] indices;
static int n;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner();
PrintWriter out = new PrintWriter(System.out);
n = sc.nextInt();
int q = sc.nextInt();
indices = new Integer[n];
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
indices[i] = i;
}
Arrays.sort(indices, Comparator.comparingInt(i -> a[i]));
/*
* the previous line sorts the elements of the array in ascending order according to the
* values of the array "a" so index i comes before index j if a[i] < a[j]
* another way to write this is Arrays.sort(indices,(i,j)->a[i]-a[j]);
*/
SegmentTree tree = new SegmentTree(); // the segment tree is built on the indices array
while (q-- > 0)
{
int l=sc.nextInt()-1,r=sc.nextInt()-1,x=sc.nextInt()-1;
int y=tree.query(l, r, x-l+1);
out.println(x==y?"Yes":"No");
}
out.close();
}
static class SegmentTree {
int[][] tree;
SegmentTree() {
tree = new int[4 * n][];
build(1, 0, n - 1);
}
void build(int node, int tl, int tr) {
if (tl == tr) {
tree[node] = new int[] { indices[tl], INF };
} else {
int mid = tl + tr >> 1, left = node << 1, right = left + 1;
build(left, tl, mid);
build(right, mid + 1, tr);
int size = tree[left].length + tree[right].length - 1;
tree[node] = new int[size];
// merging the sorted arrays of leftChild and rightChild into a sorted array
for (int k = 0, i = 0, j = 0; k < size; k++)
if (tree[left][i] < tree[right][j])
tree[node][k] = tree[left][i++];
else
tree[node][k] = tree[right][j++];
}
}
int query(int l, int r, int k) {
return query(1, l, r, k);
}
int query(int node, int l, int r, int k) {
if (tree[node].length == 2) // leaf
return tree[node][0];
int left = node << 1, right = left + 1;
int x = getCnt(left, l, r);
// if x is >=k then go left, otherwise go right
return x >= k ? query(left, l, r, k) : query(right, l, r, k - x);
}
int getCnt(int node, int l, int r) {
// returns the number of indices in node "node" that has value >=l && <=r
int lo = 0, hi = tree[node].length - 1;
int lower = -1;
int higher = -1;
while (lo <= hi) {
int mid = lo + hi >> 1;
if (tree[node][mid] >= l) {
lower = mid;
hi = mid - 1;
} else
lo = mid + 1;
}
lo = 0;
hi = tree[node].length - 1;
while (lo <= hi) {
int mid = lo + hi >> 1;
if (tree[node][mid] <= r) {
higher = mid;
lo = mid + 1;
} else
hi = mid - 1;
}
return tree[node][lower] > r ? 0 : higher - lower + 1;
}
}
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());
}
}
}
| Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | ab8f870626ca006221eb694714ffcbfe | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.io.*;
import java.util.*;
public class A{
public static void main(String[] args) throws IOException {
Scanner sc=new Scanner();
PrintWriter out=new PrintWriter(System.out);
int n=sc.nextInt(),m=sc.nextInt();
int []p=new int [n];
for(int i=0;i<n;i++)
p[i]=sc.nextInt();
while(m-->0) {
int l=sc.nextInt()-1,r=sc.nextInt()-1,x=sc.nextInt()-1;
int less=0;
for(int i=l;i<=r;i++)
if(p[i]<p[x])
less++;
out.println(l+less==x?"Yes":"No");
}
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());
}
}
} | Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | b4a4d4d2599bbf064cc0b72636c615c0 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.util.*;
public class Main {
static Scanner in = new Scanner(System.in);
static int n = in.nextInt(); // Π΄Π»ΠΈΠ½Π°
static int m = in.nextInt(); // ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΠΏΠ΅ΡΠ΅ΡΡΠ°Π½ΠΎΠ²ΠΎΠΊ
static int[] P = new int[n]; // ΠΏΠΎΡΡΠ΄ΠΎΠΊ ΡΡΡΠ°Π½ΠΈΡ
public static void main(String[] args) {
// long startTime = System.currentTimeMillis();
for (int i = 0; i < n; i++) {
P[i] = in.nextInt();
}
for (int k = 0; k < m; k++) {
int l = in.nextInt();
int r = in.nextInt();
int x = in.nextInt();
int num = l - 1;
for (int i = l - 1; i < r; i++) {
if (P[i] < P[x - 1]) {
num++;
}
}
if (P[num] == P[x - 1]) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}// System.out.println(timeSpent + " ms");
// }
}
}
| Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | 8816d2e96515aaba8723352931820047 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.util.Scanner;
public class B {
private static Scanner in;
private static int N, M;
private static int[] sequence;
private static void solve() {
N = in.nextInt();
M = in.nextInt();
sequence = new int[N];
for (int i = 0; i < N; i++)
sequence[i] = in.nextInt();
for (int i = 0; i < M; i++) {
int l = in.nextInt();
int r = in.nextInt();
int x = in.nextInt();
int lessThan = 0;
for(int j = l; j <=r; j++)
if(sequence[j-1]<sequence[x-1])
lessThan++;
if (lessThan == x - l)
System.out.println("Yes");
else
System.out.println("No");
}
}
public static void main(String[] args) {
in = new Scanner(System.in);
solve();
System.exit(0);
}
}
| Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | a4a610d33eceb313ed24c2dda67bb7b7 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[] orig = new int[n];
for (int i=0; i<n; i++)
orig[i] = sc.nextInt();
for (int i=0; i<m; i++) {
int l = sc.nextInt();
int r = sc.nextInt();
int x = sc.nextInt();
int posElemOrd = posElemOrd(l,r,orig,x);
if (orig[x-1] == orig[posElemOrd])
System.out.println("Yes");
else
System.out.println("No");
}
sc.close();
}
public static int posElemOrd (int l, int r, int[]orig, int x) {
int eleIni = l-1;
int elePro = x-1;
int qtdMenor = 0;
for(int i=eleIni; i<r; i++) {
if (orig[i]<orig[elePro])
qtdMenor++;
}
return (qtdMenor + eleIni);
}
} | Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | a3abaa46acc32f30cf7dfa5ad8af9726 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.TreeSet;
public final class CF_416_B{
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 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) {}}
static int MX=Integer.MAX_VALUE;
// Global vars
static BufferedWriter out;
static InputReader reader;
static void process() throws Exception {
out = new BufferedWriter(new OutputStreamWriter(System.out));
reader=new InputReader(System.in);
int n=reader.readInt();
int m=reader.readInt();
int[] p=new int[n];
for (int i=0;i<n;i++)
p[i]=reader.readInt()-1;
for (int i=0;i<m;i++){
int l=reader.readInt()-1;
int r=reader.readInt()-1;
int x=reader.readInt()-1;
//log("l:"+l+" x:"+x+" r:"+r);
int lo=0;
String znx="";
loop:for (int u=l;u<=r;u++){
if (p[u]<p[x]){
lo++;
if (lo>x-l)
break loop;
}
}
//log(znx+" // "+p[x]);
String res="No";
if (x-l==lo)
res="Yes";
output(res);
}
try {
out.close();
}
catch (Exception e){}
}
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 | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | 3d49b5ca953f72fc2dd64385eba67ae6 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.TreeSet;
public final class CF_416_B{
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 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) {}}
static int MX=Integer.MAX_VALUE;
// Global vars
static BufferedWriter out;
static InputReader reader;
static void process() throws Exception {
out = new BufferedWriter(new OutputStreamWriter(System.out));
reader=new InputReader(System.in);
int n=reader.readInt();
int m=reader.readInt();
int[] p=new int[n];
for (int i=0;i<n;i++)
p[i]=reader.readInt()-1;
for (int i=0;i<m;i++){
int l=reader.readInt()-1;
int r=reader.readInt()-1;
int x=reader.readInt()-1;
//log("l:"+l+" x:"+x+" r:"+r);
int lo=0;
String znx="";
for (int u=l;u<=r;u++){
if (p[u]<p[x])
lo++;
}
//log(znx+" // "+p[x]);
String res="No";
if (x-l==lo)
res="Yes";
output(res);
}
try {
out.close();
}
catch (Exception e){}
}
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 | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | a1127fb771b8b35118a31233b1a56a57 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* 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;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
static class TaskB {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt();
int m = in.nextInt();
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = in.nextInt();
}
for (int i = 0; i < m; i++) {
int l = in.nextInt() - 1;
int r = in.nextInt() - 1;
int x = in.nextInt() - 1;
int t = arr[x];
int count = 0;
for (int j = l; j <= r; j++) {
if (t > arr[j]) {
count++;
}
}
if (count != x - l) {
out.println("No");
} else {
out.println("Yes");
}
}
}
}
}
| Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | 794438df4d77f59c1e8f9e92a64a998d | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* 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;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
static class TaskB {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt();
int m = in.nextInt();
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = in.nextInt();
}
for (int i = 0; i < m; i++) {
int l = in.nextInt() - 1;
int r = in.nextInt() - 1;
int x = in.nextInt() - 1;
int temp = arr[x];
int count = 0;
for (int j = l; j <= r; j++) {
if (temp > arr[j]) {
count++;
}
}
if (count != x - l) {
out.println("No");
} else {
out.println("Yes");
}
}
}
}
}
| Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | abdf02e8cc739ff7cbc99bf8cc1168c7 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
public class A
{
public static void main(String ... ar)
{
InputReader scan=new InputReader(System.in);
int a=scan.readInt();
int b=scan.readInt();
int c=0;
int [] arr=new int[a];
for(int i=0;i<a;i++)
{
arr[i]=scan.readInt();
}
for(int i=0;i<b;i++)
{
int l=scan.readInt()-1;
int r=scan.readInt()-1;
int m=scan.readInt()-1;
for(int j=l;j<=r;j++)
{
if(arr[m]>arr[j])
{
c++;
}
}
if(c==(m-l))
{
System.out.println("Yes");
}
else
{
System.out.println("No");
}
c=0;
}
}
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 readInt()
{
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 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 readLine() {
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 double readDouble() {
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, readInt());
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, readInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public long readLong() {
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 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);
}
public boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
}
| Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | 1bb45e31ae6f8573ea26240bed127c69 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class B {
static int [] numeros;
static String[] respostas;
static int comprimento , ordens;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inf[] = br.readLine().split(" ");
comprimento = Integer.parseInt(inf[0]);
ordens = Integer.parseInt(inf[1]);
respostas = new String[ordens];
numeros = new int[comprimento];
String inf2[] = br.readLine().split(" ");
for (int i = 0; i < comprimento; i++){
numeros[i] = Integer.parseInt(inf2[i]);
}
for (int i = 0; i < ordens; i++){
int l, r, x;
String inf3[] = br.readLine().split(" ");
l = Integer.parseInt(inf3[0])-1;
r = Integer.parseInt(inf3[1])-1;
x = Integer.parseInt(inf3[2])-1;
int numero = numeros[x];
int maior = 0;
for (int y = l; y < r+1; y++){
if (numeros[y]> numero){
maior+=1;
}
}
if (r-maior == x){
respostas[i] = "Yes";
} else {
respostas[i] = "No";
}
}
for (int i = 0; i < ordens; i++){
System.out.println(respostas[i]);
}
}
}
| Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | 7b2a6575022a4798be71cba4372e0736 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
static Scanner in = new Scanner(System.in);
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.valueOf(st.nextToken());
int m = Integer.valueOf(st.nextToken());
int a[] = new int[n + 1];
st = new StringTokenizer(br.readLine());
for (int i = 1; i <= n; i++)
a[i] = Integer.valueOf(st.nextToken());
for (int i = 0; i < m; i++) {
st = new StringTokenizer(br.readLine());
int l = Integer.valueOf(st.nextToken());
int r = Integer.valueOf(st.nextToken());
int x = Integer.valueOf(st.nextToken());
int cnt = 0;
for (int j = l; j <= r; j++) {
if (a[j] < a[x])
cnt++;
}
if(cnt == x-l)
System.out.println("Yes");
else {
System.out.println("No");
}
}
}
} | Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | b923e7691525c92c704f449e78ed9f1e | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
public class codeforces
{
public static void main(String[] args)
{
InputReader in = new InputReader(System.in);
PrintWriter pw = new PrintWriter(System.out);
//Code Starts Here
int n = in.nextInt();
int m = in.nextInt();
int[] a = new int[n+1];
for(int i=1;i<=n; i++)
a[i] = in.nextInt();
for(int i=0; i<m; i++) {
int l1 = in.nextInt();
int l2 = in.nextInt();
int x = in.nextInt();
if(l1<=x && x<=l2) {
int r = 0;
int l = 0;
for(int j=x-1; j>=l1; j--) {
if(a[j]>a[x])
l++;
}
for(int j=x+1; j<=l2; j++) {
if(a[j]<a[x])
r++;
}
if(l==r)
pw.println("Yes");
else
pw.println("No");
}
else
pw.println("YES");
}
//Code Ends Here
pw.flush();
pw.close();
}
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private 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 String nextLine() {
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isEndOfLine(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;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
public static long mod = 1000000007;
public static int d;
public static int p;
public static int q;
public static int[] suffle(int[] a,Random gen)
{
int n = a.length;
for(int i=0;i<n;i++)
{
int ind = gen.nextInt(n-i)+i;
int temp = a[ind];
a[ind] = a[i];
a[i] = temp;
}
return a;
}
public static void swap(int a, int b){
int temp = a;
a = b;
b = temp;
}
public static ArrayList<Integer> primeFactorization(int n)
{
ArrayList<Integer> a =new ArrayList<Integer>();
for(int i=2;i*i<=n;i++)
{
while(n%i==0)
{
a.add(i);
n/=i;
}
}
if(n!=1)
a.add(n);
return a;
}
public static void sieve(boolean[] isPrime,int n)
{
for(int i=1;i<n;i++)
isPrime[i] = true;
isPrime[0] = false;
isPrime[1] = false;
for(int i=2;i*i<n;i++)
{
if(isPrime[i] == true)
{
for(int j=(2*i);j<n;j+=i)
isPrime[j] = false;
}
}
}
static boolean coprime(long u, long v)
{
if (((u | v) & 1) == 0) return false;
while ((u & 1) == 0) u >>= 1;
if (u == 1) return true;
do
{
while ((v & 1) == 0) v >>= 1;
if (v == 1) return true;
if (u > v) { long t = v; v = u; u = t; }
v -= u;
} while (v != 0);
return false;
}
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 void extendedEuclid(int A,int B)
{
if(B==0)
{
d = A;
p = 1 ;
q = 0;
}
else
{
extendedEuclid(B, A%B);
int temp = p;
p = q;
q = temp - (A/B)*q;
}
}
public static long LCM(long a,long b)
{
return (a*b)/GCD(a,b);
}
public static int LCM(int a,int b)
{
return (a*b)/GCD(a,b);
}
public static int binaryExponentiation(int x,int n)
{
int result=1;
while(n>0)
{
if(n % 2 ==1)
result=result * x;
x=x*x;
n=n/2;
}
return result;
}
public static long binaryExponentiation(long x,long n)
{
long result=1;
while(n>0)
{
if(n % 2 ==1)
result=result * x;
x=x*x;
n=n/2;
}
return result;
}
public static int modularExponentiation(int x,int n,int M)
{
int result=1;
while(n>0)
{
if(n % 2 ==1)
result=(result * x)%M;
x=(x*x)%M;
n=n/2;
}
return result;
}
public static long modularExponentiation(long x,long n,long M)
{
long result=1;
while(n>0)
{
if(n % 2 ==1)
result=(result * x)%M;
x=(x*x)%M;
n=n/2;
}
return result;
}
public static int modInverse(int A,int M)
{
return modularExponentiation(A,M-2,M);
}
public static long modInverse(long A,long M)
{
return modularExponentiation(A,M-2,M);
}
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;
for (int i=5; i*i<=n; i=i+6)
{
if (n%i == 0 || n%(i+2) == 0)
return false;
}
return true;
}
static class pair implements Comparable<pair>
{
Integer x, y;
pair(int x,int y)
{
this.x=x;
this.y=y;
}
public int compareTo(pair o) {
int result = x.compareTo(o.x);
if(result==0)
result = y.compareTo(o.y);
return result;
}
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();
}
}
} | Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | 741e7f41e6eeb5730241e57e4a0815d9 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.util.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
public class Main
{
public static void main(String[] args) throws Exception
{
long startTime = System.nanoTime();
int n=in.nextInt();
int m=in.nextInt();
int [] data=new int[n+1];
for(int i=1;i<=n;i++)
{
data[i]=in.nextInt();
}
for(int j=0;j<m;j++)
{
int l=in.nextInt();
int r=in.nextInt();
int x=in.nextInt();
int a=0;
int b=0;
for(int i=l;i<=x;i++)
{
if(data[i] > data[x])
{
a++;
}
}
for(int i=x+1;i<=r;i++)
{
if(data[i] < data[x])
{
b++;
}
}
if(a==b)
{
out.println("Yes");
}
else
{
out.println("No");
}
}
long endTime = System.nanoTime();
err.println("Execution Time : +" + (endTime-startTime)/1000000 + " ms");
exit(0);
}
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 long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
}
static void exit(int a)
{
out.close();
err.close();
System.exit(a);
}
static InputStream inputStream = System.in;
static OutputStream outputStream = System.out;
static OutputStream errStream = System.err;
static InputReader in = new InputReader(inputStream);
static PrintWriter out = new PrintWriter(outputStream);
static PrintWriter err = new PrintWriter(errStream);
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
}
| Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | 4741225e2f340e31e3f4c20d674c5139 | train_004.jsonl | 1495877700 | Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation Pβ=β[p1,βp2,β...,βpn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladikβs mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number xΒ β what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.concurrent.ThreadLocalRandom;
public class B {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
int m = sc.nextInt();
int a[] = new int[n];
for (int i = 0; i < a.length; i++) {
int x = sc.nextInt();
a[i] = x;
}
for (int i = 0; i < m; i++) {
int l = sc.nextInt() - 1;
int r = sc.nextInt() - 1;
int pos = sc.nextInt() - 1;
int less = 0;
int great = 0;
for (int j = l; j <= r; j++) {
if (j < pos && a[j] > a[pos])
great++;
else if (j > pos && a[j] < a[pos])
less++;
}
if (less == great)
out.println("Yes");
else
out.println("No");
}
out.flush();
out.close();
}
static void shuffleArray(int[] ar) {
Random rnd = ThreadLocalRandom.current();
for (int i = ar.length - 1; i > 0; i--) {
int index = rnd.nextInt(i + 1);
int a = ar[index];
ar[index] = ar[i];
ar[i] = a;
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
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 boolean ready() throws IOException {
return br.ready();
}
}
} | Java | ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3"] | 2 seconds | ["Yes\nNo\nYes\nYes\nNo", "Yes\nNo\nYes\nNo\nYes"] | NoteExplanation of first test case: [1,β2,β3,β4,β5]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [3,β4,β5,β2,β1]Β β permutation after sorting, 1-st element has changed, so answer is "No". [5,β2,β3,β4,β1]Β β permutation after sorting, 3-rd element hasnβt changed, so answer is "Yes". [5,β4,β3,β2,β1]Β β permutation after sorting, 4-th element hasnβt changed, so answer is "Yes". [5,β1,β2,β3,β4]Β β permutation after sorting, 3-rd element has changed, so answer is "No". | Java 8 | standard input | [
"implementation",
"sortings"
] | 44162a97e574594ac0e598368e8e4e14 | First line contains two space-separated integers n, m (1ββ€βn,βmββ€β104)Β β length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1,βp2,β...,βpn (1ββ€βpiββ€βn)Β β permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1ββ€βliββ€βxiββ€βriββ€βn)Β β left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik. | 1,200 | For each momβs sorting on itβs own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | standard output | |
PASSED | 7e584ed057a633a75e10dd833d83dc59 | train_004.jsonl | 1353339000 | Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2Β·xβ+β1ββ€βn) and take a coin from each chest with numbers x, 2Β·x, 2Β·xβ+β1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied.Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int[] a=new int[n+1];
for(int i=1;i<=n;i++){
a[i]=in.nextInt();
}
int ans=0;
for(int i=n;i>0;i--){
int x=i/2;
if(x==0) x=i;
if(x*2+1>n) continue;
ans+=a[i];
a[x]=max(a[x]-a[i],0);
a[2*x]=max(a[2*x]-a[i],0);
a[2*x+1]=max(a[2*x+1]-a[i],0);
}
for(int i=1;i<=n;i++){
if(a[i]!=0){
System.out.println(-1);
return;
}
}
System.out.println(ans);
}
private static int max(int i, int j) {
if(i>j)
return i;
else return j;
}
}
| Java | ["1\n1", "3\n1 2 3"] | 2 seconds | ["-1", "3"] | NoteIn the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests.In the second sample there is only one possible move xβ=β1. This move should be repeated at least 3 times to empty the third chest. | Java 7 | standard input | [
"greedy"
] | 42bfc8dbf45f643782bf42be432cb57c | The first line contains a single integer n (1ββ€βnββ€β100) β the number of chests with coins. The second line contains a sequence of space-separated integers: a1,βa2,β...,βan (1ββ€βaiββ€β1000), where ai is the number of coins in the chest number i at the beginning of the game. | 1,700 | Print a single integer β the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. | standard output | |
PASSED | 694a7ddc24854fd0a1a234583c455da1 | train_004.jsonl | 1353339000 | Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2Β·xβ+β1ββ€βn) and take a coin from each chest with numbers x, 2Β·x, 2Β·xβ+β1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied.Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. | 256 megabytes | import java.io.*;
import java.util.*;
public class GameWithCoins {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
int n = in.nextInt();
int[] a = new int[n + 1];
for (int i = 1; i <= n; ++i)
a[i] = in.nextInt();
if (n % 2 == 0 || n < 3)
System.out.println(-1);
else {
int ans = 0;
for (int i = n; i >= 2; --i) {
int x = i / 2;
int max = a[i];
ans += max;
a[x] = Math.max(0, a[x] - max);
a[2 * x] = Math.max(0, a[2 * x] - max);
a[2 * x + 1] = Math.max(0, a[2 * x + 1] - max);
}
for (int i = 0; i < n; ++i)
if (a[i] > 0)
ans += a[i];
System.out.println(ans);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = new StringTokenizer("");
}
public String next() {
try {
while (!tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
return tokenizer.nextToken();
}
public String nextLine() {
String line = null;
try {
tokenizer = new StringTokenizer("");
line = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return line;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
boolean hasNext() {
while (!tokenizer.hasMoreTokens()) {
String line = nextLine();
if (line == null) return false;
tokenizer = new StringTokenizer(line);
}
return true;
}
}
}
| Java | ["1\n1", "3\n1 2 3"] | 2 seconds | ["-1", "3"] | NoteIn the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests.In the second sample there is only one possible move xβ=β1. This move should be repeated at least 3 times to empty the third chest. | Java 7 | standard input | [
"greedy"
] | 42bfc8dbf45f643782bf42be432cb57c | The first line contains a single integer n (1ββ€βnββ€β100) β the number of chests with coins. The second line contains a sequence of space-separated integers: a1,βa2,β...,βan (1ββ€βaiββ€β1000), where ai is the number of coins in the chest number i at the beginning of the game. | 1,700 | Print a single integer β the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. | standard output | |
PASSED | ad7e1e814ce98991cbf0356475e1546d | train_004.jsonl | 1353339000 | Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2Β·xβ+β1ββ€βn) and take a coin from each chest with numbers x, 2Β·x, 2Β·xβ+β1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied.Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. | 256 megabytes | import java.io.*;
import java.util.*;
public class GameWithCoins {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
int n = in.nextInt();
int[] a = new int[n + 1];
for (int i = 1; i <= n; ++i)
a[i] = in.nextInt();
if (n % 2 == 0 || n < 3)
System.out.println(-1);
else {
int ans = 0;
for (int i = n; i >= 2; --i) {
int x = i / 2;
int max = a[i];
ans += max;
a[x] = Math.max(0, a[x] - max);
a[2 * x] = Math.max(0, a[2 * x] - max);
a[2 * x + 1] = Math.max(0, a[2 * x + 1] - max);
}
boolean ok = true;
for (int i = 0; i < n; ++i)
if (a[i] > 0)
ans += a[i];
if (!ok)
System.out.println(-1);
else
System.out.println(ans);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = new StringTokenizer("");
}
public String next() {
try {
while (!tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
return tokenizer.nextToken();
}
public String nextLine() {
String line = null;
try {
tokenizer = new StringTokenizer("");
line = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return line;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
boolean hasNext() {
while (!tokenizer.hasMoreTokens()) {
String line = nextLine();
if (line == null) return false;
tokenizer = new StringTokenizer(line);
}
return true;
}
}
}
| Java | ["1\n1", "3\n1 2 3"] | 2 seconds | ["-1", "3"] | NoteIn the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests.In the second sample there is only one possible move xβ=β1. This move should be repeated at least 3 times to empty the third chest. | Java 7 | standard input | [
"greedy"
] | 42bfc8dbf45f643782bf42be432cb57c | The first line contains a single integer n (1ββ€βnββ€β100) β the number of chests with coins. The second line contains a sequence of space-separated integers: a1,βa2,β...,βan (1ββ€βaiββ€β1000), where ai is the number of coins in the chest number i at the beginning of the game. | 1,700 | Print a single integer β the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. | standard output | |
PASSED | 3ee8ce6c7cf6e0e6c1ee01492bdacf19 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | //package autowired;
import java.util.*;
public class Greg_Array {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int k=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
Triplet[] arr=new Triplet[m];//for operations
for(int i=0;i<m;i++)
{
int l=sc.nextInt();
int r=sc.nextInt();
int v=sc.nextInt();
arr[i]=new Triplet(l,r,v);
}
Pair b[]=new Pair[k];
for(int i=0;i<k;i++) //for queries
{
int x=sc.nextInt();
int y=sc.nextInt();
b[i]=new Pair(x,y);
}
long ans[]=new long[n];
long temp[]=new long[m];
for(int i=0;i<k;i++)
{
int left=b[i].x;
temp[left-1]+=1;
int right=b[i].y;
if(right<m)
temp[right]-=1;
}
for(int i=1;i<m;i++)
{
temp[i]+=temp[i-1];
}
for(int i=0;i<m;i++)
{
int left=arr[i].l;
left-=1;
ans[left]+=temp[i]*arr[i].d;
int right=arr[i].r;
if(right<n)
ans[right]-=temp[i]*arr[i].d;
}
for(int i=1;i<n;i++)
{
ans[i]+=ans[i-1];
}
for(int i=0;i<n;i++)
{
ans[i]+=a[i];
System.out.print(ans[i]+" ");
}
System.out.println();
}
}
class Pair
{
int x,y;
public Pair(int x,int y)
{
this.x=x;
this.y=y;
}
}
class Triplet
{
int l,r,d;
public Triplet(int l,int r,int d)
{
this.l=l;
this.r=r;
this.d=d;
}
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 984318449fa8012185f580977e75e720 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author PM
*/
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);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
}
class TaskC {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
long[] a = new long[n];
//array
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
int[] opL = new int[m], opR = new int[m], opD = new int[m];
for (int i = 0; i < m; i++) {
opL[i] = in.nextInt()-1;
opR[i] = in.nextInt()-1;
opD[i] = in.nextInt();
}
//count how many times each operation executed, (will be summed up from left)
long[] executeNumber = new long[m+1];
for (int i = 0; i < k; i++) {
int st = in.nextInt()-1; //first executed op
int en = in.nextInt()-1; //last exected op (inclusive)
executeNumber[st]++;
executeNumber[en+1]--;
}
//now execute operations on the array
long numberOpsToExecute = 0;
long[] shifts = new long[n+1];
for (int i = 0; i < m; i++) {
numberOpsToExecute += executeNumber[i];
shifts[opL[i]] += numberOpsToExecute * opD[i];
shifts[opR[i]+1] -= numberOpsToExecute * opD[i];
}
long fullShift = 0;
for (int i = 0; i < n; i++) {
fullShift += shifts[i];
out.print(fullShift + a[i]);
out.print(' ');
}
}
}
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());
}
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 67408756adfdddb5d9e8c276b4c8786d | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes |
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.StringTokenizer;
public class A {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();
long [] a = new long[n];
for (int i = 0; i < a.length; i++) {
a[i] = sc.nextInt();
}
int [] l = new int[m];
int [] r = new int[m];
int [] d = new int[m];
int [] occ = new int[m+1];
long [] tmp = new long[n+1];
for (int i = 0; i < m; i++) {
l[i] = sc.nextInt()-1; r[i] = sc.nextInt()-1; d[i] = sc.nextInt();
}
for (int i = 0; i < k; i++) {
int x = sc.nextInt()-1, y = sc.nextInt()-1;
occ[y+1]--;
occ[x]++;
}
int num = 0;
for (int i = 0; i < occ.length-1; i++) {
num += occ[i];
tmp[r[i]+1] -= 1l*d[i]*num;
tmp[l[i]] += 1l*d[i]*num;
}
long nu = 0;
for (int i = 0; i < a.length; i++) {
nu += tmp[i];
out.print(a[i]+nu + " ");
}
out.flush();
out.close();
}
static class Scanner {
BufferedReader bf;
StringTokenizer st;
public Scanner(InputStream i) {
bf = new BufferedReader(new InputStreamReader(i));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(bf.readLine());
return st.nextToken();
}
public int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(next());
}
public long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(next());
}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 72ca00b28a8139d23a4ec7ac41a9d646 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.util.*;
import java.io.*;
public final class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
long[] a = new long[n];
long[] a1 = new long[n];
for(int i = 0; i<n; i++)
a[i] = sc.nextLong();
int[][] q = new int[m][3];
for(int i = 0; i<m; i++) {
q[i][0] = sc.nextInt();
q[i][1] = sc.nextInt();
q[i][2] = sc.nextInt();
}
long[] freq = new long[m];
for(int i = 0; i<k; i++) {
int l = sc.nextInt();
int r = sc.nextInt();
freq[l-1]++;
if(r<m)
freq[r]--;
}
long f = 0;
for(int i = 0; i<m; i++) {
f+=freq[i];
long adds = q[i][2]*1l*f;
a1[q[i][0]-1]+=adds;
if(q[i][1]<n)
a1[q[i][1]]-=adds;
}
long add = 0;
for(int i = 0; i<n; i++) {
add+=a1[i];
System.out.print(a[i]+add + " ");
}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | ecd568b3cebc07cace2578fd8cb2b259 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class gregAndArray {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[]s=br.readLine().split(" ");
int n=Integer.parseInt(s[0]);
int m=Integer.parseInt(s[1]);
int k=Integer.parseInt(s[2]);
long [] ns=new long [n];
s=br.readLine().split(" ");
for(int i=0;i<n;i++){
ns[i]=Integer.parseInt(s[i]);
}
int[][] ops=new int[m][3];
for(int i=0;i<m;i++){
s=br.readLine().split(" ");
ops[i][0]=Integer.parseInt(s[0]);
ops[i][1]=Integer.parseInt(s[1]);
ops[i][2]=Integer.parseInt(s[2]);
}
bit qs=new bit(m);
for(int i=0;i<k;i++){
s=br.readLine().split(" ");
int start=Integer.parseInt(s[0])-1;
int end=Integer.parseInt(s[1]);
qs.add(end, 1);
qs.add(start, -1);
}
bit ans=new bit(n);
for(int i=0;i<m;i++){
ans.add(ops[i][1], (ops[i][2]*qs.q(i)));
ans.add(ops[i][0]-1, -(ops[i][2]*qs.q(i)));
}
// for(int i=0;i<m;i++){
// System.out.println(qs.q(i));
// }
System.out.print(ns[0]+ans.q(0));
for(int i=1;i<n;i++){
System.out.print(" "+(ns[i]+ans.q(i)));
}
System.out.println();
}
}
class bit{
long n;
long[] v;
bit (long N){
v=new long[(int) (n=N)];
}
long q(long x){
return q2(x);
}
long q2(long x){
return x<0?0:(v[(int) x]+q2((x&(x+1))-1));
}
void add(int p, long x){
for(int i=p;i<n;i|=(i+1)){
v[i]-=x;
}
for(int i=0;i<n;i|=(i+1)){
v[i]+=x;
}
}
}
//class bit{
// long[][] vals;
// public bit(int a){
// vals=new long[20][a];
// }
// public void add(int i, long v){
// int pow=0;
// i--;
// while(pow<20){
// if((i&1)==0){
// vals[pow>>1][i]+=v;
// }
// pow++;
// i>>=1;
// }
// }
// public long q(int i){
// int pow=0;
// long v=0;
// while(pow<20){
// if((i&1)!=0){
// v+=vals[pow>>1][i];
// }
// pow++;
// i>>=1;
// }
// return v;
// }
//} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 68fb6a2786a479bcd9af2d22dec0e2c2 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class gregAndArray {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[]s=br.readLine().split(" ");
int n=Integer.parseInt(s[0]);
int m=Integer.parseInt(s[1]);
int k=Integer.parseInt(s[2]);
long [] ns=new long [n];
s=br.readLine().split(" ");
for(int i=0;i<n;i++){
ns[i]=Integer.parseInt(s[i]);
}
int[][] ops=new int[m][3];
for(int i=0;i<m;i++){
s=br.readLine().split(" ");
ops[i][0]=Integer.parseInt(s[0]);
ops[i][1]=Integer.parseInt(s[1]);
ops[i][2]=Integer.parseInt(s[2]);
}
bit qs=new bit(m+1);
for(int i=0;i<k;i++){
s=br.readLine().split(" ");
int start=Integer.parseInt(s[0])-2;
int end=Integer.parseInt(s[1])-1;
qs.add(end, 1);
qs.add(start, -1);
}
bit ans=new bit(n+1);
for(int i=0;i<m;i++){
ans.add(ops[i][1]-1, (ops[i][2]*qs.q(i)));
ans.add(ops[i][0]-2, -(ops[i][2]*qs.q(i)));
}
// for(int i=0;i<m;i++){
// System.out.println(qs.q(i));
// }
System.out.print(ns[0]+ans.q(0));
for(int i=1;i<n;i++){
System.out.print(" "+(ns[i]+ans.q(i)));
}
System.out.println();
}
}
//class bit{
// long n;
// long[] v;
// bit (long N){
// v=new long[(int) (n=N)];
// }
// long q(long x){
// return q2(x);
// }
// long q2(long x){
// return x<0?0:(v[(int) x]+q2((x&(x+1))-1));
// }
// void add(int p, long x){
// for(int i=p;i<n;i|=(i+1)){
// v[i]-=x;
// }
// for(int i=0;i<n;i|=(i+1)){
// v[i]+=x;
// }
// }
//}
//
class bit {
long[] arr;
public bit(int n) {
arr = new long[n+1];
}
void add(int index, long val) {
index++;
while (index > 0) {
this.arr[index] += val;
index -= (index & -index);
}
}
long q(int index) {
index++;
long sum = 0;
while (index < this.arr.length) {
sum += this.arr[index];
index += (index & -index);
}
return sum;
}
}
//class bit{
// long[][] vals;
// public bit(int a){
// vals=new long[20][a];
// }
// public void add(int i, long v){
// int pow=0;
// i--;
// while(pow<20){
// if((i&1)==0){
// vals[pow>>1][i]+=v;
// }
// pow++;
// i>>=1;
// }
// }
// public long q(int i){
// int pow=0;
// long v=0;
// while(pow<20){
// if((i&1)!=0){
// v+=vals[pow>>1][i];
// }
// pow++;
// i>>=1;
// }
// return v;
// }
//} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 9a50273f63cdaed84d4a33093b5a85be | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.BufferedOutputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Aeroui
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Kattio in = new Kattio(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, Kattio in, PrintWriter out) {
int n = in.nextInt();
int m = in.nextInt();
int k = in.nextInt();
int[] preQ = new int[m + 2];
long[] arr = new long[n + 2];
long[] pre = new long[n + 2];
Query[] queries = new Query[m + 1];
for (int i = 1; i <= n; ++i) {
arr[i] = in.nextLong();
}
for (int i = 1; i <= m; ++i) {
queries[i] = new Query(in.nextInt(), in.nextInt(), in.nextLong());
}
for (int i = 1; i <= k; ++i) {
int l = in.nextInt();
int r = in.nextInt();
++preQ[l];
--preQ[r + 1];
}
for (int i = 1; i <= m; ++i) {
preQ[i] += preQ[i - 1];
int l = queries[i].l;
int r = queries[i].r;
long d = (long) preQ[i] * queries[i].d;
pre[l] += d;
pre[r + 1] -= d;
}
for (int i = 1; i <= n; ++i) {
pre[i] += pre[i - 1];
arr[i] += pre[i];
out.print(arr[i] + " ");
}
}
private class Query {
int l;
int r;
long d;
public Query(int l, int r, long d) {
this.l = l;
this.r = r;
this.d = d;
}
}
}
static class Kattio extends PrintWriter {
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
public Kattio(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public Kattio(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) {
}
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | c27cfda654b7c1169548486054a8c7f3 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | /*
[ ( ^ _ ^ ) ]
*/
import java.io.*;
import java.util.*;
public class test {
int INF = (int)1e9;
long MOD = 1000000007;
void solve(InputReader in, PrintWriter out) throws IOException {
int n = in.nextInt();
int q = in.nextInt();
int k = in.nextInt();
long[] a = new long[n+5];
for(int i=1; i<=n; i++) {
a[i] = in.nextInt();
}
long[][] m = new long[q+5][4];
for(int i=1; i<=q; i++) {
m[i][0] = in.nextInt();
m[i][1] = in.nextInt();
m[i][2] = in.nextInt();
}
for(int i=0; i<k; i++) {
int x = in.nextInt();
int y = in.nextInt();
m[x][3] += 1;
m[y+1][3] -= 1;
}
long[] d = new long[n+5];
for(int i=1; i<=q; i++) {
m[i][3] += m[i-1][3];
d[(int)m[i][0]] += m[i][2]*m[i][3];
d[(int)m[i][1]+1] -= m[i][2]*m[i][3];
}
for(int i=1; i<=n; i++) {
d[i] += d[i-1];
out.print((a[i]+d[i])+" ");
}
out.println();
}
public static void main(String[] args) throws IOException {
if(args.length>0 && args[0].equalsIgnoreCase("d")) {
DEBUG_FLAG = true;
}
InputReader in = new InputReader();
PrintWriter out = new PrintWriter(System.out);
int t = 1;//in.nextInt();
long start = System.nanoTime();
while(t-->0) {
new test().solve(in, out);
}
long end = System.nanoTime();
debug("\nTime: " + (end-start)/1e6 + " \n\n");
out.close();
}
static boolean DEBUG_FLAG = false;
static void debug(String s) {
if(DEBUG_FLAG) System.out.print(s);
}
public static void show(Object... o) {
System.out.println(Arrays.deepToString(o));
}
static class InputReader {
static BufferedReader br;
static StringTokenizer st;
public InputReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !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());
}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 3b4f5fb08e586b091edd0389ccedb394 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();
long[] a = new long[n + 2];
for (int i = 1; i <= n; i++)
a[i] = sc.nextInt();
Operation[] ops = new Operation[m + 1];
for (int i = 1; i <= m; i++)
ops[i] = new Operation(sc.nextInt(), sc.nextInt(), sc.nextInt());
int[] cnt = new int[m + 2];
while (k-- > 0) {
cnt[sc.nextInt()]++;
cnt[sc.nextInt() + 1]--;
}
long[] effect = new long[n + 2];
for (int i = 1; i <= m; i++) {
cnt[i] += cnt[i - 1];
int l = ops[i].l, r = ops[i].r;
long add = 1l * cnt[i] * ops[i].d;
effect[l] += add;
effect[r + 1] -= add;
}
for (int i = 1; i <= n; i++) {
effect[i] += effect[i - 1];
out.print(a[i] + effect[i] + " ");
}
out.flush();
out.close();
}
static class Operation {
int l, r, d;
public Operation(int l, int r, int d) {
this.l = l;
this.r = r;
this.d = d;
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
boolean ready() throws IOException {
return br.ready();
}
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[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
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 Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public double[] nextDoubleArray(int n) throws IOException {
double[] ans = new double[n];
for (int i = 0; i < n; i++)
ans[i] = nextDouble();
return ans;
}
public short nextShort() throws IOException {
return Short.parseShort(next());
}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 7322f9053093ba221106f8b74dd6090b | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
* @author Don Li
*/
public class GregArray {
void solve() {
int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = in.nextInt();
int[] l = new int[m], r = new int[m], d = new int[m];
for (int i = 0; i < m; i++) {
l[i] = in.nextInt() - 1;
r[i] = in.nextInt();
d[i] = in.nextInt();
}
int[] x = new int[k], y = new int[k];
for (int i = 0; i < k; i++) {
x[i] = in.nextInt() - 1;
y[i] = in.nextInt();
}
int[] cnt = new int[m + 1];
for (int i = 0; i < k; i++) {
cnt[x[i]]++;
cnt[y[i]]--;
}
for (int i = 1; i < m; i++) cnt[i] += cnt[i - 1];
long[] delta = new long[n + 1];
for (int i = 0; i < m; i++) {
delta[l[i]] += (long) d[i] * cnt[i];
delta[r[i]] -= (long) d[i] * cnt[i];
}
for (int i = 1; i < n; i++) delta[i] += delta[i - 1];
for (int i = 0; i < n; i++) {
if (i > 0) out.print(' ');
out.print(a[i] + delta[i]);
}
}
public static void main(String[] args) {
in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
out = new PrintWriter(System.out);
new GregArray().solve();
out.close();
}
static FastScanner in;
static PrintWriter out;
static class FastScanner {
BufferedReader in;
StringTokenizer st;
public FastScanner(BufferedReader in) {
this.in = in;
}
public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
public double nextDouble() {
return Double.parseDouble(nextToken());
}
}
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 868881d517d748f678ae94d8da7eb062 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes |
import java.io.*;
import java.util.StringTokenizer;
import static java.lang.Integer.parseInt;
public class C_Greg_and_Array {
static int n,m,k,l,r,d,x,y;
static long ar[];
static int cum[],ar2[];
static truple tr[];
static class truple{
int l,r,d;
public truple(int l,int r,int d){
this.r = r;
this.l = l;
this.d = d;
}
}
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer tk = new StringTokenizer(in.readLine());
n = parseInt(tk.nextToken());
m = parseInt(tk.nextToken());
k = parseInt(tk.nextToken());
ar = new long[n + 1];
ar2 = new int[n];
cum = new int[m + 1];
tr = new truple[m];
tk = new StringTokenizer(in.readLine());
for (int i = 0; i < n; i++) {
ar2[i] = parseInt(tk.nextToken());
}
for (int i = 0; i < m; i++) {
tk = new StringTokenizer(in.readLine());
l = parseInt(tk.nextToken());
r = parseInt(tk.nextToken());
d = parseInt(tk.nextToken());
l--;r--;
tr[i] = new truple(l,r,d);
}
for (int i = 0; i < k; i++) {
tk = new StringTokenizer(in.readLine());
x = parseInt(tk.nextToken());
y = parseInt(tk.nextToken());
x--; y--;
cum[x]++;
cum[y + 1]--;
}
for (int i = 1; i < m; i++) {
cum[i] = cum[i] + cum[i - 1];
}
for (int i = 0; i < m; i++) {
ar[tr[i].l] += 1L * cum[i] * tr[i].d;
ar[tr[i].r + 1] -= 1L * cum[i] * tr[i].d;
}
for (int i = 1; i < n; i++) {
ar[i] = ar[i] + ar[i - 1];
}
for (int i = 0; i < n; i++) {
ar[i] += ar2[i];
}
out.write(ar[0]+"");
for (int i = 1; i < n; i++) {
out.write(" "+ar[i]);
}
out.newLine();
out.flush();
}
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 2d11eec6866d8cf41521f4f29d153dfb | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
static class FastScanner {
BufferedReader s;
StringTokenizer st;
public FastScanner(InputStream InputStream) {
st = new StringTokenizer("");
s = new BufferedReader(new InputStreamReader(InputStream));
}
public FastScanner(File f) throws FileNotFoundException {
st = new StringTokenizer("");
s = new BufferedReader(new FileReader(f));
}
public int nextInt() throws IOException {
if (st.hasMoreTokens())
return Integer.parseInt(st.nextToken());
else {
st = new StringTokenizer(s.readLine());
return nextInt();
}
}
public BigInteger big() throws IOException {
if (st.hasMoreTokens())
return new BigInteger(st.nextToken());
else {
st = new StringTokenizer(s.readLine());
return big();
}
}
public double nextDouble() throws IOException {
if (st.hasMoreTokens())
return Double.parseDouble(st.nextToken());
else {
st = new StringTokenizer(s.readLine());
return nextDouble();
}
}
public long nextLong() throws IOException {
if (st.hasMoreTokens())
return Long.parseLong(st.nextToken());
else {
st = new StringTokenizer(s.readLine());
return nextLong();
}
}
public String next() throws IOException {
if (st.hasMoreTokens())
return st.nextToken();
else {
st = new StringTokenizer(s.readLine());
return next();
}
}
public String nextLine() throws IOException {
return s.readLine();
}
public void close() throws IOException {
s.close();
}
}
public static void main(String[] args) throws IOException {
FastScanner in = new FastScanner(System.in);
int n = in.nextInt(), m = in.nextInt(), q = in.nextInt();
long[] arr = new long[n + 1];
for(int x = 1; x <= n; x++)
arr[x] = in.nextInt();
pair[] op = new pair[m + 1];
for(int x = 1; x <= m; x++) {
op[x] = new pair(in.nextInt(), in.nextInt(),in.nextInt());
}
long doop[] = new long[m + 2];
for(int x = 0; x < q; x++) {
doop[in.nextInt()]++;
doop[in.nextInt() + 1]--;
}
long sum = 0;
for(int x = 1; x <= m; x++) {
sum += doop[x];
doop[x] = sum;
}
long add[] = new long[n + 2];
for(int x = 1; x <= m; x++) {
long val = op[x].k * doop[x];
add[op[x].i] += val;
add[op[x].j + 1] -= val;
}
sum = 0;
for(int x = 1; x <= n; x++) {
sum += add[x];
add[x] = sum;
}
StringBuilder sb = new StringBuilder("");
for(int x = 1; x <= n; x++) {
long val = add[x] + arr[x];
sb.append(val + " ");
}
System.out.println(sb);
}
static class pair {
int i, j, k;
pair(int i, int j, int k) {
this.i = i;
this.j = j;
this.k = k;
}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 2f6e1d1aa22a61fd175a39587a41e669 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
try (InputReader in = new InputReader(System.in)) {
int N = in.nextInt();
int M = in.nextInt();
int K = in.nextInt();
int[] A = new int[N];
for (int i = 0; i < N; i++) {
A[i] = in.nextInt();
}
Operation[] operations = new Operation[M];
for (int i = 0; i < M; i++) {
int l = in.nextInt();
int r = in.nextInt();
int d = in.nextInt();
operations[i] = new Operation(l, r, d);
}
int[] cnt = new int[M + 1];
for (int i = 0; i < K; i++) {
int x = in.nextInt() - 1;
int y = in.nextInt() - 1;
cnt[x]++;
cnt[y + 1]--;
}
for (int i = 1; i < M; i++) {
cnt[i] += cnt[i - 1];
}
long[] sum = new long[N + 2];
for (int i = 0; i < M; i++) {
sum[operations[i].l] += (long)cnt[i] * operations[i].d;
sum[operations[i].r + 1] -= (long)cnt[i] * operations[i].d;
}
for (int i = 1; i <= N; i++) {
sum[i] += sum[i - 1];
}
for (int i = 0; i < N; i++) {
System.out.printf("%d ", sum[i + 1] + A[i]);
}
System.out.println();
}
}
private static class Operation{
public int l, r, d;
public Operation(int l, int r, int d) {
this.l = l;
this.r = r;
this.d = d;
}
}
static class InputReader implements AutoCloseable{
private BufferedReader reader;
private StringTokenizer tokenizer;
private InputStream inputStream;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 1 << 20);
tokenizer = null;
inputStream = stream;
}
private String nextToken() {
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(nextToken());
}
public String nextString(){
return nextToken();
}
public void close() {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | a474cae026e34b12b37c87f9b98502f6 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class code5 {
InputStream is;
PrintWriter out;
static long mod=pow(10,9)+7;
static final int max=100000;
static int dx[]={1,-1,-1,1,0,0,1,-1},dy[]={1,-1,1,-1,1,-1,0,0};
void solve()
{
int n=ni();
int m=ni();
int k=ni();
int a[]=na(n);
Pair p[]=new Pair[m];
for(int i=0;i<m;i++)
p[i]=new Pair(ni(),ni(),ni());
int dp[]=new int[m+1];
for(int i=0;i<k;i++)
{
int l=ni()-1;
int r=ni();
dp[l]++;
dp[r]--;
}
int count=0;
for(int i=0;i<m;i++)
{
count+=dp[i];
dp[i]=count;
}
long ans[]=new long[n+1];
for(int i=0;i<m;i++)
{
Pair temp=p[i];
ans[temp.x-1]+=(temp.k*1L)*dp[i];
ans[temp.y]-=(temp.k*1L)*dp[i];
}
long c=0;
for(int i=0;i<n;i++)
{
c+=ans[i];
ans[i]=c;
ans[i]+=a[i];
out.print(ans[i]+" ");
}
}
public static int count(int x)
{
int num=0;
while(x!=0)
{
x=x&(x-1);
num++;
}
return num;
}
static long d, x, y;
void extendedEuclid(long A, long B) {
if(B == 0) {
d = A;
x = 1;
y = 0;
}
else {
extendedEuclid(B, A%B);
long temp = x;
x = y;
y = temp - (A/B)*y;
}
}
long modInverse(long A,long M) //A and M are coprime
{
extendedEuclid(A,M);
return (x%M+M)%M; //x may be negative
}
public static void mergeSort(int[] arr, int l ,int r){
if((r-l)>=1){
int mid = (l+r)/2;
mergeSort(arr,l,mid);
mergeSort(arr,mid+1,r);
merge(arr,l,r,mid);
}
}
public static void merge(int arr[], int l, int r, int mid){
int n1 = (mid-l+1), n2 = (r-mid);
int left[] = new int[n1];
int right[] = new int[n2];
for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
int i =0, j =0, k = l;
while(i<n1 && j<n2){
if(left[i]>right[j]){
arr[k++] = right[j++];
}
else{
arr[k++] = left[i++];
}
}
while(i<n1) arr[k++] = left[i++];
while(j<n2) arr[k++] = right[j++];
}
public static void mergeSort(long[] arr, int l ,int r){
if((r-l)>=1){
int mid = (l+r)/2;
mergeSort(arr,l,mid);
mergeSort(arr,mid+1,r);
merge(arr,l,r,mid);
}
}
public static void merge(long arr[], int l, int r, int mid){
int n1 = (mid-l+1), n2 = (r-mid);
long left[] = new long[n1];
long right[] = new long[n2];
for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
int i =0, j =0, k = l;
while(i<n1 && j<n2){
if(left[i]>right[j]){
arr[k++] = right[j++];
}
else{
arr[k++] = left[i++];
}
}
while(i<n1) arr[k++] = left[i++];
while(j<n2) arr[k++] = right[j++];
}
static class Pair implements Comparable<Pair>{
int x,y,k,i;
Pair (int x,int y,int k){
this.x=x;
this.y=y;
this.k=k;
}
public int compareTo(Pair o) {
return this.x-o.x;
}
public boolean equals(Object o) {
if (o instanceof Pair) {
Pair p = (Pair)o;
return p.x == x && p.y == y && p.k==k;
}
return false;
}
@Override
public String toString() {
return "("+x + " " + y +" "+k+" "+i+" )";
}
}
public static boolean isPal(String s){
for(int i=0, j=s.length()-1;i<=j;i++,j--){
if(s.charAt(i)!=s.charAt(j)) return false;
}
return true;
}
public static String rev(String s){
StringBuilder sb=new StringBuilder(s);
sb.reverse();
return sb.toString();
}
public static long gcd(long x,long y){
if(x%y==0)
return y;
else
return gcd(y,x%y);
}
public static int gcd(int x,int y){
if(y==0)
return x;
return gcd(y,x%y);
}
public static long gcdExtended(long a,long b,long[] x){
if(a==0){
x[0]=0;
x[1]=1;
return b;
}
long[] y=new long[2];
long gcd=gcdExtended(b%a, a, y);
x[0]=y[1]-(b/a)*y[0];
x[1]=y[0];
return gcd;
}
public static int abs(int a,int b){
return (int)Math.abs(a-b);
}
public static long abs(long a,long b){
return (long)Math.abs(a-b);
}
public static int max(int a,int b){
if(a>b)
return a;
else
return b;
}
public static int min(int a,int b){
if(a>b)
return b;
else
return a;
}
public static long max(long a,long b){
if(a>b)
return a;
else
return b;
}
public static long min(long a,long b){
if(a>b)
return b;
else
return a;
}
public static long pow(long n,long p,long m){
long result = 1;
if(p==0)
return 1;
if (p==1)
return n;
while(p!=0)
{
if(p%2==1)
result *= n;
if(result>=m)
result%=m;
p >>=1;
n*=n;
if(n>=m)
n%=m;
}
return result;
}
public static long pow(long n,long p){
long result = 1;
if(p==0)
return 1;
if (p==1)
return n;
while(p!=0)
{
if(p%2==1)
result *= n;
p >>=1;
n*=n;
}
return result;
}
public static void debug(Object... o) {
System.out.println(Arrays.deepToString(o));
}
void run() throws Exception {
is = System.in;
out = new PrintWriter(System.out);
solve();
out.flush();
}
public static void main(String[] args) throws Exception {
new Thread(null, new Runnable() {
public void run() {
try {
new code5().run();
} catch (Exception e) {
e.printStackTrace();
}
}
}, "1", 1 << 26).start();
}
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))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m) {
char[][] map = new char[n][];
for (int i = 0; i < n; i++)
map[i] = ns(m);
return map;
}
private int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = ni();
return a;
}
private int ni() {
int num = 0, 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 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();
}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | f463a6c3a45c603d9c2faca8ab57555e | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | // δ½θ
οΌζ¨ζηε
η
import java.io.*;
import java.util.*;
public class cf {
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;
}
}
static class Operation {
int l, r, d;
public Operation(int l, int r, int d) {
this.l = l;
this.r = r;
this.d = d;
}
}
static class Fenwick {
long[] tree;
int size;
public Fenwick(int size) {
this.size = size;
tree = new long[size+5];
}
public void update(int idx, long val) {
while(idx <= size) {
tree[idx] += val;
idx += idx & (-idx);
}
}
public long getSum(int idx) {
long res = 0;
while(idx > 0) {
res += tree[idx];
idx -= idx & (-idx);
}
return res;
}
public long[] getArr() {
long[] res = new long[size+1];
for(int i=1;i<=size;i++) {
res[i] = getSum(i);
}
return res;
}
}
public static void main(String[] args) {
FastScanner sc = new FastScanner();
PrintWriter pw = new PrintWriter(System.out);
int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();
int[] a = new int[n+1];
for(int i=1;i<=n;i++) a[i] = sc.nextInt();
Operation[] operations = new Operation[m+1];
for(int i=1;i<=m;i++) operations[i] = new Operation(sc.nextInt(), sc.nextInt(), sc.nextInt());
Fenwick ori = new Fenwick(m);
for(int i=1;i<=k;i++) {
int x = sc.nextInt();
int y = sc.nextInt();
ori.update(x, (long) 1);
ori.update(y + 1, (long) -1);
}
long[] after = ori.getArr();
Fenwick ori2 = new Fenwick(n);
for(int i=1;i<after.length;i++) {
long total = operations[i].d * after[i];
ori2.update(operations[i].l, total);
ori2.update(operations[i].r + 1, -total);
}
long[] actual = ori2.getArr();
for(int i=1;i<actual.length;i++) {
pw.print(a[i] + actual[i] + " ");
}
pw.close();
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 1bb507ba148d0d421ddfe4c8174f73f4 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class SegmentTree { // 1-based DS, OOP
int N; // the number of elements in the array as a power of 2 (i.e. after padding)
long[] array, sTree, lazy;
SegmentTree(long[] in) {
array = in;
N = in.length - 1;
sTree = new long[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
lazy = new long[N << 1];
build(1, 1, N);
}
void build(int node, int b, int e) // O(n)
{
if (b == e)
sTree[node] = array[b];
else {
int mid = b + e >> 1;
build(node << 1, b, mid);
build(node << 1 | 1, mid + 1, e);
sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
}
}
void update_point(int index, int val) // O(log n)
{
index += N - 1;
sTree[index] += val;
while (index > 1) {
index >>= 1;
sTree[index] = sTree[index << 1] + sTree[index << 1 | 1];
}
}
void update_range(int i, int j, long l) // O(log n)
{
update_range(1, 1, N, i, j, l);
}
void update_range(int node, int b, int e, int i, int j, long l) {
if (i > e || j < b)
return;
if (b >= i && e <= j) {
sTree[node] += (e - b + 1) * l;
lazy[node] += l;
} else {
int mid = b + e >> 1;
propagate(node, b, mid, e);
update_range(node << 1, b, mid, i, j, l);
update_range(node << 1 | 1, mid + 1, e, i, j, l);
sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
}
}
void propagate(int node, int b, int mid, int e) {
lazy[node << 1] += lazy[node];
lazy[node << 1 | 1] += lazy[node];
sTree[node << 1] += (mid - b + 1) * lazy[node];
sTree[node << 1 | 1] += (e - mid) * lazy[node];
lazy[node] = 0;
}
long query(int i, int j) {
return query(1, 1, N, i, j);
}
long query(int node, int b, int e, int i, int j) // O(log n)
{
if (i > e || j < b)
return 0;
if (b >= i && e <= j)
return sTree[node];
int mid = b + e >> 1;
propagate(node, b, mid, e);
long q1 = query(node << 1, b, mid, i, j);
long q2 = query(node << 1 | 1, mid + 1, e, i, j);
return q1 + q2;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int N = 1;
while (N < n)
N *= 2;
long[] a = new long[N + 1];
st = new StringTokenizer(br.readLine());
for (int i = 1; i <= n; i++) {
a[i] = Integer.parseInt(st.nextToken());
}
N = 1;
while (N < m)
N *= 2;
triple[] t = new triple[m];
SegmentTree sg = new SegmentTree(a);
long[] a2 = new long[N + 1];
SegmentTree sg2 = new SegmentTree(a2);
for (int i = 0; i < m; i++) {
st = new StringTokenizer(br.readLine());
int l = Integer.parseInt(st.nextToken());
int r = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
t[i] = new triple(l, r, d);
}
// System.out.println(sg.query(1, 2));
for (int i = 0; i < k; i++) {
st = new StringTokenizer(br.readLine());
int l = Integer.parseInt(st.nextToken());
int r = Integer.parseInt(st.nextToken());
sg2.update_range(l, r, 1);
}
// System.out.println(Arrays.toString(sg2.sTree));
for (int i = 0; i < m; i++) {
long x=sg2.query(i+1, i+1);
sg.update_range(t[i].x, t[i].y, t[i].z*1l*x);
}
// System.out.println(Arrays.toString(sg.sTree));
for (int i = 1; i <=n; i++) {
pw.print(sg.query(i, i)+" ");
}
pw.flush();
pw.close();
}
static class triple implements Comparable<triple> {
int x;
int y;
int z;
public triple(int a, int b, int c) {
x = a;
y = b;
z = c;
}
@Override
public int compareTo(triple o) {
// TODO Auto-generated method stub
return y - o.y;
}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 0b6fecb4ac9514693cad3637bc8c192b | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes |
import java.util.Scanner;
/**
*
* @author ASUS
*/
public class GregAndArray {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int m=in.nextInt();
int k=in.nextInt();
long[] temp=new long[n+3];
long[] a=new long[n+3];
for(int i=0;i<n;i++)
{
a[i]=in.nextInt();
}
int[] l=new int[m+3];
int[] r=new int[m+3];
int[] d=new int[m+3];
long[] occ=new long[m+3];
for(int i=1;i<=m;i++)
{
l[i]=in.nextInt();
r[i]=in.nextInt();
d[i]=in.nextInt();
}
for(int i=1;i<=k;i++)
{
int x=in.nextInt();
int y=in.nextInt();
occ[y+1]--;
occ[x]++;
}
for(int i=1;i<=m;i++)
{
occ[i]+=occ[i-1];
temp[l[i]]+=d[i]*occ[i];
temp[r[i]+1]-=d[i]*occ[i];
}
for(int i=1;i<=n;i++)
{
temp[i]+=temp[i-1];
System.out.print(temp[i]+a[i-1]+" ");
}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 6eeb9aff464fd7d86ddb40c41419d299 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.util.*;
import org.omg.CORBA.INTERNAL;
import java.awt.List;
import java.io.*;
import java.lang.*;
import java.lang.reflect.Array;
public class code1
{
public static void main(String[] args)
{
InputReader in = new InputReader(System.in);
PrintWriter pw = new PrintWriter(System.out);
//Code starts..
int n = in.nextInt();
int m = in.nextInt();
int k = in.nextInt();
long[] a = new long[1000007];
for(int i=0; i<n; i++)
a[i] = in.nextLong();
long[] count = new long[1000007];
int[] ll = new int[1000007];
int[] rl = new int[1000007];
long[] d = new long[1000007];
for(int i=0; i<m; i++)
{
int l = in.nextInt()-1;
int r = in.nextInt()-1;
long d2 = in.nextLong();
ll[i] = l;
rl[i] = r;
d[i] = d2;
}
int[] query = new int[1000007];
for(int i=0; i<k; i++)
{
int l = in.nextInt()-1;
int r = in.nextInt()-1;
query[l]++;
query[r+1]--;
}
long[] mul = new long[1000007];
long cnt = 0;
for(int i=0; i<m; i++)
{
cnt += query[i];
mul[i] = cnt;
}
for(int i=0; i<m; i++)
{
count[ll[i]] += (long)d[i] * mul[i];
count[rl[i]+1] -= (long)d[i] * mul[i];
}
long var = 0;
long[] ans = new long[1000007];
for(int i=0; i<n; i++)
{
var += count[i];
ans[i] = a[i] + var;
}
for(int i=0; i<n; i++)
pw.print(ans[i]+" ");
//Code ends....
pw.flush();
pw.close();
}
public static long dis(long x, long y, long x1, long y1)
{
return (long)((long)x-x1)*(long)((long)x-x1) + (long)((long)y-y1)*(long)((long)y-y1);
}
static class InputReader
{
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private 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 String nextLine()
{
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = snext();
} while (!isEndOfLine(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;
}
private boolean isEndOfLine(int c)
{
return c == '\n' || c == '\r' || c == -1;
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
public static long c = 0;
public static long mod = 1000000007;
public static int d;
public static int p;
public static int q;
public static boolean flag;
public static long INF= Long.MAX_VALUE;
public static long fun(int[] a, int[] b, int m,int n) {
long result =0;
for(int i=0; i<m; i++)
for(int j=0; j<m; j++)
{
long[] fib = new long[Math.max(2, n+2)];
fib[1] = a[i];
fib[2] = b[j];
for(int k=3; k<=n; k++)
fib[k] = (fib[k-1]%mod + fib[k-2]%mod)%mod;
result = (result%mod + fib[n]%mod)%mod;
}
return result;
}
public static double slope(pair p1, pair p2)
{
double m = INF;
if((p1.x - p2.x)!=0)
m = (p1.y - p2.y)/(p1.x - p2.x);
return Math.abs(m);
}
public static int count(String[] s, int f)
{
int count = 0;
int n = s[0].length();
if(f==1)
{
for(int i = 0; i<n; i++)
{
for(int j=0; j<n; j++)
{
if(i%2==0)
{
if(j%2==0 && s[i].charAt(j)=='0')
count++;
if(j%2==1 && s[i].charAt(j)=='1')
count++;
}
if(i%2==1)
{
if(j%2==1 && s[i].charAt(j)=='0')
count++;
if(j%2==0 && s[i].charAt(j)=='1')
count++;
}
}
}
}
else
{
count = 0;
for(int i = 0; i<n; i++)
{
for(int j=0; j<n; j++)
{
if(i%2==1)
{
if(j%2==0 && s[i].charAt(j)=='0')
count++;
if(j%2==1 && s[i].charAt(j)=='1')
count++;
}
if(i%2==0)
{
if(j%2==1 && s[i].charAt(j)=='0')
count++;
if(j%2==0 && s[i].charAt(j)=='1')
count++;
}
}
}
}
return count;
}
public static int gcd(int p2, int p22)
{
if (p2 == 0)
return (int) p22;
return gcd(p22%p2, p2);
}
public static int findGCD(int arr[], int n)
{
int result = arr[0];
for (int i=1; i<n; i++)
result = gcd(arr[i], result);
return result;
}
public static void nextGreater(long[] a, int[] ans)
{
Stack<Integer> stk = new Stack<>();
stk.push(0);
for(int i=1; i<a.length; i++)
{
if(!stk.isEmpty())
{
int s = stk.pop();
while(a[s]<a[i])
{
ans[s] = i;
if(!stk.isEmpty())
s = stk.pop();
else
break;
}
if(a[s]>=a[i])
stk.push(s);
}
stk.push(i);
}
return;
}
public static void nextGreaterRev(long[] a, int[] ans)
{
int n = a.length;
int[] pans = new int[n];
Arrays.fill(pans, -1);
long[] arev = new long[n];
for(int i=0; i<n; i++)
arev[i] = a[n-1-i];
Stack<Integer> stk = new Stack<>();
stk.push(0);
for(int i=1; i<n; i++)
{
if(!stk.isEmpty())
{
int s = stk.pop();
while(arev[s]<arev[i])
{
pans[s] = n - i-1;
if(!stk.isEmpty())
s = stk.pop();
else
break;
}
if(arev[s]>=arev[i])
stk.push(s);
}
stk.push(i);
}
//for(int i=0; i<n; i++)
//System.out.print(pans[i]+" ");
for(int i=0; i<n; i++)
ans[i] = pans[n-i-1];
return;
}
public static void nextSmaller(long[] a, int[] ans)
{
Stack<Integer> stk = new Stack<>();
stk.push(0);
for(int i=1; i<a.length; i++)
{
if(!stk.isEmpty())
{
int s = stk.pop();
while(a[s]>a[i])
{
ans[s] = i;
if(!stk.isEmpty())
s = stk.pop();
else
break;
}
if(a[s]<=a[i])
stk.push(s);
}
stk.push(i);
}
return;
}
public static long lcm(int[] numbers) {
long lcm = 1;
int divisor = 2;
while (true) {
int cnt = 0;
boolean divisible = false;
for (int i = 0; i < numbers.length; i++) {
if (numbers[i] == 0) {
return 0;
} else if (numbers[i] < 0) {
numbers[i] = numbers[i] * (-1);
}
if (numbers[i] == 1) {
cnt++;
}
if (numbers[i] % divisor == 0) {
divisible = true;
numbers[i] = numbers[i] / divisor;
}
}
if (divisible) {
lcm = lcm * divisor;
} else {
divisor++;
}
if (cnt == numbers.length) {
return lcm;
}
}
}
public static long fact(long n) {
long factorial = 1;
for(int i = 1; i <= n; i++)
{
factorial *= i;
}
return factorial;
}
public static void factSieve(int[] a, int n) {
for(int i=2; i<=n; i+=2)
a[i] = 2;
for(int i=3; i<=n; i+=2)
{
if(a[i]==0)
{
a[i] = i;
for(int j=i; j*i<=n; j++)
{
a[i*j] = i;
}
}
}
int k = 1000;
while(k!=1)
{
System.out.print(a[k]+" ");
k /= a[k];
}
}
public static int lowerLimit(int[] a, int n) {
int ans = 0;
int ll = 0;
int rl = a.length-1;
// System.out.println(a[rl]+" "+n);
if(a[0]>n)
return 0;
if(a[0]==n)
return 1;
else if(a[rl]<=n)
return rl+1;
while(ll<=rl)
{
int mid = (ll+rl)/2;
if(a[mid]==n)
{
ans = mid + 1;
break;
}
else if(a[mid]>n)
{
rl = mid-1;
}
else
{
ans = mid+1;
ll = mid+1;
}
}
return ans;
}
public static long choose(long total, long choose){
if(total < choose)
return 0;
if(choose == 0 || choose == total)
return 1;
return (choose(total-1,choose-1)+choose(total-1,choose))%mod;
}
public static int[] suffle(int[] a,Random gen)
{
int n = a.length;
for(int i=0;i<n;i++)
{
int ind = gen.nextInt(n-i)+i;
int temp = a[ind];
a[ind] = a[i];
a[i] = temp;
}
return a;
}
public static long[] sort(long[] a)
{
Random gen = new Random();
int n = a.length;
for(int i=0;i<n;i++)
{
int ind = gen.nextInt(n-i)+i;
long temp = a[ind];
a[ind] = a[i];
a[i] = temp;
}
Arrays.sort(a);
return a;
}
public static pair[] sort(pair[] a)
{
Random gen = new Random();
int n = a.length;
for(int i=0;i<n;i++)
{
int ind = gen.nextInt(n-i)+i;
pair temp = a[ind];
a[ind] = a[i];
a[i] = temp;
}
Arrays.sort(a);
return a;
}
public static int[] sort(int[] a)
{
Random gen = new Random();
int n = a.length;
for(int i=0;i<n;i++)
{
int ind = gen.nextInt(n-i)+i;
int temp = a[ind];
a[ind] = a[i];
a[i] = temp;
}
Arrays.sort(a);
return a;
}
public static int floorSearch(int arr[], int low, int high, int x)
{
if (low > high)
return -1;
if (x > arr[high])
return high;
int mid = (low+high)/2;
if (mid > 0 && arr[mid-1] < x && x < arr[mid])
return mid-1;
if (x < arr[mid])
return floorSearch(arr, low, mid-1, x);
return floorSearch(arr, mid+1, high, x);
}
public static void swap(int a, int b){
int temp = a;
a = b;
b = temp;
}
public static ArrayList<Integer> primeFactorization(int n)
{
ArrayList<Integer> a =new ArrayList<Integer>();
for(int i=2;i*i<=n;i++)
{
while(n%i==0)
{
a.add(i);
n/=i;
}
}
if(n!=1)
a.add(n);
return a;
}
public static void sieve(boolean[] isPrime,int n)
{
for(int i=1;i<n;i++)
isPrime[i] = true;
isPrime[0] = false;
isPrime[1] = false;
for(int i=2;i*i<n;i++)
{
if(isPrime[i] == true)
{
for(int j=(2*i);j<n;j+=i)
isPrime[j] = false;
}
}
}
public static int lowerbound(ArrayList<Long> net, long c2) {
int i=Collections.binarySearch(net, c2);
if(i<0)
i = -(i+2);
return i;
}
public static int lowerboundArray(long[] psum, long c2) {
int i=Arrays.binarySearch(psum, c2);
if(i<0)
i = -(i+2);
return i;
}
public static int lowerboundArray(int[] psum, int c2) {
int i=Arrays.binarySearch(psum, c2);
if(i<0)
i = -(i+2);
return i;
}
public static int uperboundArray(long[] psum, long c2) {
int i=Arrays.binarySearch(psum, c2);
if(i<0)
i = -(i+1);
return i;
}
public static int uperbound(ArrayList<Long> net, long c2) {
int i=Collections.binarySearch(net, c2);
if(i<0)
i = -(i+1);
return i;
}
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 void extendedEuclid(int A,int B)
{
if(B==0)
{
d = A;
p = 1 ;
q = 0;
}
else
{
extendedEuclid(B, A%B);
int temp = p;
p = q;
q = temp - (A/B)*q;
}
}
public static long LCM(long a,long b)
{
return (a*b)/GCD(a,b);
}
public static int LCM(int a,int b)
{
return (a*b)/GCD(a,b);
}
public static int binaryExponentiation(int x,int n)
{
int result=1;
while(n>0)
{
if(n % 2 ==1)
result=result * x;
x=x*x;
n=n/2;
}
return result;
}
public static int[] countDer(int n)
{
int der[] = new int[n + 1];
der[0] = 1;
der[1] = 0;
der[2] = 1;
for (int i = 3; i <= n; ++i)
der[i] = (i - 1) * (der[i - 1] + der[i - 2]);
// Return result for n
return der;
}
static long binomialCoeff(int n, int k)
{
long C[][] = new long[n+1][k+1];
int i, j;
// Calculate value of Binomial Coefficient in bottom up manner
for (i = 0; i <= n; i++)
{
for (j = 0; j <= Math.min(i, k); j++)
{
// Base Cases
if (j == 0 || j == i)
C[i][j] = 1;
// Calculate value using previosly stored values
else
C[i][j] = C[i-1][j-1] + C[i-1][j];
}
}
return C[n][k];
}
public static long binaryExponentiation(long x,long n)
{
long result=1;
while(n>0)
{
if(n % 2 ==1)
result=result * x;
x=(x%mod * x%mod)%mod;
n=n/2;
}
return result;
}
public static int modularExponentiation(int x,int n,int M)
{
int result=1;
while(n>0)
{
if(n % 2 ==1)
result=(result * x)%M;
x=(x%M*x%M)%M;
n=n/2;
}
return result;
}
public static long modularExponentiation(long x,long n,long M)
{
long result=1;
while(n>0)
{
if(n % 2 ==1)
result=(result %M* x%M)%M;
x=(x*x)%M;
n=n/2;
}
return result;
}
public static int modInverse(int A,int M)
{
return modularExponentiation(A,M-2,M);
}
public static long modInverse(long A,long M)
{
return modularExponentiation(A,M-2,M);
}
public static boolean checkYear(int year)
{
if (year % 400 == 0)
return true;
if (year % 100 == 0)
return false;
if (year % 4 == 0)
return true;
return false;
}
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;
for (int i=5; i*i<=n; i=i+6)
{
if (n%i == 0 || n%(i+2) == 0)
return false;
}
return true;
}
static class pair implements Comparable<pair>
{
Long x, y;
pair(long x, long y) {
this.x = x;
this.y = y;
}
public int compareTo(pair o) {
int result = x.compareTo(o.x);
if (result == 0)
result = y.compareTo(o.y);
return result;
}
public String toString() {
return x + " " + y;
}
public boolean equals(Object o) {
if (o instanceof pair) {
pair p = (pair) o;
if(p.x-x==0 && p.y-y==0)
return true;
else
return false;
}
return false;
}
public int hashCode() {
return new Long(x).hashCode() * 31 + new Long(y).hashCode();
}
}
static class triplet implements Comparable<triplet>
{
Integer x,y;
Long z;
triplet(Integer l,Integer m,long z)
{
this.x = l;
this.y = m;
this.z = z;
}
public int compareTo(triplet o)
{
int result = x.compareTo(o.x);
if(result==0)
result = y.compareTo(o.y);
if(result==0)
result = z.compareTo(o.z);
return result;
}
public boolean equlas(Object o)
{
if(o instanceof triplet)
{
triplet p = (triplet)o;
return x==p.x && y==p.y && z==p.z;
}
return false;
}
public String toString()
{
return x+" "+y+" "+z;
}
public int hashCode()
{
return new Long(x).hashCode()*31 + new Long(y).hashCode() + new Long(z).hashCode();
}
}
/*static class node implements Comparable<node>
{
Integer x, y, z;
node(int x,int y, int z)
{
this.x=x;
this.y=y;
this.z=z;
}
public int compareTo(pair o) {
int result = x.compareTo(o.x);
if(result==0)
result = y.compareTo(o.y);
if(result==0)
result = z.compareTo(z);
return result;
}
@Override
public int compareTo(node o) {
// TODO Auto-generated method stub
return 0;
}
}
*/
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 73bc15d85ff9b8f0b0a0efe292cb05d8 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution{
static PrintWriter out=new PrintWriter(System.out);
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] temp=br.readLine().trim().split(" ");
int n=Integer.parseInt(temp[0]);
int m=Integer.parseInt(temp[1]);
int k=Integer.parseInt(temp[2]);
long[] arr=new long[n];
temp=br.readLine().trim().split(" ");
for(int i=0;i<n;i++){
arr[i]=Long.parseLong(temp[i]);
}
int[][] operations=new int[m][3];
for(int i=0;i<m;i++){
temp=br.readLine().trim().split(" ");
operations[i][0]=Integer.parseInt(temp[0]);
operations[i][1]=Integer.parseInt(temp[1]);
operations[i][2]=Integer.parseInt(temp[2]);
}
int[] differenceArrayOperations=new int[m+1];
while(k-->0){
temp=br.readLine().trim().split(" ");
int x=Integer.parseInt(temp[0]);
int y=Integer.parseInt(temp[1]);
differenceArrayOperations[x]++;
if(y+1<m+1){
differenceArrayOperations[y+1]--;
}
}
int[] freq=new int[m+1];
for(int i=1;i<=m;i++){
freq[i]=differenceArrayOperations[i]+freq[i-1];
}
long[] differenceArray=new long[n];
for(int i=1;i<=m;i++){
int operationIndex=i-1;
int l=operations[operationIndex][0]-1;
int r=operations[operationIndex][1]-1;
int d=operations[operationIndex][2];
differenceArray[l]+=1L*d*freq[i];
if(r+1<n){
differenceArray[r+1]-=1L*d*freq[i];
}
}
long[] increase=new long[n];
increase[0]=differenceArray[0];
for(int i=1;i<n;i++){
increase[i]=differenceArray[i]+increase[i-1];
}
for(int i=0;i<n;i++){
arr[i]+=increase[i];
}
for(int i=0;i<n;i++){
out.print(arr[i]+" ");
}
out.println();
out.flush();
out.close();
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 2a377d98164d0b4c1c8d246b066ddad9 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class C {
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();
int[] a = new int[n], l = new int[m], r = new int[m];
for(int i = 0; i < n; i++) a[i] = sc.nextInt();
long[] d = new long[m];
for(int i = 0; i < m; i++)
{
l[i] = sc.nextInt();
r[i] = sc.nextInt();
d[i] = sc.nextInt();
}
int N = 1; while(N < m) N <<= 1;
long[] in = new long[N + 1];
SegmentTree st1 = new SegmentTree(in);
for(int i = 0; i < k; i++)
st1.update_range(sc.nextInt(), sc.nextInt(), 1);
N = 1; while(N < n) N <<= 1;
in = new long[N + 1];
for(int i = 1; i <= n; i++) in[i] = a[i-1];
SegmentTree st2 = new SegmentTree(in);
for(int i = 0; i < m; i++)
st2.update_range(l[i], r[i], d[i] * st1.query(i + 1, i + 1));
for(int i = 0; i < n; i++)
out.print(st2.query(i + 1, i + 1) + " ");
out.flush();
out.close();
}
static class SegmentTree {
int N;
long[] array, sTree, lazy;
SegmentTree(long[] in)
{
array = in; N = in.length - 1;
sTree = new long[N<<1];
lazy = new long[N<<1];
build(1,1,N);
}
void build(int node, int b, int e)
{
if(b == e)
sTree[node] = array[b];
else
{
int mid = b + e >> 1;
build(node<<1,b,mid);
build(node<<1|1,mid+1,e);
sTree[node] = sTree[node<<1] + sTree[node<<1|1];
}
}
void update_range(int i, int j, long val)
{
update_range(1,1,N,i,j,val);
}
void update_range(int node, int b, int e, int i, int j, long val)
{
if(i > e || j < b)
return;
if(b >= i && e <= j)
{
sTree[node] += (e-b+1)*val;
lazy[node] += val;
}
else
{
int mid = b + e >> 1;
propagate(node, b, mid, e);
update_range(node<<1,b,mid,i,j,val);
update_range(node<<1|1,mid+1,e,i,j,val);
sTree[node] = sTree[node<<1] + sTree[node<<1|1];
}
}
void propagate(int node, int b, int mid, int e)
{
lazy[node<<1] += lazy[node];
lazy[node<<1|1] += lazy[node];
sTree[node<<1] += (mid-b+1)*lazy[node];
sTree[node<<1|1] += (e-mid)*lazy[node];
lazy[node] = 0;
}
long query(int i, int j)
{
return query(1,1,N,i,j);
}
long query(int node, int b, int e, int i, int j)
{
if(i>e || j <b)
return 0;
if(b>= i && e <= j)
return sTree[node];
int mid = b + e >> 1;
propagate(node, b, mid, e);
long q1 = query(node<<1,b,mid,i,j);
long q2 = query(node<<1|1,mid+1,e,i,j);
return q1 + q2;
}
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream System){br = new BufferedReader(new InputStreamReader(System));}
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 boolean ready() throws IOException{return br.ready();}
public void waitForInput(){for(long i = 0; i < 3e9; i++);}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 907dabadba5494a9ab65a8e0dd8a7b1c | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main{
static class tri{
int l,r,d;
public tri(int l,int r,int d){this.l=l;this.r=r;this.d=d;}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k;
int ar[] = new int[sc.nextInt()+1];
long br[] = new long[ar.length];
tri[] op = new tri[sc.nextInt()+1];
int ps [] = new int[op.length];
k = sc.nextInt();
for(int i =1;i<ar.length;i++) ar[i]=sc.nextInt();
for(int i =1;i<op.length;i++) op[i] = new tri(sc.nextInt(),sc.nextInt(),sc.nextInt());
for(int i =0;i<k;i++){
int f = sc.nextInt();
int s = sc.nextInt();
ps[f]++;
if(s<ps.length-1)
ps[s+1]--;
}
for(int i = 1;i<ps.length;i++) ps[i] = ps[i] + ps[i-1];
for(int i =1;i<op.length;i++){
br[op[i].l] += ((long)op[i].d)*ps[i];
if(op[i].r < br.length-1)
br[op[i].r+1] -= (((long)op[i].d)*ps[i]);
}
for(int i =1;i<br.length;i++)
br[i] = br[i]+br[i-1];
for(int i =1;i<br.length;i++) br[i] += ar[i];
System.out.print(br[1]);
for(int i = 2;i<br.length;i++) System.out.print(" "+br[i]);
System.out.println();
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 81f1bb82520cc76e69f2fd3846030ab8 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.util.*;
import java.io.*;
public class CF196C_segTree{
public static Pair[] seg, qry;
public static void main(String[] args)throws Exception {
InputReader in = new InputReader(System.in);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
Node[] op = new Node[m+1];
seg = new Pair[7*n];
for(int i = 0; i < 7*n; i++) seg[i] = new Pair(0l, 0l);
qry = new Pair[7*m];
for(int i = 0; i < 7*m; i++) qry[i] = new Pair(0l, 0l);
for(int i = 1; i <= n; i++){
long x = in.nextLong();
update(seg, 1, 1, n, i, i, x);
}
for(int i = 1; i <= m; i++){
op[i] = new Node(in.nextInt(), in.nextInt(), in.nextInt());
}
for(int i = 0; i < k; i++){
int x = in.nextInt(), y = in.nextInt();
update(qry, 1, 1, m, x, y, 1);
}
for(int i = 1; i <= m; i++){
long x = query(qry, 1, 1, m, i); //System.err.println(op[i].x+" "+op[i].y+" "+( op[i].d*x));
update(seg, 1, 1, n, op[i].x, op[i].y, op[i].d*x);
}
for(int i = 1; i <= n; i++){
long x = query(seg, 1, 1, n, i);
pw.print(x+" ");
}
pw.println();
pw.close();
}
static void update(Pair [] segTree, int p, int s, int e, int l, int r, long v){
if(s >= l && e <= r){
segTree[p].prop += v;
return;
}
else if( s > r || e < l) return;
int m = (s+e)/2;
update(segTree, 2*p, s, m, l, r, v);
update(segTree, 2*p+1, m+1, e, l, r, v);
}
static void pushDown(Pair[] segTree, int p, int left, int right){
segTree[left].prop += segTree[p].prop;
segTree[right].prop += segTree[p].prop;
segTree[p].prop = 0;
}
static long query(Pair[] segTree, int p, int s, int e, int pos){
if(s == pos && s == e){
segTree[p].sum += segTree[p].prop;
segTree[p].prop = 0;
return segTree[p].sum;
}
if(s > pos || e < pos) return 0;
int mid = (s+e)/2;
pushDown(segTree, p, 2*p, 2*p+1);
return query(segTree, 2*p, s, mid, pos) + query(segTree, 2*p+1, mid+1, e, pos);
}
static class Pair{
public long sum, prop;
public Pair(long s, long p){
sum = s; prop = p;
}
}
static class Node{
public int x, y, d;
public Node(int xx, int yy, int dd){
x = xx; y = yy; d = dd;
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next()throws Exception {
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
return tokenizer.nextToken();
}
public String nextLine()throws Exception {
String line = null;
tokenizer = null;
line = reader.readLine();
return line;
}
public int nextInt()throws Exception {
return Integer.parseInt(next());
}
public double nextDouble() throws Exception{
return Double.parseDouble(next());
}
public long nextLong()throws Exception {
return Long.parseLong(next());
}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | cc8dae032bba351d6457956fc95bfd0d | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.util.*;
import java.io.*;
public class CF196C{
public static long [] qMul, qAdd, oMul, oAdd;
public static int qlen, olen;
public static void main(String[] args)throws Exception {
InputReader in = new InputReader(System.in);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
int n = in.nextInt(),m = in.nextInt(), k = in.nextInt();
olen = m+5;
oMul = new long[olen];
oAdd = new long[olen];
qlen = n+5;
qMul = new long[qlen];
qAdd = new long[qlen];
for(int i = 1; i <= n; i++){
long x = in.nextLong();
update(qMul, qAdd, i, i, x);
}
Node[] op = new Node[m+1];
for(int i = 1; i <= m; i++){
op[i] = new Node(in.nextInt(), in.nextInt(), in.nextInt());
}
for(int i = 0; i < k; i++){
int x = in.nextInt(), y = in.nextInt();
update(oMul, oAdd, x, y, 1l);
}
for(int i = 1; i <= m; i++){
long x = query(oMul, oAdd, i) - query(oMul, oAdd, i-1);
update(qMul, qAdd, op[i].x, op[i].y, op[i].d*x);
}
for(int i = 1; i <= n; i++){
long x = query(qMul, qAdd, i) - query(qMul, qAdd, i-1);
pw.print(x+" ");
}
pw.println();
pw.close();
}
static class Node{
public int x, y, d;
public Node(int xx, int yy, int dd){
x = xx; y = yy; d = dd;
}
}
static void update(long [] dataMul, long [] dataAdd, int left, int right, long by) {
internalUpdate(dataMul, dataAdd, left, by, -by * (long)(left - 1));
internalUpdate(dataMul, dataAdd, right, -by, by * (long)right);
}
static void internalUpdate(long [] dataMul, long [] dataAdd, int at, long mul, long add) {
int len = dataMul.length;
while (at < len) {
dataMul[at] += mul;
dataAdd[at] += add;
at |= (at + 1);
}
}
static long query(long [] dataMul, long [] dataAdd, int at) {
long mul = 0;
long add = 0;
int start = at;
while (at >= 0) {
mul += dataMul[at];
add += dataAdd[at];
at = (at & (at + 1)) - 1;
}
return mul * (long)start + add;
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next()throws Exception {
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
return tokenizer.nextToken();
}
public String nextLine()throws Exception {
String line = null;
tokenizer = null;
line = reader.readLine();
return line;
}
public int nextInt()throws Exception {
return Integer.parseInt(next());
}
public double nextDouble() throws Exception{
return Double.parseDouble(next());
}
public long nextLong()throws Exception {
return Long.parseLong(next());
}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | c38b699d1373e4097c7354affcebf626 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | /* / οΎοΎβ β β β β β β β β β β β γ
/ )\β β β β β β β β β β β β Y
(β β | ( Ν‘Β° ΝΚ Ν‘Β°οΌβ β(β γ
(β οΎβ Y βγ½-γ __οΌ
| _β qγ| γq |/
(β γΌ '_δΊΊ`γΌ οΎ
β |\ οΏ£ _δΊΊ'彑οΎ
β )\β β qβ β /
β β (\β #β /
β /β β β /α½£====================D-
/β β β /β \ \β β \
( (β )β β β β ) ).β )
(β β )β β β β β ( | /
|β /β β β β β β | /
[_] β β β β β [___] */
// Main Code at the Bottom
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
public class Main {
//Fast IO class
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
boolean env=System.getProperty("ONLINE_JUDGE") != null;
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=1000000000+7;
//Euclidean Algorithm
static long gcd(long A,long B){
return (B==0)?A:gcd(B,A%B);
}
//Modular Exponentiation
static long fastExpo(long x,long n){
if(n==0) return 1;
if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;
return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;
}
//Modular Inverse
static long inverse(long x) {
return fastExpo(x,MOD-2);
}
//Prime Number Algorithm
static boolean isPrime(long n){
if(n<=1) return false;
if(n<=3) 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;
}
//Reverse an array
static void reverse(int arr[],int l,int r){
while(l<r) {
int tmp=arr[l];
arr[l++]=arr[r];
arr[r++]=tmp;
}
}
//Print array
static void print1d(int arr[]) {
out.println(Arrays.toString(arr));
}
static void print2d(int arr[][]) {
for(int a[]: arr) out.println(Arrays.toString(a));
}
// Pair
static class pair{
long x,y;
pair(long a,long b){
this.x=a;
this.y=b;
}
public boolean equals(Object obj) {
if(obj == null || obj.getClass()!= this.getClass()) return false;
pair p = (pair) obj;
return (this.x==p.x && this.y==p.y);
}
public int hashCode() {
return Objects.hash(x,y);
}
}
static FastReader sc=new FastReader();
static PrintWriter out=new PrintWriter(System.out);
//Main function(The main code starts from here)
public static void main (String[] args) throws java.lang.Exception {
int test=1;
while(test-->0) {
int n=sc.nextInt(),m=sc.nextInt(),k=sc.nextInt();
long a[]=new long[n],dp[]=new long[m+1],upd[]=new long[n+1];
for(int i=0;i<n;i++) a[i]=sc.nextInt();
long q[][]=new long[m][3];
for(int i=0;i<m;i++) {
q[i][0]=sc.nextInt()-1;
q[i][1]=sc.nextInt()-1;
q[i][2]=sc.nextLong();
}
for(int i=0;i<k;i++) {
int l=sc.nextInt()-1,r=sc.nextInt()-1;
dp[l]++;
dp[r+1]--;
}
for(int i=1;i<=m;i++) dp[i]+=dp[i-1];
for(int i=0;i<m;i++) {
long val=dp[i]*q[i][2];
upd[(int)q[i][0]]+=val;
upd[(int)q[i][1]+1]-=val;
}
for(int i=1;i<=n;i++) upd[i]+=upd[i-1];
for(int i=0;i<n;i++) out.print((a[i]+upd[i])+" ");
}
out.flush();
out.close();
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 91ad15bc67df5c6fddad673451cfcd6f | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Solution7 {
static int c = 0;
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] sa1 = br.readLine().split(" ");
int n = Integer.parseInt(sa1[0]);
int m = Integer.parseInt(sa1[1]);
int k = Integer.parseInt(sa1[2]);
int[] l = new int[m];
int[] r = new int[m];
int[] d = new int[m];
long[] a = new long[n];
String[] sa2 = br.readLine().split(" ");
for(int i=0;i<n;i++)
{
a[i] = Integer.parseInt(sa2[i]);
}
for(int i= 0;i<m;i++)
{
String[] sa = br.readLine().split(" ");
l[i] = Integer.parseInt(sa[0]);
r[i] = Integer.parseInt(sa[1]);
d[i] = Integer.parseInt(sa[2]);
}
long[] q = new long[m+1];
for(int i=0;i<k;i++)
{
String[] sa = br.readLine().split(" ");
int x = Integer.parseInt(sa[0]);
int y = Integer.parseInt(sa[1]);
q[x]++;
if(y+1<=m)
q[y+1]--;
}
for(int j=1;j<m+1;j++)
{
q[j]+=q[j-1];
}
// System.out.println(Arrays.toString(q));
long[] gold = new long[n];
for(int i=0;i<m;i++)
{
gold[l[i]-1] += (d[i]*q[i+1]);
if(r[i]<n)
gold[r[i]] -= (d[i]*q[i+1]);
}
for(int i=1;i<n;i++)
gold[i]+=gold[i-1];
for(int i=0;i<n;i++)
{
a[i]+=gold[i];
}
for(int i=0;i<n;i++)
System.out.print(a[i]+" ");
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 0f2314d7a72abcc64a33fd327e7f870d | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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;
inputClass in = new inputClass(inputStream);
PrintWriter out = new PrintWriter(outputStream);
CGregAndArray solver = new CGregAndArray();
solver.solve(1, in, out);
out.close();
}
static class CGregAndArray {
public void solve(int testNumber, inputClass sc, PrintWriter out) {
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
int[] l = new int[m];
int[] r = new int[m];
int[] d = new int[m];
for (int i = 0; i < m; i++) {
l[i] = sc.nextInt() - 1;
r[i] = sc.nextInt() - 1;
d[i] = sc.nextInt();
}
long[] howmany = new long[m];
for (int i = 0; i < k; i++) {
int x = sc.nextInt() - 1;
int y = sc.nextInt() - 1;
howmany[x]++;
if (y < m - 1)
howmany[y + 1]--;
}
for (int i = 1; i < m; i++) {
howmany[i] += howmany[i - 1];
}
long[] ans = new long[n];
for (int i = 0; i < m; i++) {
ans[l[i]] += d[i] * howmany[i];
if (r[i] < n - 1) {
ans[r[i] + 1] -= d[i] * howmany[i];
}
}
for (int i = 1; i < n; i++) {
ans[i] += ans[i - 1];
}
for (int i = 0; i < n; i++) {
out.print((a[i] + ans[i]) + " ");
}
out.println();
}
}
static class inputClass {
BufferedReader br;
StringTokenizer st;
public inputClass(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
}
public 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());
}
}
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 5067ffe5e953f6152c61f203f9286758 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes |
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
//
OutputStream out = new BufferedOutputStream(System.out);
FastReader sc = new FastReader();
int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();
long[] temp = new long[n + 3];
long[] a = new long[n + 3];
for (int i = 1; i <= n; i++) {
a[i] = sc.nextInt();
}
int[] l = new int[m + 3];
int[] r = new int[m + 3];
int[] d = new int[m + 3];
long[] occ = new long[m + 3];
for (int i = 1; i <= m; i++) {
l[i] = sc.nextInt();
r[i] = sc.nextInt();
d[i] = sc.nextInt();
}
for (int i = 1; i <= k; i++) {
int x = sc.nextInt(), y = sc.nextInt();
occ[y + 1]--;
occ[x]++;
}
for (int i = 1; i <= m; i++) {
occ[i] += occ[i - 1];
temp[l[i]] += d[i] * occ[i];
temp[r[i] + 1] -= d[i] * occ[i];
}
for (int i = 1; i <= n; i++) {
temp[i] += temp[i - 1];
out.write((temp[i] + a[i] + " ").getBytes());
}
out.flush();
}
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) {
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 1aaf6b957248bbef94d83718d71bb5cf | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | /*
* Remember a 7.0 student can know more than a 10.0 student.
* Grades don't determine intelligence, they test obedience.
* I Never Give Up.
*/
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import static java.lang.System.out;
import static java.util.Arrays.*;
import static java.lang.Math.*;
public class ContestMain {
private static Reader in=new Reader();
private static StringBuilder ans=new StringBuilder();
private static long MOD=1000000007;//10^9+7
private static final int N=100000; //10^5
// private static final int LIM=26;
// private static final double PI=3.1415;
// private static ArrayList<Integer> v[]=new ArrayList[N];
// private static int color[]=new int[N]; //For Graph Coloring
// private static boolean mark[]=new boolean[N];
// private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
// private static void dfs(int node){mark[node]=true;for(int x:v[node]){if(!mark[x]){dfs(x,v);}}}
private static long powmod(long x,long n,long m){
if(n==0)return 1;
else if(n%2==0)return(powmod((x*x)%m,n/2,m));
else return (x*(powmod((x*x)%m,(n-1)/2,m)))%m;
}
// private static void shuffle(long [] arr) {
// for (int i = arr.length - 1; i >= 2; i--) {
// int x = new Random().nextInt(i - 1);
// long temp = arr[x];
// arr[x] = arr[i];
// arr[i] = temp;
// }
// }
// private static void swap(int i,int j,int ar[]){
// int temp=ar[i];
// ar[i]=ar[j];
// ar[j]=temp;
// }
// private static long gcd(long a, long b){
// if(b==0)return a;
// return gcd(b,a%b);
// }
public static void main(String[] args) throws IOException{
int n=in.nextInt();
int m=in.nextInt();
int k=in.nextInt();
long q_add[]=new long[m+1];
long q_remove[]=new long[m+1];
long op_add[]=new long[n+1];
long op_remove[]=new long[n+1];
int ar[][]=new int[m+1][4];
long num[]=new long[n+1];
for(int i=1;i<=n;i++)
num[i]=in.nextInt();
for(int i=1;i<=m;i++){
ar[i][1]=in.nextInt();ar[i][2]=in.nextInt();ar[i][3]=in.nextInt();
}
int x,y;
for(int i=1;i<=k;i++){
x=in.nextInt();y=in.nextInt();
q_add[y]+=1;
q_remove[x]+=1;
}
long c=0;
for(int i=m;i>=1;i--){
c+=q_add[i];
op_add[ar[i][2]]+=ar[i][3]*c;
op_remove[ar[i][1]]+=ar[i][3]*c;
c-=q_remove[i];
}
c=0;
// for(int i=1;i<=n;i++)
// out.print(op_add[i]+" ");
for(int i=n;i>=1;i--){
c+=op_add[i];
num[i]+=c;
c-=op_remove[i];
}
for(int i=1;i<=n;i++)
out.print(num[i]+" ");
}
static class Pair<T> implements Comparable<Pair>{
int l;
int r;
Pair(){
l=0;
r=0;
}
Pair(int k,int v,int a){
l=k;
r=v;
}
@Override
public int compareTo(Pair o) {
if(o.l!=l)return (int) (l-o.l);
else return (r-o.r);
}
}
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;
}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | b760832340e5739bc25325d0a230fe4c | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes |
import java.util.*;
import java.io.IOException;
public class Task2 {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
int n = in.nextInt(),m=in.nextInt(),k=in.nextInt();
long [] a= new long[n];
for (int i = 0; i < n; i++) a[i]=in.nextInt();
int [] s= new int[m+1];
int [] l = new int[m],r = new int[m],d = new int[m];
for (int i = 0; i < m; i++) {
l[i]=in.nextInt()-1;
r[i]=in.nextInt()-1;d[i]=in.nextInt();
}
long [] ans= new long[n+1];
for (int i = 0; i < k; i++) {
s[in.nextInt()-1]++;
s[in.nextInt()]--;
}
int t=0;
for (int i = 0; i < s.length-1; i++) {
t+=s[i];
ans[l[i]]+=1L*d[i]*t;
ans[r[i]+1]-=1L*d[i]*t;
}
long h=0;
for (int i = 0; i <a.length; i++) {
h+=ans[i];
System.out.print(a[i]+h+" ");
}
}
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 7d3696b2af8be7fc484b7eaae9ca0f68 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes |
import java.util.*;
import javafx.util.*;
public class Master {
public static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int n = in.nextInt();
int m = in.nextInt();
int k = in.nextInt();
long[] z = new long[n];
for (int i = 0; i < n; i++) {
z[i] = in.nextInt();
}
Operation[] op = new Operation[m];
for (int i = 0; i < m; i++) {
op[i] = new Operation(in.nextInt() - 1, in.nextInt() - 1, in.nextInt());
}
long[] arr = new long[m];
long[] freq = new long[m];
while (k-- > 0) {
int l = in.nextInt() - 1;
int r = in.nextInt() - 1;
arr[l]++;
if (r + 1 < m) {
arr[r + 1]--;
}
}
freq[0] = arr[0];
for (int i = 1; i < arr.length; i++) {
freq[i] = arr[i] + freq[i - 1];
}
for (int i = 0; i < m; i++) {
op[i].d = freq[i] * op[i].d;
}
freq = new long[z.length];
for (Operation o : op) {
int l = o.l;
int r = o.r;
freq[l] += o.d;
if (r + 1 < freq.length) {
freq[r + 1] -= o.d;
}
}
long[] cum = new long[z.length];
cum[0] = freq[0];
for (int i = 1; i < z.length; i++) {
cum[i] = freq[i] + cum[i - 1];
}
for (int i = 0; i < z.length; i++) {
System.out.print((cum[i] + z[i]) + " ");
}
System.out.println("");
}
public static class Operation {
int l = 0;
int r = 0;
long d = 0;
public Operation(int a, int b, long c) {
l = a;
r = b;
d = c;
}
}
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 048baf3e2010d094ebbd04f265a32248 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.math.BigInteger;
import java.util.regex.*;
public class Myclass {
public static void main(String[] args)
{
InputReader in = new InputReader(System.in);
PrintWriter pw = new PrintWriter(System.out);
int n=in.nextInt();
int m=in.nextInt();
int k=in.nextInt();
long a[]=new long[n+1];
pair b[]=new pair[m+1];
long trace[]=new long[m+1];
long add[]=new long [n+1];
for(int i=1;i<=n;i++) {
a[i]=in.nextLong();
}
for(int i=1;i<=m;i++) {
b[i]=new pair(in.nextInt(),in.nextInt(),in.nextInt());
}
for(int i=0;i<k;i++)
{
int x=in.nextInt();
int y=in.nextInt();
trace[x-1]--;
trace[y]++;
}
//pw.println(Arrays.toString(trace));
for(int i=m;i>0;i--)
{
trace[i-1]+=trace[i];
}
//pw.println(Arrays.toString(trace));
for(int i=1;i<=m;i++)
{
pair p=b[i];
add[p.x-1]-=(p.z*trace[i]);
add[p.y]+=(p.z*trace[i]);
}
for(int i=n;i>=1;i--) {
add[i-1]+=add[i];
}
for(int i=1;i<=n;i++)
{
a[i]+=add[i];
pw.print(a[i]+" ");
}
pw.flush();
pw.close();
}
static class InputReader
{
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private 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;
}
static class tri implements Comparable<tri> {
int p, c, l;
tri(int p, int c, int l) {
this.p = p;
this.c = c;
this.l = l;
}
public int compareTo(tri o) {
return Integer.compare(l, o.l);
}
}
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 String nextLine()
{
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = snext();
} while (!isEndOfLine(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;
}
private boolean isEndOfLine(int c)
{
return c == '\n' || c == '\r' || c == -1;
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
public static long mod = 1000000007;
public static int d;
public static int p;
public static int q;
public static int[] suffle(int[] a,Random gen)
{
int n = a.length;
for(int i=0;i<n;i++)
{
int ind = gen.nextInt(n-i)+i;
int temp = a[ind];
a[ind] = a[i];
a[i] = temp;
}
return a;
}
public static void swap(int a, int b){
int temp = a;
a = b;
b = temp;
}
public static HashSet<Integer> primeFactorization(int n)
{
HashSet<Integer> a =new HashSet<Integer>();
for(int i=2;i*i<=n;i++)
{
while(n%i==0)
{
a.add(i);
n/=i;
}
}
if(n!=1)
a.add(n);
return a;
}
public static void sieve(boolean[] isPrime,int n)
{
for(int i=1;i<n;i++)
isPrime[i] = true;
isPrime[0] = false;
isPrime[1] = false;
for(int i=2;i*i<n;i++)
{
if(isPrime[i] == true)
{
for(int j=(2*i);j<n;j+=i)
isPrime[j] = false;
}
}
}
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 void extendedEuclid(int A,int B)
{
if(B==0)
{
d = A;
p = 1 ;
q = 0;
}
else
{
extendedEuclid(B, A%B);
int temp = p;
p = q;
q = temp - (A/B)*q;
}
}
public static long LCM(long a,long b)
{
return (a*b)/GCD(a,b);
}
public static int LCM(int a,int b)
{
return (a*b)/GCD(a,b);
}
public static int binaryExponentiation(int x,int n)
{
int result=1;
while(n>0)
{
if(n % 2 ==1)
result=result * x;
x=x*x;
n=n/2;
}
return result;
}
public static long binaryExponentiation(long x,long n)
{
long result=1;
while(n>0)
{
if(n % 2 ==1)
result=result * x;
x=x*x;
n=n/2;
}
return result;
}
public static int modularExponentiation(int x,int n,int M)
{
int result=1;
while(n>0)
{
if(n % 2 ==1)
result=(result * x)%M;
x=(x*x)%M;
n=n/2;
}
return result;
}
public static long modularExponentiation(long x,long n,long M)
{
long result=1;
while(n>0)
{
if(n % 2 ==1)
result=(result * x)%M;
x=(x*x)%M;
n=n/2;
}
return result;
}
public static long modInverse(int A,int M)
{
return modularExponentiation(A,M-2,M);
}
public static long modInverse(long A,long M)
{
return modularExponentiation(A,M-2,M);
}
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;
for (int i=5; i*i<=n; i=i+6)
{
if (n%i == 0 || n%(i+2) == 0)
return false;
}
return true;
}
public static long[] shuffle(long[] a, Random gen){
for(int i = 0, n = a.length;i < n;i++){
int ind = gen.nextInt(n-i)+i;
long d = a[i];
a[i] = a[ind];
a[ind] = d;
}
return a;
}
static class pair implements Comparable<pair>
{
Integer x;
Integer y;
Integer z;
pair(int a,int m,int n)
{
this.x=a;
this.y=m;
this.z=n;
}
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
public int compareTo(pair o) {
int result = x.compareTo(o.x);
if(result==0)
result = y.compareTo(o.y);
return result;
}
public String toString()
{
return x+" "+y+" "+z;
}
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();
}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 919212f901e9fe7206a5b912b0316acb | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.*;
import java.util.*;
public class d {
public static void main(String args[]) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader sc = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
int n=sc.nextInt(),m=sc.nextInt(),k=sc.nextInt();
int []a = new int[n+1];
Fenwick vals = new Fenwick(n+1);
for(int i =1;i<=n;i++){
a[i]=sc.nextInt();
vals.updateQuery(i,a[i]-a[i-1]);
}
int []l=new int[m+1];
int[]r = new int[m+1];
int []d = new int[m+1];
for(int i =1;i<=m;i++){
l[i]=sc.nextInt();
r[i]=sc.nextInt();
d[i]=sc.nextInt();
}
Fenwick query = new Fenwick(m+1);
for(int i =0;i<k;i++) {
int b=sc.nextInt(),c=sc.nextInt();
query.updateQuery(b,1);
query.updateQuery(c+1,-1);
}
for(int i =1;i<=m;i++) {
vals.updateQuery(l[i], (long)d[i] * query.getSum(i));
vals.updateQuery(r[i]+1, (long)-d[i] * query.getSum(i));
}
for(int i =1;i<=n;i++){
out.print(vals.getSum(i)+ " ");
}
out.close();
}
public static void shuffle(long[] arr) {
int n = arr.length;
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
long tmp = arr[i];
int randomPos = i + rnd.nextInt(n - i);
arr[i] = arr[randomPos];
arr[randomPos] = tmp;
}
}
public static void shuffle(int[] arr) {
int n = arr.length;
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
int tmp = arr[i];
int randomPos = i + rnd.nextInt(n - i);
arr[i] = arr[randomPos];
arr[randomPos] = tmp;
}
}
public static int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.valueOf(next());
}
public double nextDouble() {
return Double.valueOf(next());
}
String nextLine() throws IOException {
return reader.readLine();
}
}
}
class Fenwick{
long []tree;
public Fenwick(int size){
tree = new long[size+1];
}
public void updateQuery(int index,long newVal){
while (index<tree.length){
tree[index]+=newVal;
index=getNext(index);
}
}
public int getNext(int index){
return index+(index&-index);
}
public long getSum(int index){
long sum=0;
while(index>0){
sum+=tree[index];
index=getParent(index);
}
return sum;
}
public int getParent(int index){
return index-(index&-index);
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | a4ef641b4c9432edffa37f7d2a8ee80b | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.*;
import java.util.*;
public class d {
public static void main(String args[]) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader sc = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
int n=sc.nextInt(),m=sc.nextInt(),k=sc.nextInt();
int []a = new int[n+1];
Fenwick vals = new Fenwick(n+1);
for(int i =1;i<=n;i++){
a[i]=sc.nextInt();
vals.updateQuery(i,a[i]-a[i-1]);
}
int []l=new int[m+1];
int[]r = new int[m+1];
int []d = new int[m+1];
for(int i =1;i<=m;i++){
l[i]=sc.nextInt();
r[i]=sc.nextInt();
d[i]=sc.nextInt();
}
Fenwick query = new Fenwick(m+1);
for(int i =0;i<k;i++) {
int b=sc.nextInt(),c=sc.nextInt();
query.updateQuery(b,-1);
query.updateQuery(c+1,1);
}
for(int i =1;i<=m;i++) {
vals.updateQuery(l[i], (long)-d[i] * query.getSum(i));
vals.updateQuery(r[i]+1, (long)d[i] * query.getSum(i));
}
for(int i =1;i<=n;i++){
out.print(vals.getSum(i)+ " ");
}
out.close();
}
public static void shuffle(long[] arr) {
int n = arr.length;
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
long tmp = arr[i];
int randomPos = i + rnd.nextInt(n - i);
arr[i] = arr[randomPos];
arr[randomPos] = tmp;
}
}
public static void shuffle(int[] arr) {
int n = arr.length;
Random rnd = new Random();
for (int i = 0; i < n; ++i) {
int tmp = arr[i];
int randomPos = i + rnd.nextInt(n - i);
arr[i] = arr[randomPos];
arr[randomPos] = tmp;
}
}
public static int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.valueOf(next());
}
public double nextDouble() {
return Double.valueOf(next());
}
String nextLine() throws IOException {
return reader.readLine();
}
}
}
class Fenwick{
long []tree;
public Fenwick(int size){
tree = new long[size+1];
}
public void updateQuery(int index,long newVal){
while (index<tree.length){
tree[index]+=newVal;
index=getNext(index);
}
}
public int getNext(int index){
return index+(index&-index);
}
public long getSum(int index){
long sum=0;
while(index>0){
sum+=tree[index];
index=getParent(index);
}
return sum;
}
public int getParent(int index){
return index-(index&-index);
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 8a19327299d55deb7985e28c108f0899 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import javafx.util.Pair;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
/**
* Created by timur on 28.03.15.
*/
public class TaskC {
boolean eof;
BufferedReader br;
StringTokenizer st;
PrintWriter out;
public static void main(String[] args) throws IOException {
new TaskC().run();
}
public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return "-1";
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
String nextLine() throws IOException {
return br.readLine();
}
void run() throws IOException {
InputStream input = System.in;
PrintStream output = System.out;
try {
File f = new File("a.in");
if (f.exists() && f.canRead()) {
input = new FileInputStream(f);
output = new PrintStream("a.out");
}
} catch (Throwable e) {
}
br = new BufferedReader(new InputStreamReader(input));
out = new PrintWriter(output);
solve();
br.close();
out.close();
}
class Pair implements Comparable<Pair>{
int x, y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Pair pair = (Pair) o;
return x == pair.x &&
y == pair.y;
}
@Override
public int compareTo(Pair o) {
int f = x - o.x;
if (f == 0) {
f = y - o.y;
}
return f;
}
}
static class SegmentTree {
private long[] sum;
private long[] add;
private long[] set;
private boolean[] toSet;
private int[] count;
final int n;
public SegmentTree(int n) {
this.n = Integer.highestOneBit(n) << 1;
sum = new long[this.n << 1];
add = new long[this.n << 1];
set = new long[this.n << 1];
count = new int[this.n << 1];
toSet = new boolean[this.n << 1];
count(0, 0, this.n);
}
private int count(int node, int l, int r) {
if (l == r - 1) {
count[node] = 1;
return 1;
}
int m = (l + r) >> 1;
return count[node] = count((node << 1) | 1, l, m)
+ count((node << 1) + 2, m, r);
}
private void add(int node, long x) {
if (toSet[node]) {
set[node] += x;
} else {
add[node] += x;
}
}
private void set(int node, long x) {
add[node] = 0;
set[node] = x;
toSet[node] = true;
}
private void relax(int node) {
if (!toSet[node] && add[node] == 0) {
return;
}
sum[node] = getSum(node);
if (toSet[node]) {
set((node << 1) | 1, set[node]);
set((node << 1) + 2, set[node]);
toSet[node] = false;
} else {
add((node << 1) | 1, add[node]);
add((node << 1) + 2, add[node]);
add[node] = 0;
}
}
private long getSum(int node) {
return toSet[node] ? set[node] * count(node) : sum[node]
+ add[node] * count(node);
}
private long count(int node) {
return count[node];
}
private void add(int node, int l, int r, int left, int right, long x) {
if (right <= l || r <= left) {
return;
}
if (left <= l && r <= right) {
add(node, x);
return;
}
relax(node);
int m = (l + r) >> 1;
add((node << 1) | 1, l, m, left, right, x);
add((node << 1) + 2, m, r, left, right, x);
sum[node] = getSum((node << 1) | 1) + getSum((node << 1) + 2);
}
private void set(int node, int l, int r, int left, int right, long x) {
if (right <= l || r <= left) {
return;
}
if (left <= l && r <= right) {
set(node, x);
return;
}
relax(node);
int m = (l + r) >> 1;
set((node << 1) | 1, l, m, left, right, x);
set((node << 1) + 2, m, r, left, right, x);
sum[node] = getSum((node << 1) | 1) + getSum((node << 1) + 2);
}
private long getSum(int node, int l, int r, int left, int right) {
if (right <= l || r <= left) {
return 0;
}
if (left <= l && r <= right) {
return getSum(node);
}
relax(node);
int m = (l + r) >> 1;
return getSum((node << 1) | 1, l, m, left, right)
+ getSum((node << 1) + 2, m, r, left, right);
}
public void set(int l, int r, long x) {
if (l >= r) {
return;
}
set(0, 0, n, l, r, x);
}
public void add(int l, int r, long x) {
if (l >= r) {
return;
}
add(0, 0, n, l, r, x);
}
public long getSum(int l, int r) {
if (l >= r) {
return 0;
}
return getSum(0, 0, n, l, r);
}
}
void solve() {
int n = nextInt(), m = nextInt(), k = nextInt();
SegmentTree queries = new SegmentTree(m);
SegmentTree arr = new SegmentTree(n);
for (int i = 0; i < n; i++) {
arr.add(i, i+ 1, nextInt());
}
int[] l = new int[m];
int[] r = new int[m];
long[] d = new long[m];
for (int i = 0; i < m; i++) {
l[i] = nextInt() - 1;
r[i] = nextInt();
d[i] = nextInt();
}
for (int i = 0; i < k; i++) {
int f = nextInt() - 1, s = nextInt();
queries.add(f, s, 1);
}
for (int i = 0; i < m; i++) {
long f = queries.getSum(i, i + 1);
arr.add(l[i], r[i], f * d[i]);
}
for (int i = 0; i < n; i++) {
out.print(arr.getSum(i, i + 1) + " ");
}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 421d90a2416f5aa3949bf0d9b2a4c3b4 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.util.*;
public class c18 {
public static void main(String[] args) {
Scanner scn =new Scanner(System.in);
int n,m,k;
n= scn.nextInt();
m= scn.nextInt();
k= scn.nextInt();
int a[]=new int[n+1];
int i=1;
while(i<=n)
{
a[i++]= scn.nextInt();
}
i=1;
lrd[] lrray= new lrd[m+1];
int l,r,d;
while(i<=m)
{
l= scn.nextInt();
r= scn.nextInt();
d= scn.nextInt();
lrray[i++]=new lrd(l,r,d);
}
long b[]= new long[m+1];
i=0;
int xi,yi;
while(i<k)
{
xi= scn.nextInt();
yi= scn.nextInt();
b[xi-1]++;
// System.out.println("error::"+b[xi]);
// System.out.println("error::"+b[yi]);
b[yi]--;
i++;
}
// System.out.println("rule frequency");
// System.out.println("rule1"+"::"+b[0]);
for(i=1;i<m;i++)
{
b[i]=b[i]+b[i-1];
// System.out.println("rule"+(i+1)+"::"+b[i]);
}
long c[]= new long[n+1];
i=1;
lrd tempo;
for(i=1;i<=m;i++)
{
tempo=lrray[i];
tempo.d*=b[i-1];
// System.out.println("rule::"+i+"\tincrement::"+tempo.d);
c[tempo.l-1]+=tempo.d;
c[tempo.r]-=tempo.d;
}
for(i=1;i<=n;i++)
{
c[i]=c[i]+c[i-1];
// System.out.println("total increment at"+(i)+"::"+c[i]);
}
for(i=1;i<=n;i++)
{
System.out.print(a[i]+c[i-1]+" ");
}
System.out.println();
}
}
class lrd{
public int l,r;
public long d;
public lrd(int a,int b,int c)
{
l=a;
r=b;
d=c;
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 0c223a5f896f063c5bd82bb115ac104a | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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);
PrintWriter out = new PrintWriter(outputStream);
CGregAndArray solver = new CGregAndArray();
solver.solve(1, in, out);
out.close();
}
static class CGregAndArray {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int m = in.nextInt();
int k = in.nextInt();
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
CGregAndArray.Operation[] o = new CGregAndArray.Operation[m];
for (int i = 0; i < m; i++) {
o[i] = new CGregAndArray.Operation(in.nextInt(), in.nextInt(), in.nextInt());
}
long[] operBIT = new long[m + 1];
for (int i = 0; i < k; i++) {
int x = in.nextInt();
int y = in.nextInt();
rangeUpdate(operBIT, x, y, 1);
}
long[] ansBIT = new long[n + 1];
for (int i = 1; i < m + 1; i++) {
long total = o[i - 1].v * query(operBIT, i);
rangeUpdate(ansBIT, o[i - 1].l, o[i - 1].r, total);
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
a[i] += query(ansBIT, i + 1);
sb.append(a[i] + " ");
}
out.println(sb.toString());
}
static long query(long[] bit, int i) {
long sum = 0;
for (; i > 0; i -= i & -i)
sum += bit[i];
return sum;
}
static void update(long[] bit, int i, long delta) {
for (; i < bit.length; i += i & -i)
bit[i] += delta;
}
static void rangeUpdate(long[] bit, int a, int b, long delta) {
update(bit, a, delta);
update(bit, b + 1, -delta);
}
static class Operation {
int l;
int r;
int v;
Operation(int l, int r, int v) {
this.l = l;
this.r = r;
this.v = v;
}
}
}
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());
}
}
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 304a71fadf54b0067e8e20bf54596d1e | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/*
* Author : joney_000[let_me_start]
* Algorithm : Bit / fenwick tree
* Platform : Codeforces
* Ref : https://sanugupta.wordpress.com/2014/08/29/binary-indexed-tree-fenwick-tree/
*/
public class A{
private InputStream inputStream ;
private OutputStream outputStream ;
private FastReader in ;
private PrintWriter out ;
private final int BUFFER = 200005;
private int auxInts[] = new int[BUFFER];
private long auxLongs[] = new long[1];
private double auxDoubles[] = new double[1];
private char auxChars[] = new char[1];
private final long mod = 1000000000+7;
private final int INF = Integer.MAX_VALUE;
private final long INF_L = Long.MAX_VALUE / 10;
public A(){}
public A(boolean stdIO)throws FileNotFoundException{
// stdIO = false;
if(stdIO){
inputStream = System.in;
outputStream = System.out;
}else{
inputStream = new FileInputStream("input.txt");
outputStream = new FileOutputStream("output.txt");
}
in = new FastReader(inputStream);
out = new PrintWriter(outputStream);
}
final int MAX = 200000;
long tree[] = new long[MAX + 5];
void run()throws Exception{
int n = i(); int q = i(); int m = i();
int qry[][] = new int[3][q + 1];// 0=>l, 1=> r
int a[] = new int[n + 1];
for(int i = 1; i <= n; i++){
a[i] = i();
update(tree, i, a[i]);
update(tree, i + 1, -a[i]);
}
for(int i = 1; i <= q; i++){
qry[0][i] = i(); // l
qry[1][i] = i(); // r
qry[2][i] = i(); // value
}
int c[] = new int[q + 2];
for(int i = 1; i <= m; i++){
c[i()] += 1;
c[i() + 1] -= 1;
}
int tot = 0;
for(int i = 1; i <= q; i++){
tot += c[i];
c[i] = tot;
update(tree, qry[0][i], c[i] *1L* qry[2][i]);
update(tree, qry[1][i] + 1, - c[i] *1L* qry[2][i]); // range [l , r]
}
for(int i = 1; i <= n; i++){
long res = qry(tree, i);
out.write(""+res+" ");
}
}// end run
void update(long tree[], int idx, long value){
while(idx < MAX){
tree[idx] += value;
idx += (idx & (-idx));
}
}
long qry(long tree[], int idx){
long ret = 0;
while(idx > 0){
ret += tree[idx];
idx -= (idx & (-idx));
}
return ret;
}
long gcd(long a, long b){
if(b == 0)return a;
return gcd(b, a % b);
}
long lcm(long a, long b){
if(a == 0 || b == 0)return 0;
return (a * b)/gcd(a, b);
}
long mulMod(long a, long b, long mod){
if(a == 0 || b == 0)return 0;
if(b == 1)return a;
long ans = mulMod(a, b/2, mod);
ans = (ans * 2) % mod;
if(b % 2 == 1)ans = (a + ans)% mod;
return ans;
}
long pow(long a, long b, long mod){
if(b == 0)return 1;
if(b == 1)return a;
long ans = pow(a, b/2, mod);
ans = (ans * ans);
if(ans >= mod)ans %= mod;
if(b % 2 == 1)ans = (a * ans);
if(ans >= mod)ans %= mod;
return ans;
}
// 20*20 nCr Pascal Table
long[][] ncrTable(){
long ncr[][] = new long[21][21];
for(int i = 0; i <= 20; i++){
ncr[i][0] = ncr[i][i] = 1L;
}
for(int j = 0; j <= 20; j++){
for(int i = j + 1; i <= 20; i++){
ncr[i][j] = ncr[i-1][j] + ncr[i-1][j-1];
}
}
return ncr;
}
int i()throws Exception{
return in.nextInt();
}
int[] is(int n)throws Exception{
for(int i=1 ; i <= n ;i++)auxInts[i] = in.nextInt();
return auxInts;
}
long l()throws Exception{
return in.nextLong();
}
long[] ls(int n)throws Exception{
for(int i=1 ; i <= n ;i++)auxLongs[i] = in.nextLong();
return auxLongs;
}
double d()throws Exception{
return in.nextDouble();
}
double[] ds(int n)throws Exception{
for(int i=1 ; i <= n ;i++)auxDoubles[i] = in.nextDouble();
return auxDoubles;
}
char c()throws Exception{
return in.nextCharacter();
}
char[] cs(int n)throws Exception{
for(int i=1 ; i <= n ;i++)auxChars[i] = in.nextCharacter();
return auxChars;
}
String s()throws Exception{
return in.nextLine();
}
BigInteger bi()throws Exception{
return in.nextBigInteger();
}
private void closeResources(){
out.flush();
out.close();
return;
}
// IMP: roundoff upto 2 digits
// double roundOff = Math.round(a * 100.0) / 100.0;
// or
// System.out.printf("%.2f", val);
// print upto 2 digits after decimal
// val = ((long)(val * 100.0))/100.0;
public static void main(String[] args) throws java.lang.Exception{
A driver = new A(true);
driver.run();
driver.closeResources();
}
}
class FastReader{
private boolean finished = false;
private InputStream stream;
private byte[] buf = new byte[4 * 1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public FastReader(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==','){
c = read();
}
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{
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 nextLine(){
String s = readLine0 ();
while (s.trim ().length () == 0)
s = readLine0 ();
return s;
}
public String nextLine(boolean ignoreEmptyLines){
if (ignoreEmptyLines){
return nextLine ();
}else{
return readLine0 ();
}
}
public BigInteger nextBigInteger(){
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{
public boolean isSpaceChar(int ch);
}
}
class Pair implements Comparable<Pair>{
public int a;
public int b;
public Pair(){
this.a = 0;
this.b = 0;
}
public Pair(int a,int b){
this.a = a;
this.b = b;
}
public int compareTo(Pair p){
if(this.a == p.a){
return this.b - p.b;
}
return this.a - p.a;
}
@Override
public String toString(){
return "a = " + this.a + " b = " + this.b;
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | d8d490bfd23815b03298a0b8ae0baa81 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/*
* Author : joney_000[let_me_start]
* Algorithm : Bit / fenwick tree
* Platform : Codeforces
* Ref : https://sanugupta.wordpress.com/2014/08/29/binary-indexed-tree-fenwick-tree/
*/
public class A{
private InputStream inputStream ;
private OutputStream outputStream ;
private FastReader in ;
private PrintWriter out ;
private final int BUFFER = 200005;
private int auxInts[] = new int[BUFFER];
private long auxLongs[] = new long[1];
private double auxDoubles[] = new double[1];
private char auxChars[] = new char[1];
private final long mod = 1000000000+7;
private final int INF = Integer.MAX_VALUE;
private final long INF_L = Long.MAX_VALUE / 10;
public A(){}
public A(boolean stdIO)throws FileNotFoundException{
// stdIO = false;
if(stdIO){
inputStream = System.in;
outputStream = System.out;
}else{
inputStream = new FileInputStream("input.txt");
outputStream = new FileOutputStream("output.txt");
}
in = new FastReader(inputStream);
out = new PrintWriter(outputStream);
}
final int MAX = 200000;
long tree[] = new long[MAX + 5];
void run()throws Exception{
int n = i(); int q = i(); int m = i();
int qry[][] = new int[3][q + 1];// 0=>l, 1=> r, 2=>val
int a[] = new int[n + 1];
for(int i = 1; i <= n; i++){
a[i] = i();
update(tree, i, a[i]);
update(tree, i + 1, -a[i]); // point update this time, if range qry than comment this line and res = qry(tree, idx) - qry(tree, idx - 1)
}
for(int i = 1; i <= q; i++){
qry[0][i] = i(); // l
qry[1][i] = i(); // r
qry[2][i] = i(); // value
}
int c[] = new int[q + 2];
for(int i = 1; i <= m; i++){
c[i()] += 1;
c[i() + 1] -= 1;
}
int tot = 0;
for(int i = 1; i <= q; i++){
tot += c[i];
c[i] = tot;
update(tree, qry[0][i], c[i] *1L* qry[2][i]);
update(tree, qry[1][i] + 1, - c[i] *1L* qry[2][i]); // range [l , r]
}
for(int i = 1; i <= n; i++){
long res = qry(tree, i); // in case of point qry
out.write(""+res+" ");
}
}// end run
void update(long tree[], int idx, long value){
while(idx < MAX){
tree[idx] += value;
idx += (idx & (-idx));
}
}
long qry(long tree[], int idx){
long ret = 0;
while(idx > 0){
ret += tree[idx];
idx -= (idx & (-idx));
}
return ret;
}
long gcd(long a, long b){
if(b == 0)return a;
return gcd(b, a % b);
}
long lcm(long a, long b){
if(a == 0 || b == 0)return 0;
return (a * b)/gcd(a, b);
}
long mulMod(long a, long b, long mod){
if(a == 0 || b == 0)return 0;
if(b == 1)return a;
long ans = mulMod(a, b/2, mod);
ans = (ans * 2) % mod;
if(b % 2 == 1)ans = (a + ans)% mod;
return ans;
}
long pow(long a, long b, long mod){
if(b == 0)return 1;
if(b == 1)return a;
long ans = pow(a, b/2, mod);
ans = (ans * ans);
if(ans >= mod)ans %= mod;
if(b % 2 == 1)ans = (a * ans);
if(ans >= mod)ans %= mod;
return ans;
}
// 20*20 nCr Pascal Table
long[][] ncrTable(){
long ncr[][] = new long[21][21];
for(int i = 0; i <= 20; i++){
ncr[i][0] = ncr[i][i] = 1L;
}
for(int j = 0; j <= 20; j++){
for(int i = j + 1; i <= 20; i++){
ncr[i][j] = ncr[i-1][j] + ncr[i-1][j-1];
}
}
return ncr;
}
int i()throws Exception{
return in.nextInt();
}
int[] is(int n)throws Exception{
for(int i=1 ; i <= n ;i++)auxInts[i] = in.nextInt();
return auxInts;
}
long l()throws Exception{
return in.nextLong();
}
long[] ls(int n)throws Exception{
for(int i=1 ; i <= n ;i++)auxLongs[i] = in.nextLong();
return auxLongs;
}
double d()throws Exception{
return in.nextDouble();
}
double[] ds(int n)throws Exception{
for(int i=1 ; i <= n ;i++)auxDoubles[i] = in.nextDouble();
return auxDoubles;
}
char c()throws Exception{
return in.nextCharacter();
}
char[] cs(int n)throws Exception{
for(int i=1 ; i <= n ;i++)auxChars[i] = in.nextCharacter();
return auxChars;
}
String s()throws Exception{
return in.nextLine();
}
BigInteger bi()throws Exception{
return in.nextBigInteger();
}
private void closeResources(){
out.flush();
out.close();
return;
}
// IMP: roundoff upto 2 digits
// double roundOff = Math.round(a * 100.0) / 100.0;
// or
// System.out.printf("%.2f", val);
// print upto 2 digits after decimal
// val = ((long)(val * 100.0))/100.0;
public static void main(String[] args) throws java.lang.Exception{
A driver = new A(true);
driver.run();
driver.closeResources();
}
}
class FastReader{
private boolean finished = false;
private InputStream stream;
private byte[] buf = new byte[4 * 1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public FastReader(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==','){
c = read();
}
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{
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 nextLine(){
String s = readLine0 ();
while (s.trim ().length () == 0)
s = readLine0 ();
return s;
}
public String nextLine(boolean ignoreEmptyLines){
if (ignoreEmptyLines){
return nextLine ();
}else{
return readLine0 ();
}
}
public BigInteger nextBigInteger(){
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{
public boolean isSpaceChar(int ch);
}
}
class Pair implements Comparable<Pair>{
public int a;
public int b;
public Pair(){
this.a = 0;
this.b = 0;
}
public Pair(int a,int b){
this.a = a;
this.b = b;
}
public int compareTo(Pair p){
if(this.a == p.a){
return this.b - p.b;
}
return this.a - p.a;
}
@Override
public String toString(){
return "a = " + this.a + " b = " + this.b;
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | a7e8f3c04e4c381ed11974c02578b8fb | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import static java.lang.Math.*;
public class Main implements Runnable {
public static void main(String[] args) {
new Thread(null, new Main(), "Check2", 1 << 28).start();// to increse stack size in java
}
void init(ArrayList <Integer> adj[], int n){
for(int i=0;i<=n;i++)adj[i]=new ArrayList<>();
}
static long mod = (long) (1e9+7);
public void run() {
InputReader in = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n=in.nextInt();
int m=in.nextInt();
int k=in.nextInt();
long a[]=new long[n+2];
long q[]=new long[m+2];
for(int i=1;i<=n;i++)a[i]=in.nextLong();
box b[]=new box[m+1];
for(int i=1;i<=m;i++){
b[i]=new box(in.nextInt(),in.nextInt(),in.nextLong());
}
for(int i=1;i<=k;i++){
int l=in.nextInt();
int r=in.nextInt();
q[l]++;
q[r+1]--;
}
for(int i=1;i<=m;i++)q[i]+=q[i-1];
long c[]=new long[n+2];
for(int i=1;i<=m;i++){
c[b[i].l]+=(long)q[i]*(b[i].val);
c[b[i].r+1]-=q[i]*(b[i].val);
}
for(int i=1;i<=n;i++){
c[i]+=c[i-1];
}
for(int i=1;i<=n;i++)w.print((a[i]+c[i])+" ");
w.close();
}
class box{
int l,r;
long val;
box(int l,int r,long val){
this.l=l;
this.r=r;
this.val=val;
}
}
class pair {
int a;
long b;
pair(int a,long b){
this.a=a;
this.b=b;
}
public boolean equals(Object obj) { // override equals method for object to remove tem from arraylist and sets etc.......
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
pair other = (pair) obj;
if (b!= other.b||a!=other.a)
return false;
return true;
}
}
static long modinv(long a,long b)
{
long p=power(b,mod-2);
p=a%mod*p%mod;
p%=mod;
return p;
}
static long power(long x,long y){
if(y==0)return 1%mod;
if(y==1)return x%mod;
long res=1;
x=x%mod;
while(y>0){
if((y%2)!=0){
res=(res*x)%mod;
}
y=y/2;
x=(x*x)%mod;
}
return res;
}
static long gcd(long a,long b){
if(b==0)return a;
return gcd(b,a%b);
}
static void sev(int a[],int n){
for(int i=2;i<=n;i++)a[i]=i;
for(int i=2;i<=n;i++){
if(a[i]!=0){
for(int j=2*i;j<=n;){
a[j]=0;
j=j+i;
}
}
}
}
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 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 5bcf6f3c8bd92554c70e81a12316c3a5 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* 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;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
static class TaskC
{
public void solve(int testNumber, Scanner in, PrintWriter out)
{
int T = 1;
while (T-- > 0)
{
solveOne(in, out);
}
}
private void solveOne(Scanner in, PrintWriter out)
{
int N = in.nextInt(), M = in.nextInt(), K = in.nextInt();
long arr[] = CPUtils.readLongArray(N, in);
int[][] operations = new int[M][3];
for (int op = 0; op < M; op++)
{
operations[op] = CPUtils.readIntArray(3, in);
}
long[] tot_operations = new long[M + 1];
while (K-- > 0)
{
int from = in.nextInt() - 1, to = in.nextInt() - 1;
tot_operations[from]++;
tot_operations[to + 1]--;
}
// cascade
for (int i = 1; i < tot_operations.length; i++)
{
tot_operations[i] += tot_operations[i - 1];
}
long[] toSum = new long[N + 1];
for (int i = 0; i < tot_operations.length - 1; i++)
{
long times = tot_operations[i];
if (times > 0)
{
int from = operations[i][0] - 1;
int to = operations[i][1] - 1;
toSum[from] += (times * operations[i][2]);
toSum[to + 1] -= (times * operations[i][2]);
}
}
// cascade
for (int i = 1; i < toSum.length; i++)
{
toSum[i] += toSum[i - 1];
}
for (int i = 0; i < arr.length; i++)
{
arr[i] += toSum[i];
}
CPUtils.printLongArrayNoLastSpace(arr, out, arr.length);
}
}
static class CPUtils
{
public static int[] readIntArray(int size, Scanner in)
{
int[] array = new int[size];
for (int i = 0; i < size; i++)
{
array[i] = in.nextInt();
}
return array;
}
public static long[] readLongArray(int size, Scanner in)
{
long[] array = new long[size];
for (int i = 0; i < size; i++)
{
array[i] = in.nextLong();
}
return array;
}
public static void printLongArrayNoLastSpace(long[] array, PrintWriter out, int pos)
{
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < pos; i++)
{
if (i == pos - 1)
stringBuilder.append(array[i]);
else
stringBuilder.append(array[i] + " ");
}
out.print(stringBuilder.toString());
}
}
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | f11b4774244d536e5c697b24fe60ad32 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.*;
import java.util.*;
public class ZIAX {
static Scanner sc;
static PrintWriter out;
public static void main(String[] args) throws IOException, InterruptedException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
Pair[] b = new Pair[m];
for (int i = 0; i < m; i++) {
b[i] = new Pair(sc.nextInt() - 1, sc.nextInt(), sc.nextInt());
}
int[] t = new int[m + 1];
for (int i = 0; i < k; i++) {
t[sc.nextInt() - 1]++;
t[sc.nextInt()]--;
}
int cnt = 0;
long[] x = new long[n + 1];
for (int i = 0; i < m; i++) {
cnt += t[i];
x[b[i].l] += b[i].d * cnt;
x[b[i].r] -= b[i].d * cnt;
}
long cur = 0;
for (int i = 0; i < n; i++) {
cur += x[i];
out.print(a[i] + cur + " ");
}
out.close();
}
static class Pair{
int l, r;
long d;
Pair(int a, int b, int c){
l = a;
r = b;
d = c;
}
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
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 boolean ready() throws IOException {return br.ready();}
}
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | d8bd78bdcdf63574893a347bc65589c8 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes |
import java.io.*;
import java.util.*;
public class Problems1 {
public static void main(String[] args) throws IOException {
FastScanner sc=new FastScanner(System.in);
int n,m,k;
n=sc.nextInt();
m=sc.nextInt();
k=sc.nextInt();
long a[]=new long[n];//array
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int op[][]=new int[m][3];//operations
for(int i=0;i<m;i++){
op[i][0]=sc.nextInt();
op[i][1]=sc.nextInt();
op[i][2]=sc.nextInt();
}
long uop[]=new long[m+1];//update operations
long ua[]=new long[n+1];//update array
for(int i=0;i<k;i++){
int x=sc.nextInt();
int y=sc.nextInt();
uop[x-1]++;
uop[y]--;
}
long sum=0;
for(int i=0;i<m;i++){
sum=sum+uop[i];
ua[op[i][0]-1]+=op[i][2]*sum;
ua[op[i][1]]-=op[i][2]*sum;
}
sum=0;
for(int i=0;i<n;i++){
sum+=ua[i];
a[i]+=sum;
}
dis(a);
}
public static void dis(long a[]){
for(int i=0;i<a.length;i++){
System.out.print(a[i]+" ");
}
System.out.println("");
}
//__________________________________________________________
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 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 6edf9b785c841fd580a1c244285b059a | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes |
import java.io.*;
import java.util.*;
public class Problems1 {
public static void main(String[] args) throws IOException {
FastScanner sc=new FastScanner(System.in);
int n,m,k;
n=sc.nextInt();
m=sc.nextInt();
k=sc.nextInt();
long a[]=new long[n];//array
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int op[][]=new int[m][3];//operations
for(int i=0;i<m;i++){
op[i][0]=sc.nextInt();
op[i][1]=sc.nextInt();
op[i][2]=sc.nextInt();
}
long uop[]=new long[m+1];//update operations
long ua[]=new long[n+1];//update array
for(int i=0;i<k;i++){
int x=sc.nextInt();
int y=sc.nextInt();
uop[x-1]++;
uop[y]--;
}
long sum=0;
for(int i=0;i<m;i++){
sum=sum+uop[i];
ua[op[i][0]-1]+=op[i][2]*sum;
ua[op[i][1]]-=op[i][2]*sum;
}
sum=0;
for(int i=0;i<n;i++){
sum+=ua[i];
a[i]+=sum;
}
dis(a);
}
public static void dis(long a[]){
StringBuilder s=new StringBuilder();
for(int i=0;i<a.length;i++){
s.append(a[i]+" ");
}
System.out.println(s.toString());
}
//__________________________________________________________
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 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 27ef9d11fb7047314716fc32c52a2583 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.management.MemoryType;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.function.Function;
public class Main {
static final int INF = Integer.MAX_VALUE;
static int mergeSort(int[] a,int [] c, int begin, int end)
{
int inversion=0;
if(begin < end)
{
inversion=0;
int mid = (begin + end) >>1;
inversion+= mergeSort(a,c, begin, mid);
inversion+=mergeSort(a, c,mid + 1, end);
inversion+=merge(a,c, begin, mid, end);
}
return inversion;
}
static int merge(int[] a,int[]c, int b, int mid, int e)
{
int n1 = mid - b + 1;
int n2 = e - mid;
int[] L = new int[n1+1], R = new int[n2+1];
int[] L1 = new int[n1+1], R1 = new int[n2+1];
//inversion
int inversion=0;
for(int i = 0; i < n1; i++) {
L[i] = a[b + i];
L1[i] = c[b + i];
// L2[i] = w[b + i];
}
for(int i = 0; i < n2; i++) {
R[i] = a[mid + 1 + i];
R1[i] = c[mid + 1 + i];
//R2[i] = w[mid + 1 + i];
}
L[n1] = R[n2] = INF;
for(int k = b, i = 0, j = 0; k <= e; k++)
if(L[i] <= R[j]){
a[k] = L[i];
c[k] = L1[i];
++i;
// w[k]=L2[i++];
}
else
{
a[k] = R[j];
c[k] = R1[j];
//w[k] = R2[j++];
++j;
inversion=inversion+(n1-i);
}
return inversion;
}
public static void main (String[]args) throws IOException {
Scanner sc = new Scanner(System.in);
try(PrintWriter or = new PrintWriter(System.out)) {
int n = sc.nextInt();
int m=sc.nextInt();
int k = sc.nextInt();
long [] a = new long[n];
for (int i = 0; i < a.length; i++) {
a[i] = sc.nextInt();
}
int [] l = new int[m];
int [] r = new int[m];
int [] d = new int[m];
int [] occ = new int[m+1];
long [] tmp = new long[n+1];
for (int i = 0; i < m; i++) {
l[i] = sc.nextInt()-1; r[i] = sc.nextInt()-1; d[i] = sc.nextInt();
}
for (int i = 0; i < k; i++) {
int x = sc.nextInt()-1, y = sc.nextInt()-1;
occ[y+1]--;
occ[x]++;
}
int num = 0;
for (int i = 0; i < occ.length-1; i++) {
num += occ[i];
tmp[r[i]+1] -= 1l*d[i]*num;
tmp[l[i]] += 1l*d[i]*num;
}
long nu = 0;
for (int i = 0; i < a.length; i++) {
nu += tmp[i];
or.print(a[i]+nu + " ");
}
}
}
static int getlen(int r,int l,int a){
return (r-l+1+1)/(a+1);
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
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 boolean ready() throws IOException {
return br.ready();
}
}
}
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 first - o.first;
}
}
class Tempo {
int num;
int index;
public Tempo(int num, int index) {
this.num = num;
this.index = index;
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 925b123e63c78f226e275f11e7cc3bfa | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class CF296_D2_C {
public static void main(String[] args) {
FastReader scanner = new FastReader();
int n = scanner.nextInt();
int m = scanner.nextInt();
int k = scanner.nextInt();
long[] arr = nextArray(scanner, n);
Operation[] operations = new Operation[m];
for (int i = 0; i < m; i++) {
operations[i] = new Operation(scanner.nextInt(), scanner.nextInt(), scanner.nextInt());
}
long[] opCount = new long[m + 9];
for (int i = 0; i < k; i++) {
int x = scanner.nextInt();
int y = scanner.nextInt();
opCount[x]++;
opCount[y + 1]--;
}
for (int i = 1; i < m + 1; i++) {
opCount[i] = opCount[i - 1] + opCount[i];
}
long[] sums = new long[n + 9];
for (int i = 0; i < m; i++) {
Operation o = operations[i];
long count = opCount[i + 1];
sums[o.l] += (count * o.d);
sums[o.r + 1] -= (count * o.d);
}
for (int i = 1; i < n + 1; i++) {
sums[i] = sums[i - 1] + sums[i];
}
for (int i = 0; i < n; i++) {
arr[i] += sums[i + 1];
}
printArrayInLine(arr);
}
private static void applyOperation(long[] arr, Operation operation, int count) {
for (int i = operation.l - 1; i < operation.r; i++) {
arr[i] += (operation.d * count);
}
}
public static long[] nextArray(FastReader scanner, int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = scanner.nextLong();
// arr[i] = i;
}
return arr;
}
static class Operation {
int l;
int r;
int d;
public Operation(int l, int r, int d) {
this.l = l;
this.r = r;
this.d = d;
}
}
public static void printArrayInLine(long[] arr) {
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
}
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 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | d9340b68bcf93debe9ada447cf60c879 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class CF296C {
public static void main(String[] args) throws FileNotFoundException {
InputStream inputStream = System.in;
// InputStream inputStream = new FileInputStream(new File("input"));
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
int n, m, k;
Operation[] operations;
class Bit {
long[] tree;
int size;
public Bit(int size) {
this.size = size;
tree = new long[size + 5];
}
void update(int idx, int val) {
update(idx, (long)val);
}
void update(int idx, long val) {
while (idx <= size) {
tree[idx] += val;
idx += idx & -idx;
}
}
long get(int idx) {
long res = 0;
while (idx > 0) {
res += tree[idx];
idx -= idx & -idx;
}
return res;
}
long[] getArr() {
long[] res = new long[size + 1];
for (int i = 1; i <= size; ++i) {
res[i] = get(i);
}
return res;
}
}
public void solve(int testNumber, InputReader in, PrintWriter out) {
n = in.nextInt();
m = in.nextInt();
k = in.nextInt();
int[] a = new int[n + 1];
for (int i = 1; i <= n; ++i) {
a[i] = in.nextInt();
}
operations = new Operation[m + 1];
for (int i = 1; i <= m; ++i) {
operations[i] = new Operation(in.nextInt(), in.nextInt(), in.nextInt());
}
Bit op_tree = new Bit(m);
for (int i = 1; i <= k; ++i) {
int l = in.nextInt();
int r = in.nextInt();
// out.println(l + " " + r);
op_tree.update(l, 1);
op_tree.update(r + 1, -1);
}
long[] after = op_tree.getArr();
Bit val_tree = new Bit(n);
for (int i = 1; i < after.length; ++i) {
long total = operations[i].d * after[i];
val_tree.update(operations[i].l, total);
val_tree.update(operations[i].r + 1, -total);
}
long[] actual = val_tree.getArr();
for (int i = 1; i < actual.length; ++i) {
out.print(actual[i] + a[i] + " " );
}
}
static class Operation {
int l, r, d;
public Operation(int l, int r, int d) {
this.l = l;
this.r = r;
this.d = d;
}
}
}
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());
}
}
} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 712bc9bb904861d30886c59ab84fc4a6 | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import java.util.*;
public class Fhg {
private static Scanner in=new Scanner(System.in);
static LinkedList A;
public static void main(String[] args) {
long a[],b[],c[];
a=new long [100005];
b=new long [100005];
c=new long [100005];
int n=in.nextInt();
int m=in.nextInt();
int k=in.nextInt();
for(int i=1;i<=n;i++){a[i]=in.nextInt();}
long l[],o[],p[];
l=new long [100005];
o=new long [100005];
p=new long [100005];
for(int i=1;i<=m;i++){
l[i]=in.nextInt();
o[i]=in.nextInt();
b[i]=in.nextInt();
}
for(int i=1;i<=k;i++)
{int u=in.nextInt(),y=in.nextInt();
p[u]++;
p[y+1]--;
}
for(int i=1;i<=m;i++){
p[i]+=p[i-1];
c[(int)l[i]]+=p[i]*b[i];
c[(int)o[i]+1]-=p[i]*b[i];
}
for(int i=1;i<=n;i++){
c[i]+=c[i-1];
System.out.print((a[i]+c[i])+" ");
}
}} | Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | c57f750ad8d7d1fa9384bf5c76c50adf | train_004.jsonl | 1365694200 | Greg has an array aβ=βa1,βa2,β...,βan and m operations. Each operation looks as: li, ri, di, (1ββ€βliββ€βriββ€βn). To apply operation i to the array means to increase all array elements with numbers li,βliβ+β1,β...,βri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1ββ€βxiββ€βyiββ€βm). That means that one should apply operations with numbers xi,βxiβ+β1,β...,βyi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg. | 256 megabytes | import org.omg.CORBA.INTERNAL;
import java.util.*;
public class Sol {
static class Node {
int x;
int y;
Long val;
public Node(int x, int y, Long val) {
this.x = x;
this.y = y;
this.val = val;
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int m = input.nextInt();
int k = input.nextInt();
Long[]arr = new Long[n];
for(int i=0 ; i<n ; i++)
arr[i] = input.nextLong();
List<Node> list = new ArrayList<>();
for(int i=0 ; i<m ; i++){
list.add(new Node(input.nextInt(),input.nextInt(),input.nextLong()));
}
int[][] queries = new int[m][2];
int[] simple = new int[m];
while (k-- > 0){
int x = input.nextInt();
int y = input.nextInt();
queries[x-1][0] +=1;
queries[y-1][1] -=1;
}
Long sum = 0L;
for(int i=0 ; i<m ; i++){
sum += queries[i][0];
simple[i] += sum;
sum+= queries[i][1];
}
int[][] ans = new int[n][2];
for(int i=0 ; i< m ; i++){
Node a = list.get(i);
a.val = a.val * simple[i];
list.set(i,a);
}
long[][] upanddpown = new long[n][2];
for(int i=0 ; i<m ; i++){
upanddpown[list.get(i).x-1][0] += list.get(i).val;
upanddpown[list.get(i).y-1][1] -= list.get(i).val;
}
sum = 0L;
for(int i=0 ; i<n ; i++){
sum += upanddpown[i][0];
arr[i] += sum;
sum+= upanddpown[i][1];
}
for(int i=0 ; i<n ; i++)
System.out.print(arr[i] + " ");
}
}
| Java | ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3"] | 1.5 seconds | ["9 18 17", "2", "5 18 31 20"] | null | Java 8 | standard input | [
"dp",
"implementation",
"data structures"
] | c3120f96894c17957bd8acb968bf37cd | The first line contains integers n, m, k (1ββ€βn,βm,βkββ€β105). The second line contains n integers: a1,βa2,β...,βan (0ββ€βaiββ€β105) β the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1ββ€βliββ€βriββ€βn), (0ββ€βdiββ€β105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1ββ€βxiββ€βyiββ€βm). The numbers in the lines are separated by single spaces. | 1,400 | On a single line print n integers a1,βa2,β...,βan β the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | standard output | |
PASSED | 277c965fbf3c29f41bf5f15b8f0fcf52 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt() , m = in.nextInt();
if(n < m) System.out.println(-1);
else{
if(m == 1 && n > 1) System.out.println(-1);
else if(n == 1 && m == 1) System.out.println("a");
else{
char s[] = new char[n];
int i , j;
for(i = n - 1 ; m > 2 ; i-- , m--){
s[i] = (char)( 'a' + m - 1);
}
for(j = 0 ; j < i ; j += 2){
s[j] = 'a' ;
s[j + 1] = 'b';
}
if(j == i) s[j] = 'a';
System.out.println(s);
}
}
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 94afac26c6773efe47aced46e66028bb | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class A {
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter out;
public void solve() throws IOException {
int N = nextInt();
int K = nextInt();
if(N < K ){
out.println("-1"); return;
}
if( N == 1 && K == 1){
out.println('a'); return;
}
if( K == 1 && N > 1 ){
out.println("-1"); return;
}
char prev = 'b';
for(int i = 0; i < N-(K-2); i++){
prev = prev=='b'?'a':'b';
out.print( prev);
}
for(int i = 0; i < (K-2); i++){
out.print( (char)('c'+i) );
}
out.println();
}
/**
* @param args
*/
public static void main(String[] args) {
new A().run();
}
public void run() {
try {
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = null;
out = new PrintWriter(System.out);
solve();
reader.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 772d85e72d34311f2b0f7929e1612549 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | /**
* Created with IntelliJ IDEA.
* User: brzezinsky
* Date: 12/13/12
* Time: 5:43 PM
* To change this template use File | Settings | File Templates.
*/
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class A extends Thread {
public A(String inputFileName, String outputFileName) {
try {
if (inputFileName != null) {
this.input = new BufferedReader(new FileReader(inputFileName));
} else {
this.input = new BufferedReader(new InputStreamReader(System.in));
}
if (outputFileName != null) {
this.output = new PrintWriter(outputFileName);
} else {
this.output = new PrintWriter(System.out);
}
this.setPriority(Thread.MAX_PRIORITY);
} catch (Throwable e) {
System.err.println(e.getMessage());
e.printStackTrace();
System.exit(666);
}
}
private void solve() throws Throwable {
int n = nextInt(), k = nextInt();
if (n < k) {
output.println(-1);
return;
}
if (k == 1) {
if (n > 1) {
output.println(-1);
} else
output.println("a");
return;
}
StringBuilder ans = new StringBuilder();
if ((n + k) % 2 == 0) {
int offset = n - k;
for (int i = 0; i < offset >> 1; ++i) ans.append("ab");
for (int i = 0; i < k; ++i) ans.append((char)('a' + i));
}
else {
int offset = n - k;
for (int i = 0; i < (offset + 1)>> 1; ++i) ans.append("ab");
ans.append("a");
for (int i = 2; i < k; ++i) {
ans.append((char)('a' + i));
}
}
output.println(ans.toString());
}
public void run() {
try {
solve();
} catch (Throwable e) {
System.err.println(e.getMessage());
e.printStackTrace();
System.exit(666);
} finally {
output.close();
}
}
public static void main(String... args) {
new A(null, null).start();
//new A("input.txt", "output.txt").start();
}
private int nextInt() throws IOException {
return Integer.parseInt(next());
}
private double nextDouble() throws IOException {
return Double.parseDouble(next());
}
private long nextLong() throws IOException {
return Long.parseLong(next());
}
private String next() throws IOException {
while (tokens == null || !tokens.hasMoreTokens()) {
tokens = new StringTokenizer(input.readLine());
}
return tokens.nextToken();
}
private StringTokenizer tokens;
private BufferedReader input;
private PrintWriter output;
} | Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 018a33c5959b8806e3a993df6f0d24e6 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.*;
import java.util.*;
public class A implements Runnable {
private void solve() throws IOException {
int n = nextInt(), k = nextInt();
if (k == 1 && n == 1) {
print('a');
return;
}
if (k == 1 || k > n) {
print(-1);
return;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n - k + 2; i++)
if ((i & 1) == 0)
sb.append('a'); else sb.append('b');
for (int i = 2; i < k; i++)
sb.append((char) (i + 'a'));
print(sb.toString());
}
public static void main(String[] args) {
new A().run();
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
public void run() {
try {
reader = new BufferedReader(new InputStreamReader(System.in));
writer = new PrintWriter(System.out);
solve();
writer.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(261);
}
}
void halt() {
writer.close();
System.exit(0);
}
void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
void println(Object... objects) {
print(objects);
writer.println();
}
String nextLine() throws IOException {
return reader.readLine();
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(nextLine());
return tokenizer.nextToken();
}
int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(nextToken());
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 101803a3c28972045c4f21952e6ba564 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
public static void main(String[]args) throws NumberFormatException, IOException {
BufferedReader x=new BufferedReader(new InputStreamReader(System.in));
String s=x.readLine();
String[]a=s.split(" ");
int n= Integer.parseInt(a[0]);
int k=Integer.parseInt(a[1]);
int diff=n-k;
String letters="abcdefghijklmnopqrstuvwxyz";
int d=2;
long f=Math.round((double)diff/2);
if(n==1&k==1)
System.out.println("a");
else if(k==n){
for(int i=0;i<n;i++){
System.out.print(letters.charAt(i));
}
}
else if(k<n){
if(k==1){
System.out.println("-1");return;}
else if(n%2==0&&k%2==0){
f=f+1;
}
else if(n%2!=0&&k%2!=0)
f=f+1;
for(long j=0;j<f;j++){
System.out.print("ab");
}
if(n-f*2>k-2){
System.out.print('a');
}
for(int t=0;t<k-2;t++){
System.out.print(letters.charAt(d));
d++;
}
}
else {
System.out.println("-1");
}
}} | Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 0c239b19c985681a216984cedf6ae867 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class A {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] line = in.readLine().split(" ");
int n = Integer.parseInt(line[0]);
int k = Integer.parseInt(line[1]);
if (k > n || (k == 1 && n > 1)) {
System.out.println(-1);
return;
}
if (n == 1) {
System.out.println("a");
return;
}
if (n == 2) {
System.out.println("ab");
return;
}
char[] res = new char[n];
for (int i=0; i<n-k+2; i++) {
res[i] = (char)(i%2 + 'a');
}
for (int i=2; i<k; i++) {
res[n-k+i] = (char)(i + 'a');
}
System.out.println(new String(res));
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 379dacd753a6c873461736b0d2c0a0e1 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.util.Scanner;
public class PoloThePenguinAndStrings {
public static void main(String[]args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
if(k == 1 && n == 1) {
System.out.println('a');
return;
}
if(k > n || k <= 1) {
System.out.println(-1);
return;
}
for(int i = 0; i < n - (k-2); i++) {
if(i%2 == 0)
System.out.print('a');
else
System.out.print('b');
}
for(int i = 1; i<= k-2; i++) {
System.out.print((char)('b' + i));
}
}
} | Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 92a9ad0b1a1b96bc2e825ffb5d99db28 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
long time = System.nanoTime();
int n = next();
int k = next();
if (k == 1 && n == 1) {
out.println("a");
out.close();
return;
}
if (n > 1 && k == 1) {
out.println(-1);
out.close();
return;
}
if (k > n) {
out.println(-1);
out.close();
return;
}
for (int i = 0; i < n - k + 2; i++) out.print(i % 2 == 0 ? 'a' : 'b');
for (int i = 2; i < k; i++) out.print((char)('a' + i));
out.println();
//System.out.println((System.nanoTime() - time)* 1e-9);
out.close();
}
static PrintWriter out = new PrintWriter(System.out);
static BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer in = new StringTokenizer("");
static String nextToken() throws Exception {
if (!in.hasMoreTokens()) in = new StringTokenizer(bufferedreader.readLine());
return in.nextToken();
}
static int next() throws Exception {return Integer.parseInt(nextToken());};
static int[] next(int n) throws Exception {
int[] x = new int[n];
for (int i = 0; i < n; i++) x[i] = next();
return x;
}
static int[][] next(int n, int m) throws Exception {
int[][] x = new int[n][];
for (int i = 0; i < n; i++) x[i] = next(m);
return x;
}
static long nextl() throws Exception {return Long.parseLong(nextToken());};
static long[] nextl(int n) throws Exception {
long[] x = new long[n];
for (int i = 0; i < n; i++) x[i] = nextl();
return x;
}
static long[][] nextl(int n, int m) throws Exception {
long[][] x = new long[n][];
for (int i = 0; i < n; i++) x[i] = nextl(m);
return x;
}
static double nextd() throws Exception {return Double.parseDouble(nextToken());};
static double[] nextd(int n) throws Exception {
double[] x = new double[n];
for (int i = 0; i < n; i++) x[i] = nextd();
return x;
}
static double[][] nextd(int n, int m) throws Exception {
double[][] x = new double[n][];
for (int i = 0; i < n; i++) x[i] = nextd(m);
return x;
}
static String nextline() throws Exception {
in = new StringTokenizer("");
return bufferedreader.readLine();
}
} | Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | fd088abe0d52f5ec143e85e1fa62d3e5 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Penguin {
public static void main(String args[]) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String s = r.readLine();
String[] inp = s.split(" ");
int n = Integer.parseInt(inp[0]);
int k = Integer.parseInt(inp[1]);
solve(n, k);
}
private static void solve(int n, int k) {
if (k > n || (k==1 && n!=1)) {
System.out.println("-1");
return;
}
int left = getLeftOver(n, k);
boolean flag = false;
for (int i = 0; i < n - left; i++) {
System.out.print((flag ? "b" : "a"));
flag = !flag;
}
for (int i = 0; i < left; i++) {
System.out.print((char)('c' + i));
}
System.out.println();
}
private static int getLeftOver(int n, int k) {
if (k == 1)
return 0;
else
return (k - 2);
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 02de4f4da755833c0e9814e000d33fbf | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Penguin {
public static void main(String args[]) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String s = r.readLine();
String[] inp = s.split(" ");
int n = Integer.parseInt(inp[0]);
int k = Integer.parseInt(inp[1]);
solve(n, k);
}
private static void solve(int n, int k) {
if (k > n || (k==1 && n!=1)) {
System.out.println("-1");
return;
}
int left = getLeftOver(n, k);
boolean flag = false;
for (int i = 0; i < n - left; i++) {
char c = (flag ? 'b' : 'a');
System.out.write(c);
flag = !flag;
}
for (int i = 0; i < left; i++) {
System.out.write((char)('c' + i));
}
System.out.println();
System.out.close();
}
private static int getLeftOver(int n, int k) {
if (k == 1)
return 0;
else
return (k - 2);
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 0e4820822e4061939e9dbafd60fc4ddc | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.util.Scanner;
public class CodeForces {
public static String charset = "abcdefghijklmnopqrstuvwxyz";
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
while (s.hasNext()) {
int n = s.nextInt(), k = s.nextInt();
printString(n, k);
}
}
public static void printString(int n, int k) {
if (k == 1) {
if (n == 1) {
System.out.print(charset.substring(0, 1));
} else {
System.out.print("-1");
}
return ;
}
if (n >= k) {
int i, m = n - k + 2;
for (i = 1; i < m; i += 2) {
System.out.print(charset.substring(0, 2));
}
if (i == m) {
System.out.print(charset.substring(0, 1));
}
if (k >= 3) {
System.out.print(charset.substring(2, k));
}
} else {
System.out.print("-1");
}
}
} | Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | d3d3fd796be015b1e99c4b5cb2cdc680 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.lang.*;
import java.io.*;
public class polo
{
public static void main(String[] args) throws IOException
{
BufferedReader cin=new BufferedReader(new InputStreamReader(System.in));
String s=cin.readLine();
String[] tok=s.split(" ");
int n=Integer.parseInt(tok[0]);
int t=Integer.parseInt(tok[1]);
if(n<t)
System.out.println("-1");
else if(t==1)
{
if(n==1)
System.out.println("a");
else
System.out.println("-1");
}
else
{
for(int i=1;i<=n-(t-2);i++)
{
if(i%2==0)
System.out.print("b");
else
System.out.print("a");
}
char c='c';
for(int i=0;i<t-2;i++)
{
System.out.print(c);
c++;
}
}
}
} | Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 46d78f52679b3c13ac095fb81e47ddc1 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class strings {
static int n, k;
static char alpha[];
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("strings.in"));
StringTokenizer nk = new StringTokenizer(in.readLine());
n = Integer.parseInt(nk.nextToken());
k = Integer.parseInt(nk.nextToken());
alpha = new char[26];
for (int i = 0; i < 26; i++) alpha[i] = (char) (i+97);
if (k > n) {
System.out.println(-1);
return;
}
if (k == 1) {
if (n == 1) System.out.print("a");
else System.out.print(-1);
return;
}
for (int i = 0; i < n-k+2; i++) System.out.print(alpha[i%2]);
for (int i = 0; i < k-2; i++) System.out.print(alpha[(i+2)%26]);
}
} | Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 1f3c87792d70b74c8f92e4cbbd173013 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.util.*;
import java.io.*;
public class j {
public static void main(String[] args) throws Exception
{
Scanner input = new Scanner(System.in);
int n = input.nextInt(), k = input.nextInt();
PrintWriter out = new PrintWriter(System.out);
if(k>n) out.println(-1);
else if(k==1)
{
if(n==1) out.print('a');
else out.println(-1);
}
else
{
int x = n - k+2;
for(int i = 0; i<x/2; i++) out.print("ab");
if(x%2==1) out.print("a");
for(int i = 0; i<k-2; i++) out.print((char)('c'+i));
}
out.close();
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | f8218f2fc0e930004f1c6c1516ed8772 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author DHA
*/
public class JavaApplication4 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
Scanner scan =new Scanner(System.in);
int n=scan.nextInt();
int k=scan.nextInt();
char a=97;
if(n>k)
{
if(k==1)
System.out.println(-1);
else{
for (int j = 0; j < n-(k-2); ) {
System.out.print(a);
j=j+1;
if(j==n-(k-2))
break;
System.out.print((char)(a+1));
j=j+1;
}
for(int j=0;j<(k-2);j++)
System.out.print((char)(a+2+j));}
}
else if(n==k)
{
for(int j=0;j<k;j++)
System.out.print((char)(a+j));
}
else
System.out.println("-1");
// int r,l,sum=0;
// for (int i = 0; i < n; i++) {
// r=scan.nextInt();
// l=scan.nextInt();
// sum+= ((l-r)+1);
// }
//
// int m=0;
// while((sum%k)!=0)
// { m++;
// sum++;
// }
// System.out.println(m);
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//
}}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | b345a080a10f4e4f176ab6a4d6f71292 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class CodeA
{
static class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String nextLine() {
try {
return br.readLine();
} catch (Exception e) {
throw (new RuntimeException());
}
}
public String next() {
while (!st.hasMoreTokens()) {
String l = nextLine();
if (l == null)
return null;
st = new StringTokenizer(l);
}
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 int[] nextIntArray(int n) {
int[] res = new int[n];
for (int i = 0; i < res.length; i++)
res[i] = nextInt();
return res;
}
public long[] nextLongArray(int n) {
long[] res = new long[n];
for (int i = 0; i < res.length; i++)
res[i] = nextLong();
return res;
}
public double[] nextDoubleArray(int n) {
double[] res = new double[n];
for (int i = 0; i < res.length; i++)
res[i] = nextLong();
return res;
}
public void sortIntArray(int[] array) {
Integer[] vals = new Integer[array.length];
for (int i = 0; i < array.length; i++)
vals[i] = array[i];
Arrays.sort(vals);
for (int i = 0; i < array.length; i++)
array[i] = vals[i];
}
public void sortLongArray(long[] array) {
Long[] vals = new Long[array.length];
for (int i = 0; i < array.length; i++)
vals[i] = array[i];
Arrays.sort(vals);
for (int i = 0; i < array.length; i++)
array[i] = vals[i];
}
public void sortDoubleArray(double[] array) {
Double[] vals = new Double[array.length];
for (int i = 0; i < array.length; i++)
vals[i] = array[i];
Arrays.sort(vals);
for (int i = 0; i < array.length; i++)
array[i] = vals[i];
}
}
static String generarBruto(int indice, char anterior, char[] puestas, int k)
{
if(indice == puestas.length)
{
boolean[] distintas = new boolean[26];
for(int i = 0; i < puestas.length; i++)
distintas[puestas[i] - 'a'] = true;
int cuenta = 0;
for(boolean b : distintas)
if(b)
cuenta++;
if(cuenta == k)
return new String(puestas);
else
return null;
}
String mejor = null;
for(char actual = 'a'; actual <= 'z'; actual++)
{
if(actual != anterior)
{
puestas[indice] = actual;
String siguiente = generarBruto(indice + 1, actual, puestas, k);
if(mejor == null)
mejor = siguiente;
if(siguiente != null)
if(mejor.compareTo(siguiente) >= 0)
mejor = siguiente;
}
}
return mejor;
}
static String generar(int n, int k)
{
char[][] dp = new char[n + 2][k + 2];
char[][] siguiente = new char[n + 2][k + 2];
for(int i = 0; i < k; i++)
{
dp[n][i] = 1;
siguiente[n][i] = 0;
}
for(int indice = n - 1; indice >= 1; indice--)
{
for(int anterior = 0; anterior < k; anterior++)
{
boolean ok = false;
for(int i = 0; i < k; i++)
{
if(i != anterior && dp[indice + 1][i] == 1)
{
dp[indice][anterior] = 1;
siguiente[indice][anterior] = (char) i;
ok = true;
break;
}
}
if(!ok)
dp[indice][anterior] = 0;
}
}
for(int i = 0; i < k; i++)
{
if(dp[1][i] == 1)
{
dp[0][0] = 1;
siguiente[0][0] = (char) i;
break;
}
}
StringBuilder sb = new StringBuilder();
int primeraLetra = 0;
if(k > n)
{
return null;
}
if(dp[0][0] == 0)
return null;
else
{
int indiceActual = 0;
int letraActual = primeraLetra;
int letraMayor = letraActual;
for(indiceActual = 1; indiceActual <= n; indiceActual++)
{
letraActual = siguiente[indiceActual - 1][letraActual];
letraMayor = Math.max(letraActual, letraMayor);
sb.append((char) (letraActual + 'a'));
}
if(letraMayor < k - 1)
{
int aPoner = k - letraMayor - 1;
letraActual = letraMayor + 1;
int posicionActual = n - aPoner;
while(posicionActual != n)
{
sb.setCharAt(posicionActual, (char) (letraActual + 'a'));
letraActual++;
posicionActual++;
}
}
return sb.toString();
}
}
public static void main(String[] args)
{
Scanner sc = new Scanner();
int n = sc.nextInt();
int k = sc.nextInt();
String val = generar(n, k);
if(val == null)
System.out.println("-1");
else
System.out.println(val);
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 6ff93965e2b2de9e4322421ccc48ef86 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.util.Scanner;
public class Prob288A {
public static void main(String[] Args) {
Scanner scan = new Scanner(System.in);
int x = scan.nextInt();
int diff = scan.nextInt();
StringBuffer sb = new StringBuffer();
if (x < diff || (x > 1 && diff == 1))
System.out.println(-1);
else if (x == 1 && diff == 1)
System.out.println("a");
else {
int pre = x - diff + 2;
for (int i = 0; i < pre; i++)
sb.append(i % 2 == 0 ? 'a' : 'b');
for (int i = 2; i < diff; i++)
sb.append((char)('a'+i));
System.out.println(sb);
}
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 8a797b6762145a809251d6293de8e9f5 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.util.Scanner;
public class PoloStrings {
private static char[] alphabets = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
private static char[] odd = {'b', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int k = scanner.nextInt();
System.out.println(PoloStrings.getString(n, k));
}
public static String getString(int n, int k) {
int diff = n - k;
if(diff < 0 || (k == 1 && n > 1)) {
return "-1";
}
StringBuffer buffer = new StringBuffer();
int i = 0;
while (diff != 0) {
buffer.append(alphabets[i++ % 2]);
diff--;
}
if (i++ % 2 == 1) {
i = 0;
while(k > 0) {
buffer.append(odd[i++]);
k--;
}
} else {
i = 0;
while(k > 0) {
buffer.append(alphabets[i++]);
k--;
}
}
return buffer.toString();
}
} | Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 3391129f3bb26ec27f43ab04b96245c7 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Throwable {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] ss = br.readLine().split(" +");
int n = Integer.parseInt(ss[0]);
int k = Integer.parseInt(ss[1]);
if (n < k || k == 1 && n > 1)
System.out.println("-1");
else {
char[] ans = new char[n];
int idx = n;
char ch = (char) (96 + k);
while (ch >= 'c')
ans[--idx] = ch--;
for (int i = 0, c = 97; i < idx; i++, c = 195 - c)
ans[i] = (char) c;
System.out.println(ans);
}
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 4b1dc1f99237feb0ffb84930079c63bf | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Codeforces2 implements Runnable {
private BufferedReader br = null;
private PrintWriter pw = null;
private StringTokenizer stk = new StringTokenizer("");
public static void main(String[] args) {
new Thread(new Codeforces2()).run();
}
public void run() { /*
* try { // br = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter("output.txt"); } catch (FileNotFoundException e)
* { e.printStackTrace(); }
*/
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new OutputStreamWriter(System.out));
solver();
pw.close();
}
private void nline() {
try {
if (!stk.hasMoreTokens())
stk = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException("KaVaBUnGO!!!", e);
}
}
private String nstr() {
while (!stk.hasMoreTokens())
nline();
return stk.nextToken();
}
private int ni() {
return Integer.valueOf(nstr());
}
private long nl() {
return Long.valueOf(nstr());
}
private double nd() {
return Double.valueOf(nstr());
}
String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
}
return null;
}
private void solver() {
String alf = "cdefghijklmnopqrstuvwxyz";
int n = ni(), k = ni();
StringBuffer sb = new StringBuffer();
if (n == 1 && k == 1) {
System.out.println("a");
} else if (n < k || k <= 1) {
System.out.println(-1);
} else {
for (int i = 0; i < (n - k + 2); i++) {
if (i % 2 == 0) {
sb.append('a');
} else {
sb.append('b');
}
}
sb.append(alf.substring(0, k - 2));
System.out.println(sb.toString());
}
}
private BigInteger nbi() {
return new BigInteger(nstr());
}
void exit() {
System.exit(0);
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 1a6ee61d6b9050d91cd82fda2a52ba15 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
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);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n=in.nextInt();
int k=in.nextInt();
if(k>n) {
out.println(-1);
return;
}
if(k==1) {
if(n==1) {
out.println("a");
return;
}
else {
out.println(-1);
return;
}
}
if(k==2) {
StringBuilder sb=new StringBuilder(n);
char curChar='a';
for(int i=0;i<n;i++) {
sb.append(curChar);
if(curChar=='a') {
curChar='b';
}
else {
curChar='a';
}
}
}
char lastLetter=(char)('a'+(k-1));
StringBuilder sb=new StringBuilder(n);
sb.setLength(n);
for(int i=0;i<k;i++) {
sb.setCharAt(n-1-i,(char)(lastLetter-i));
}
if((n-k)%2==1) {
//swap n-1-(k-1) and n-1-(k-1)+1
sb.setCharAt(n-1-(k-1),'b');
sb.setCharAt(n-1-(k-1)+1,'a');
}
char curChar='a';
for(int i=0;i<n-k;i++) {
sb.setCharAt(i,curChar);
if(curChar=='a') {
curChar='b';
}
else {
curChar='a';
}
}
out.println(sb.toString());
}
}
class InputReader {
StringTokenizer st;
BufferedReader in;
public InputReader(InputStream ins)
{
in = new BufferedReader(new InputStreamReader(ins));
}
public String nextToken()
{
while(st==null || !st.hasMoreTokens())
{
try {
st=new StringTokenizer(in.readLine());
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
return st.nextToken();
}
public int nextInt()
{
return Integer.parseInt(nextToken());
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | c87df98fe808b9432a7ff228ce24db12 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author Artem_Mikhalevitch
*/
public class Main extends ASolver {
int n;
int k;
public static void main(String[] args) throws ParseException {
Main s = new Main();
s.init();
if (s.readData()) {
s.solve();
s.writeData("" + s.solve());
}
}
@Override
public void init() {
super.init();
}
@Override
public boolean readData() {
try {
n = nextInt();
k = nextInt();
} catch (Exception ex) {
System.out.println(ex.getCause());
System.out.println(ex.getMessage());
return false;
}
return true;
}
public double[] sort(double[] mas1, double[] mas2) {
int l1 = mas1.length;
int l2 = mas2.length;
double[] result = new double[l1 + l2];
int i1 = 0, i2 = 0;
int i = 0;
for (i = 0; i1 < l1 && i2 < l2; i++) {
if (mas1[i1] <= mas2[i2]) {
result[i] = mas1[i1++];
} else {
result[i] = mas2[i2++];
}
}
for (int j = i; i1 < l1; j++) {
result[j] = mas1[i1++];
}
for (int j = i; i2 < l2; j++) {
result[j] = mas2[i2++];
}
return result;
}
public String solve() {
StringBuilder sb = new StringBuilder();
if ((n > 1 && k == 1) || k > n) {
return "-1";
}
if (n == 1) {
sb.append('a');
return sb.toString();
}
int cIndex = 99;
StringBuilder template = new StringBuilder(2);
template.append('a').append('b');
int repeate = (n - k + 2) / 2;
for (int i = 0; i < repeate; i++) {
sb.append(template);
}
if ((n - k + 2) % 2 == 1) {
sb.append('a');
}
for (int i = 0; i < k - 2; i++) {
sb.append((char) (cIndex + i));
}
return sb.toString();
}
}
abstract class ASolver {
protected StringTokenizer tokens;
protected BufferedReader input;
protected PrintWriter output;
public void init() {
input = new BufferedReader(new InputStreamReader(System.in));
}
public abstract boolean readData();
public void writeData(String result) {
System.out.println(result);
}
public void writeData(int result) {
System.out.println(result);
}
public void writeData(long result) {
System.out.println(result);
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String next() throws IOException {
while (tokens == null || !tokens.hasMoreTokens()) {
tokens = new StringTokenizer(input.readLine());
}
return tokens.nextToken();
}
public String nextLine() throws IOException {
while (tokens == null || !tokens.hasMoreTokens()) {
tokens = new StringTokenizer(input.readLine(), "\n");
}
return tokens.nextToken();
}
public long infinityImitator(long a, long b) {
if (a == Long.MIN_VALUE) {
return Long.MIN_VALUE;
} else {
return a + b;
}
}
public int infinityImitator(int a, int b) {
if (a == Integer.MIN_VALUE) {
return Integer.MIN_VALUE;
} else {
return a + b;
}
}
/*
* public long max(long... a) { long result = Long.MIN_VALUE; for (int i =
* 0; i < a.length; i++) { result = Math.max(result, a[i]); } return result;
* }
*/
public int indexMax(int... a) {
int result = 0;
int index = -1;
int length = a.length;
for (int i = 0; i < length; i++) {
if (a[i] > result) {
result = a[i];
index = i;
}
}
return index;
}
public int indexMax(long... a) {
long result = 0;
int index = -1;
int length = a.length;
for (int i = 0; i < length; i++) {
if (a[i] > result) {
result = a[i];
index = i;
}
}
return index;
}
public int max(int... a) {
int result = Integer.MIN_VALUE;
for (int i = 0; i < a.length; i++) {
result = Math.max(result, a[i]);
}
return result;
}
public long max(long... a) {
long result = Integer.MIN_VALUE;
for (int i = 0; i < a.length; i++) {
result = Math.max(result, a[i]);
}
return result;
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 6ff41565621dd78e99b70d1b3b60a2a8 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.util.*;
import java.math.*;
import java.io.*;
public class Main
{
public static void main(String args[]) throws IOException
{
InputReader in=new InputReader(System.in);
int n=in.readInt();
int k=in.readInt();
if(n<k)
{
System.out.println("-1");
return;
}
if(k==1)
{
if(n==1)
System.out.println("a");
else
System.out.println("-1");
return;
}
char A[]=new char[n];
char c=(char)('a'+k-1); //max character
int index=n-1;
for(int iter=1;iter<=k-2;iter++)
{
A[index]=c;
c=(char)(c-1);
index--;
}
if(index!=-1)
{
A[0]='a';
for(int i=1;i<=index;i++)
{
if(A[i-1]=='a')
A[i]='b';
else
A[i]='a';
}
}
StringBuffer ans=new StringBuffer("");
for(int i=0;i<n;i++)
ans=ans.append(A[i]);
PrintWriter out=new PrintWriter(System.out);
out.println(ans.toString());
out.close();
}
}
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 readInt()
{
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 char readCharacter()
{
int c=read();
while (isSpaceChar(c))
c=read();
return (char) c;
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 747bf500f7dde37be544cfec8ae4319a | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class ProblemA {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
int k = in.nextInt();
if (n < k || (k == 1 && n >= 2)) {
out.println(-1);
out.flush();
} else {
StringBuffer b = new StringBuffer();
for (int i = 0 ; i < n ; i++) {
if (i % 2 == 0) {
b.append('a');
} else {
b.append('b');
}
}
char[] cl = b.toString().toCharArray();
int ci = n - 1;
while (k >= 3) {
cl[ci] = (char)('a' + (k - 1));
ci--;
k--;
}
out.println(cl);
}
out.flush();
}
public static void debug(Object... o) {
System.err.println(Arrays.deepToString(o));
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 0e28216383ca4ce7782e7b0b706e30a3 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.*;
public class polo {
public static void main(String[] args)throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String [] line = bf.readLine().split(" ");
int len = Integer.parseInt(line[0]);
int letters = Integer.parseInt(line[1]);
if(letters>len || (letters==1 && len>1)){System.out.println(-1);return;}
if(len==1 && letters == 1){System.out.println("a");return;}
for(int i = 0; i<(len-(letters-2))/2;i++){
System.out.print("ab");
}
String c = "";
switch(letters){
case 3: c = "c";break;
case 4: c = "cd";break;
case 5: c = "cde";break;
case 6: c = "cdef";break;
case 7: c = "cdefg";break;
case 8: c = "cdefgh";break;
case 9: c = "cdefghi";break;
case 10: c = "cdefghij";break;
case 11: c = "cdefghijk";break;
case 12: c = "cdefghijkl";break;
case 13: c = "cdefghijklm";break;
case 14: c = "cdefghijklmo";break;
case 15: c = "cdefghijklmno";break;
case 16: c = "cdefghijklmnop";break;
case 17: c = "cdefghijklmnopq";break;
case 18: c = "cdefghijklmnopqr";break;
case 19: c = "cdefghijklmnopqrs";break;
case 20: c = "cdefghijklmnopqrst";break;
case 21: c = "cdefghijklmnopqrstu";break;
case 22: c = "cdefghijklmnopqrstuv";break;
case 23: c = "cdefghijklmnopqrstuvw";break;
case 24: c = "cdefghijklmnopqrstuvwx";break;
case 25: c = "cdefghijklmnopqrstuvwxy";break;
case 26: c = "cdefghijklmnopqrstuvwxyz";break;
default: break;
}
if((len-letters)%2!=0){System.out.print("a"+c);}
else{System.out.print(c);}
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | eed9bef82f7e079d3277d102bfb3288e | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | //package round177;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class A {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n = ni(), K = ni();
int ued = 0;
char[] ret = new char[n];
outer:
for(int i = 0;i < n;i++){
for(int j = 0;j < K;j++){
if(i > 0 && j+'a' == ret[i-1])continue;
int nued = ued | 1<<j;
if(n-i-1 >= K-Integer.bitCount(nued)){
ued = nued;
ret[i] = (char)('a'+j);
continue outer;
}
}
out.println(-1);
return;
}
out.println(new String(ret));
}
void run() throws Exception
{
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new A().run(); }
private byte[] inbuf = new byte[1024];
private 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))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, 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 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 boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 2379fec870c2b2f1a6a14d6a81ad2b5d | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int k = scan.nextInt();
if(k > n || (k < n && k == 1)) {
System.out.println(-1);
} else {
String[] vals = new String[2];
vals[0] = "a"; vals[1] = "b";
String second = "";
for(byte i = 2; i < k; i++) {
char t = (char) (i + 'a');
second += String.valueOf(t);
}
StringBuffer first = new StringBuffer();
int turn = 0;
for(int i = 0; first.length() + second.length() < n; i++) {
first.append(vals[turn]);
turn = (turn + 1) % 2;
}
System.out.println(first + second);
}
}
} | Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 7bed66ec7e368ca1793f13329d25a8c1 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class A
{
String line;
StringTokenizer inputParser;
BufferedReader is;
FileInputStream fstream;
DataInputStream in;
String FInput="";
void openInput(String file)
{
if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
else
{
try{
fstream = new FileInputStream(file);
in = new DataInputStream(fstream);
is = new BufferedReader(new InputStreamReader(in));
}catch(Exception e)
{
System.err.println(e);
}
}
}
void readNextLine()
{
try {
line = is.readLine();
inputParser = new StringTokenizer(line, " ");
//System.err.println("Input: " + line);
} catch (IOException e) {
System.err.println("Unexpected IO ERROR: " + e);
}
catch (NullPointerException e)
{
line=null;
}
}
int NextInt()
{
String n = inputParser.nextToken();
int val = Integer.parseInt(n);
//System.out.println("I read this number: " + val);
return val;
}
long NextLong()
{
String n = inputParser.nextToken();
long val = Long.parseLong(n);
//System.out.println("I read this number: " + val);
return val;
}
double NextDouble()
{
String n = inputParser.nextToken();
double val = Double.parseDouble(n);
//System.out.println("I read this number: " + val);
return val;
}
String NextString()
{
String n = inputParser.nextToken();
return n;
}
void closeInput()
{
try {
is.close();
} catch (IOException e) {
System.err.println("Unexpected IO ERROR: " + e);
}
}
public static void main(String [] argv)
{
//String filePath="input.txt";
String filePath=null;
if(argv.length>0)filePath=argv[0];
new A(filePath);
}
public void readFInput()
{
for(;;)
{
try
{
readNextLine();
FInput+=line+" ";
}
catch(Exception e)
{
break;
}
}
inputParser = new StringTokenizer(FInput, " ");
}
public A(String inputFile)
{
openInput(inputFile);
readNextLine();
int N=NextInt();
int K=NextInt();
StringBuilder ret = new StringBuilder();
if(K>N||(K==1&&N>1))
{
System.out.print("-1");
return;
}
if(K==1&&N==1)
{
System.out.print("a");
return;
}
for(int i=0; i<=N-K; i+=2)
{
ret.append("ab");
}
if((N-K)%2==1)ret.append("a");
for(int i=2; i<K; i++)
ret.append((char)(i+'a'));
System.out.print(ret);
closeInput();
}
public static void out(Object s)
{
try
{
FileWriter fstream = new FileWriter("output.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write(s.toString());
out.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
} | Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 0671b0e91ac378e66ecf5fd319b563d5 | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes |
import java.util.*;
import java.io.*;
import java.awt.Point;
import java.math.BigInteger;
import static java.lang.Math.*;
// Solution is at the bottom of code
public class _PA implements Runnable{
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
BufferedReader in;
OutputWriter out;
StringTokenizer tok = new StringTokenizer("");
public static void main(String[] args){
new Thread(null, new _PA(), "", 128 * (1L << 20)).start();
}
/////////////////////////////////////////////////////////////////////
void init() throws FileNotFoundException{
Locale.setDefault(Locale.US);
if (ONLINE_JUDGE){
in = new BufferedReader(new InputStreamReader(System.in));
out = new OutputWriter(System.out);
}else{
in = new BufferedReader(new FileReader("input.txt"));
out = new OutputWriter("output.txt");
}
}
// void init() throws FileNotFoundException{
// Locale.setDefault(Locale.US);
//
// if (ONLINE_JUDGE){
//// in = new BufferedReader(new InputStreamReader(System.in));
//// out = new OutputWriter(System.out);
//
// in = new BufferedReader(new FileReader(".in"));
// out = new OutputWriter(".out");
// }else{
// in = new BufferedReader(new FileReader("input.txt"));
// out = new OutputWriter("output.txt");
// }
// }
////////////////////////////////////////////////////////////////
long timeBegin, timeEnd;
void time(){
timeEnd = System.currentTimeMillis();
System.err.println("Time = " + (timeEnd - timeBegin));
}
void debug(Object... objects){
if (ONLINE_JUDGE){
for (Object o: objects){
System.err.println(o.toString());
}
}
}
/////////////////////////////////////////////////////////////////////
public void run(){
try{
timeBegin = System.currentTimeMillis();
Locale.setDefault(Locale.US);
init();
solve();
out.close();
time();
}catch (Exception e){
e.printStackTrace(System.err);
System.exit(-1);
}
}
/////////////////////////////////////////////////////////////////////
String delim = " ";
String readString() throws IOException{
while(!tok.hasMoreTokens()){
try{
tok = new StringTokenizer(in.readLine());
}catch (Exception e){
return null;
}
}
return tok.nextToken(delim);
}
String readLine() throws IOException{
return in.readLine();
}
/////////////////////////////////////////////////////////////////
final char NOT_A_SYMBOL = '\0';
char readChar() throws IOException{
int intValue = in.read();
if (intValue == -1){
return NOT_A_SYMBOL;
}
return (char) intValue;
}
char[] readCharArray() throws IOException{
return readLine().toCharArray();
}
/////////////////////////////////////////////////////////////////
int readInt() throws IOException{
return Integer.parseInt(readString());
}
int[] readIntArray(int size) throws IOException{
int[] array = new int[size];
for (int index = 0; index < size; ++index){
array[index] = readInt();
}
return array;
}
///////////////////////////////////////////////////////////////////
long readLong() throws IOException{
return Long.parseLong(readString());
}
long[] readLongArray(int size) throws IOException{
long[] array = new long[size];
for (int index = 0; index < size; ++index){
array[index] = readLong();
}
return array;
}
////////////////////////////////////////////////////////////////////
double readDouble() throws IOException{
return Double.parseDouble(readString());
}
double[] readDoubleArray(int size) throws IOException{
double[] array = new double[size];
for (int index = 0; index < size; ++index){
array[index] = readDouble();
}
return array;
}
/////////////////////////////////////////////////////////////////////
Point readPoint() throws IOException{
return new Point(readInt(), readInt());
}
Point[] readPointArray(int size) throws IOException{
Point[] array = new Point[size];
for (int index = 0; index < size; ++index){
array[index] = readPoint();
}
return array;
}
/////////////////////////////////////////////////////////////////////
List<Integer>[] readGraph(int vertexNumber, int edgeNumber)
throws IOException{
List<Integer>[] graph = new List[vertexNumber];
for (int index = 0; index < vertexNumber; ++index){
graph[index] = new ArrayList<Integer>();
}
while (edgeNumber-- > 0){
int from = readInt() - 1;
int to = readInt() - 1;
graph[from].add(to);
graph[to].add(from);
}
return graph;
}
/////////////////////////////////////////////////////////////////////
class OutputWriter extends PrintWriter{
final int DEFAULT_PRECISION = 12;
int precision;
String format, formatWithSpace;
{
precision = DEFAULT_PRECISION;
format = createFormat(precision);
formatWithSpace = format + " ";
}
public OutputWriter(OutputStream out) {
super(out);
}
public OutputWriter(String fileName) throws FileNotFoundException {
super(fileName);
}
public int getPrecision() {
return precision;
}
public void setPrecision(int precision) {
this.precision = precision;
format = createFormat(precision);
formatWithSpace = format + " ";
}
private String createFormat(int precision){
return "%." + precision + "f";
}
@Override
public void print(double d){
printf(format, d);
}
public void printWithSpace(double d){
printf(formatWithSpace, d);
}
public void printAll(double...d){
for (int i = 0; i < d.length - 1; ++i){
printWithSpace(d[i]);
}
print(d[d.length - 1]);
}
@Override
public void println(double d){
printlnAll(d);
}
public void printlnAll(double... d){
printAll(d);
println();
}
}
/////////////////////////////////////////////////////////////////////
int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int[][] steps8 = {
{-1, 0}, {1, 0}, {0, -1}, {0, 1},
{-1, -1}, {1, 1}, {1, -1}, {-1, 1}
};
boolean check(int index, int lim){
return (0 <= index && index < lim);
}
/////////////////////////////////////////////////////////////////////
boolean checkBit(int mask, int bitNumber){
return (mask & (1 << bitNumber)) != 0;
}
/////////////////////////////////////////////////////////////////////
void solve() throws IOException{
int n = readInt();
int k = readInt();
if (n < k){
out.println(-1);
return;
}
if (n > 1 && k == 1){
out.println(-1);
return;
}
char[] c = new char[n];
for (int i = k - 1, j = 1; i > 1; --i, ++j){
c[n-j] = (char) ('a' + i);
}
for (int i = 0; i < n; ++i){
if (c[i] >= 'c' && c[i] <= 'z') break;
c[i] = (i % 2 == 0? 'a': 'b');
}
for (int i = 0; i < c.length - 1; ++i){
if (c[i] == c[i+1]){
out.println(-1);
return;
}
}
for (char ch: c){
out.print(ch);
}
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output | |
PASSED | 783d286af9335486d2be617c01c144dd | train_004.jsonl | 1364916600 | Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. No two neighbouring letters of a string coincide; that is, if we represent a string as sβ=βs1s2... sn, then the following inequality holds, siββ βsiβ+β1(1ββ€βiβ<βn). Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String xβ=βx1x2... xp is lexicographically less than string yβ=βy1y2... yq, if either pβ<βq and x1β=βy1,βx2β=βy2,β... ,βxpβ=βyp, or there is such number r (rβ<βp,βrβ<βq), that x1β=βy1,βx2β=βy2,β... ,βxrβ=βyr and xrβ+β1β<βyrβ+β1. The characters of the strings are compared by their ASCII codes. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.Writer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author BSRK Aditya (bsrkaditya@gmail.com)
*/
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);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.readInt();
int k = in.readInt();
if(k == 1) {
if(n == 1) out.printLine("a");
else out.printLine("-1");
} else {
if(n < k) {
out.printLine("-1");
} else {
StringBuilder s = new StringBuilder(n);
boolean isA = true;
for(int i = 0; i < n-k+2; i++, isA = !isA)
if(isA) s.append('a');
else s.append('b');
for(int i = 0; i < k-2; ++i)
s.append((char)('c'+i));
out.printLine(s.toString());
}
}
}
}
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 readInt() {
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 interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
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();
}
}
| Java | ["7 4", "4 7"] | 2 seconds | ["ababacd", "-1"] | null | Java 6 | standard input | [
"greedy"
] | 2f659be28674a81f58f5c587b6a0f465 | A single line contains two positive integers n and k (1ββ€βnββ€β106,β1ββ€βkββ€β26) β the string's length and the number of distinct letters. | 1,300 | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.