Автор BledDest, история, 9 лет назад, перевод, По-русски

Привет, Codeforces!

21 сентября в 18:05 по Москве начнётся Educational Codeforces Round 29.

Продолжается серия образовательных раундов в рамках инициативы Harbour.Space University! Подробности о сотрудничестве Harbour.Space University и Codeforces можно прочитать в посте.

Раунд будет нерейтинговый. Соревнование будет проводиться по немного расширенным правилам ACM ICPC. После окончания раунда будет период времени длительностью в один день, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.

Вам будет предложено 7 задач на 2 часа. Мы надеемся, что вам они покажутся интересными.

Задачи вместе со мной готовили Михаил awoo Пикляев, Владимир vovuh Петров и Михаил MikeMirzayanov Мирзаянов.

Удачи в раунде! Успешных решений!

  • Проголосовать: нравится
  • +172
  • Проголосовать: не нравится

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

For a joke, How to solve the terrible problem A?

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +167 Проголосовать: не нравится

uwi be like :

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

Another ROUND!!!!where u can relax about Rating.The more u dont want to care about ratings the more u start to care....Why rating is so cruel!!!!!!!!!!!

»
9 лет назад, скрыть # |
 
Проголосовать: нравится -20 Проголосовать: не нравится

Is it rated?

»
9 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +69 Проголосовать: не нравится

This question is for uwi and halyavin.

Just out of curiosity, hacking solutions is a way to learn something new or you guys just pass your free time by hacking hundreds of solutions in Educational rounds ?

»
9 лет назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

I need to check the rules of ACM-ICPC. Can anybody send the link?

»
9 лет назад, скрыть # |
 
Проголосовать: нравится -10 Проголосовать: не нравится

i hope someday , somebody write a contest about DOTA 2 it would be so nice :D

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +60 Проголосовать: не нравится

Getting Hired.. uwi mode

»
9 лет назад, скрыть # |
 
Проголосовать: нравится -26 Проголосовать: не нравится

When is this and is it rated?

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

Hi , This will be my first Codeforces contest !

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +22 Проголосовать: не нравится

The days are gone forever when our enemies could blackmail us with nuclear bombs.

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Time to BOMB test case #3 of Problem B

»
9 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +3 Проголосовать: не нравится

Test 14 in E?

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

What is test 14 in E?

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve E? (and why i'm getting RTE with a simple segtree?)

  • »
    »
    9 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +6 Проголосовать: не нравится

    the seg tree dimenison is too little,it should be 4*2*MAXN

    • »
      »
      »
      9 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +3 Проголосовать: не нравится

      Oh, i see, thank you :)

    • »
      »
      »
      9 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      I tried to solve it using segment tree with range sum updates and range min query first i do coordinate compression and then i will update from 1 to n all queries with +1 to their corresponding range and then i will start from 1 to n and at an i th position i will remove that update by adding -1 to that range and check if in that range iam getting any 0 if NO THEN that is a valid ans as it is not affecting others's //(using range min query ) but the problem is i was unable to implement it in time .and also can't we implement a segment tree with range sum updates and range min queries??

      • »
        »
        »
        »
        9 лет назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        You don't need range min queries. What you need to know — is there any element on range equal to 1. Just access each element of your tree and build an array of prefix sums with amount of 1's on prefix, like this: prefixSum[i] = prefixSum[i-1] + (tree.get(i)==1). Then some segment [l; r] is an answer if prefixSum[r] - prefixSum[l-1] == 0

        • »
          »
          »
          »
          »
          9 лет назад, скрыть # ^ |
          ← Rev. 2  
          Проголосовать: нравится 0 Проголосовать: не нравится

          tnx , cool idea to solve that question(we don't even need a segment tree we can use partial sum trick ) . btw i have a doubt in general not regarding this question but can we code a segment tree with lazy propagation such that we can do range sum updates (i.e we can add a value v from l to r ) and we can do range min queries (i.e we can find minimum in that range from l to r ) in logN time .

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I tried to solve D using treap, I think it is an overkill but it should work! I got RE on test 10 and 11 ... it's weird

  • »
    »
    9 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +14 Проголосовать: не нравится

    I'm not sure, but it might be because you put the priorities as rand () (up to 32000 on CF compiler). If you extended the set of possible values, the possibility of two priorities being equal on adjacent positions (which most treap implementations consider 0) would dramatically decrease. I use treaps with rotations and in that implementation in function erase, if you have two neighboring nodes having the same priority and do not pay special attention to the case, you might end up with a loop. Let alone that such small values cut off the idea of normal distribution, so even if you hadn't gotten RE, you would've gotten TLE. Try to switch that line of the code with something like p = (rand () << 15) + rand ().

  • »
    »
    9 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    Actually, I did the same overkill :)

  • »
    »
    9 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    How can you reverse the segment using treap?

    • »
      »
      »
      9 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +13 Проголосовать: не нравится

      Each node should contain a bit which indicates whether you need to flip it or not. To flip a segment, split the treap into three parts (propagating the flips as needed), change the flip bit on the middle part, and then merge the parts.

    • »
      »
      »
      9 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +58 Проголосовать: не нравится

      Another approach is to build two treaps. One for the initial array and another for the reversed array. If you have to reverse a segment you swap the corresponding segments in these treaps.

»
9 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

very interesting problemset.

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +20 Проголосовать: не нравится

I laughed so hard when I saw SPFA_THE_BEST_ALGORITHM's nickname, knowing it is part of the solution to problem F :D

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Simple solution to problem E, no data structures needed (other than array) 30592259

PS: I hope nobody hacks it !

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Is there solution for D easier than treap solution?

»
9 лет назад, скрыть # |
 
Проголосовать: нравится -26 Проголосовать: не нравится

Hi guys, I did join this website yesterday. and I am really happy for this. Few minutes ago I did submit my attempt to solve the problem A but I see runtime error on test1.

I am quasi sure that my solution is working well. I did use java. should I stop using things like demanding the user to enter an input "java.util.Scanner" ? please help me!

The solution is bellow :

package javaapplication7;
import java.util.Scanner;
public class JavaApplication7 {
    public static void main(String[] args) {
        //Reading user's number and adding leading zeros 
        Scanner s = new Scanner(System.in);
        System.out.println("Enter the number please");
        Long in = s.nextLong();
        String in_to_str = in+"";
                
        int in_last_index = in_to_str.length()-1;
        String sub_str_to_add = "";
        while(in_to_str.charAt(in_last_index)=='0'){
            sub_str_to_add=sub_str_to_add+"0";
            in_last_index--;
        }
        in_to_str = sub_str_to_add + in_to_str;
       
        //testing whether it's a palindromic or NOT
        int in_len = in_to_str.length();
        int ind_diff=-1;
        for (int start=0,end=in_len-1;start<in_len/2&&end>in_len/2;end--,start++){
            if(in_to_str.charAt(start)!=in_to_str.charAt(end))
            {
                ind_diff = start;
                break; 
            }       
        }
           
        /* the second part of the if condition [in_len==2&&in_to_str.charAt(0)!=in_to_str.charAt(1)] 
        is to treat the case of a number composed of two digits which is not included in the previous test */
        if(ind_diff<in_len/2&&ind_diff!=-1||in_len==2&&in_to_str.charAt(0)!=in_to_str.charAt(1))
        System.out.println("The number "+in+" is NOT quasi-palindromic");
        else 
        System.out.println("The number "+in+" is quasi-palindromic");            
    }   
}

»
9 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

how should i approach problem E? Thank you.

  • »
    »
    9 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +8 Проголосовать: не нравится

    Create a map m which will compress the indices. The interval [l, r] will be transformed to m[l], m[r + 1] - 1. Now either

    • Use a lazy segment tree to add to a range and query the minimum along a range. A TV is redundant iff the minimum number of TV's at any integer point in time from l to r inclusive is greater than 1. This works well if you already have a template prepared. :)
    • Create a cumulative sum table, which will allow you to determine all points in time where exactly 1 TV is working. Now for each TV you can query if any of these points are inside [l, r] with a set. If none of them are inside, then this TV is redundant.
»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hey! I am new to codeforces. Can anyone guide me ?

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +36 Проголосовать: не нравится

Because hacking others' solutions is too mainstream.

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve the problem D?I have no idea on data structure,could someone give me a little help?

  • »
    »
    9 лет назад, скрыть # ^ |
    ← Rev. 2  
    Проголосовать: нравится +23 Проголосовать: не нравится

    Consider the number of queries is smaller in 100, we can calculate for every single query for the operations but not the whole sequence. As we are given the ending position of the number, we can calculate it's beginning position. For the operations,we can consider it in reverse order.

    Let's call the position of the query is now x,and consider the operation done before it become x.

    First. the operation reversed [l,r],then if the x is in [l,r] it should be l+r-x before this operation.

    Second. the operation shift [l,r] ,then if x is in [l,r] it should be x-1 before this operation. but if it's l exactly it should have been r.

    So you can solve the problem in O(nq).

    Sorry for my poor English, if it's still not clear, you can ask again.

    • »
      »
      »
      9 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      @pb0207, can you give me explanation sample test case for problem D?Problem statement aren't clear to me.Specially first operation isn't clear to me.

      • »
        »
        »
        »
        9 лет назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        The first operation is a cylic shift which is that all the numbers in the interval [l,r] goes right except the number on the position r which goes to l.

        That means for the array [1,3,2,4,5,6,7,9,8] if we do the first operation to the interval [2,5] , it would be [1,5,3,2,4,6,7,9,8]

        The second operation means to reverse the interval.Which means if you do this operation to the interval,then you can find the previous interval by reading from right to left. And for more formal explanation the number on position l would be equal to number on r,and l+1 equal to r-1 ,etc.

        And for the array [1,3,2,4,5,6,7,9,8],if we do the second operation to the interval [3,7] , it would be [1,3,9,7,6,5,4,2,8]

    • »
      »
      »
      9 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +3 Проголосовать: не нравится

      This helps a lot thanks!

      I was confused with this problem but now i get it! :')

  • »
    »
    9 лет назад, скрыть # ^ |
    ← Rev. 2  
    Проголосовать: нравится +4 Проголосовать: не нравится

    As for data structure, you can learn Treap or Splay which can reverse the array.And you can calcultate the final array in O(logn) for each operation.

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For problem B, can any body explain why this approach is wrong:

iterate over all pair and find the pair with minimal absolute difference between weights, then delete them and repeat the process.

This gives a WA, any proof why it's wrong.

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

When will be editorial published?

»
9 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

For problem E,why segment tree is not able to solve this problem?(I have change the array a for discretization) but I got WA on test 14.

The main idea I do is to add 1 in segment[l,r] and query the minimum value in this segment after all the add operations are done.Then if there is a segment whose minimum value can be greater or equal to 2 ,then this TV set is not needed.

It's that my fault in writing segment tree?But I'm so sure I could at least write a segment tree correctly...This is code...Please tell me what's wrong or just point out the solution itself is not correct...Thanks in advance...

  • »
    »
    9 лет назад, скрыть # ^ |
    ← Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    i too taught segment tree. but seeing values of array, i solved it in another way. i used binary search. 30619432

    • »
      »
      »
      9 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Thank you for reply...But is there any monotonicity for binary search in this problem?I just think it's asking about whether there has a segment which have been covered by other segments completely...

      • »
        »
        »
        »
        9 лет назад, скрыть # ^ |
        ← Rev. 3  
        Проголосовать: нравится +1 Проголосовать: не нравится

        Yes and you can search that segment using Binary search by doing some preoprocessing. let me explain it.

        example:

        3

        1 2

        2 3

        3 4

        lets sort this segments by l and if same then by r.

        array = (1, 2) (2, 3), (3, 4)

        now we will create new vector where we will store working time of tv's based on previous tv.

        for example : (1, 3) (2, 5) as you can see the second segment (l2) is lying inside 1st segment. so we can write this as (1, 3), (4, 5). so here we converted the 2nd segment l to new time which is equal to r1 + 1.

        if r1 + 1 > r2, this means that second tv is totally not needed so we can output this as answer. for example: (1, 3) (2, 3).

        after building this new vector for out previous example it will look like this:

        array = (1, 2) (2, 3) (3, 4)

        newtime = (1, 2) (3, 3) (4, 4)

        now for each segments in newtime find how many segments are there in array. if there are more than one then this segment is not needed. for this use binary search, find the leftmost segment and then find the rightmost segment. count = (rgt — lft) + 1.

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can anyone please tell me how to approach the problem B i tried all possible solutions from my side

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

When will the editorial be posted? Hacking phase is over already.

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I need editorial of problem F.Can anyone please explain how to model flow network for this problem.

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve G?

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Sorry for the late editorial, it is published now.

»
9 лет назад, скрыть # |
← Rev. 8  
Проголосовать: нравится 0 Проголосовать: не нравится

anyone can help check whats wrong with my solution for problem E, got RTE for 16th test case. http://codeforces.me/contest/863/submission/30694287

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

is there answer?