Блог пользователя kingofnumbers

Автор kingofnumbers, история, 8 лет назад, По-английски

Hello CodeForces Community! I would like to take this opportunity to extend this invitation for CodeChef May Cook-Off. As usual it is scheduled for the second last Sunday of the month.

Joining me on the problem setting panel, we have:

  • Problem setter: Pepe.Chess (Hussain Kara Fallah)

  • Testers: kingofnumbers (Hasan Jaddouh) and iscsi (Istvan Nagy)

  • Editorialist: T1duS (Udit Sanghi)

  • Language Verifier : arjunarul (Arjun Arul)

  • Russian Translator : CherryTree (Sergey Kulik)

  • Mandarin Translator: huzecong (Hu Zecong)

  • Vietnamese Translator: VNOI Team

You will be provided by 5 problems of various difficulties to solve during 2 hours and 30 minutes, I have found the problemset very interesting and I recommend coders of various skills to participate especially GrandMasters, please feel free to provide your feedback in the comments section after the contest, I hope you will enjoy solving the problem set.

You can find the rest of the details about the contest below.

Time: Sunday, 21st May, 2017 at 21:30 HRS (IST) (Indian Standard Time — +5:30 GMT) — Check your timezone.

Details: https://www.codechef.com/COOK82

Registration: You just need to have a CodeChef handle to participate. For all those, who are interested and do not have a CodeChef handle, are requested to register in order to participate.

Prizes: Top 10 performers in Global and Indian category will get CodeChef laddus, with which the winners can claim cool CodeChef goodies. Know more here: https://www.codechef.com/laddu. (For those who have not yet got their previous winning, please send an email to [email protected])

Good Luck! Hope to see you participating!!

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

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

25 minutes left to start!

»
8 лет назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

Did someone manage to solve "Nasty Queries" using a Segment Tree?

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

How to approach Nasty Queries?

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

    The degree of any vertex must be even.

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

      Yes but why does the solution use hashes? Sorry if this is a stupid question.

      • »
        »
        »
        »
        8 лет назад, # ^ |
        Rev. 3   Проголосовать: нравится +7 Проголосовать: не нравится

        The degrees are even means all the endpoints in the given query range appear even number of times. So your query basically is to check if there's any element with odd frequency in given range.

        You can do that by checking if the xor of elements in that range is zero (if each number appears even number of times, they cancel out in pairs). This solution might give wrong decisions for some set of values like: 1, 2, 3. Even though their xor is zero, all of them have odd frequency.

        The idea is to hash each number from 1 to n to distinct and very large numbers chosen randomly so that the probability of such sets occurring becomes very small. Then you can simply check for zero xor.

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

          Thanks! :)

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

          I got it, but what if you are submitting such a solution on codeforces where you will not be able to know whether your randomization failed or not till the end of the contest ?

          • »
            »
            »
            »
            »
            »
            8 лет назад, # ^ |
            Rev. 4   Проголосовать: нравится +18 Проголосовать: не нравится

            Yes you can't know but you can take safety measures to reduce the failure probability to almost zero. On CF I'd probably use 4 - 5 different hashes (in fact, you can take around 50 hashes in this constraint). I'd answer "Yes" only if all of them gave zero. It's close to impossible for such solution to fail.

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

          Could you tell how to design such hash function.Any resources would be useful.

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

            Just assigning a large random number to each value from 1 to n suffices. I did the following.

            const long long MOD = 1e14 + 7;
            
            for (int i = 1; i <= n; ++i) {
              hashValue[i] = (rand() * 1LL * rand()) % MOD;
            }
            

            There's no need to "design" any hash function here. You just need the numbers to be scattered enough so that there's no range with xor zero. For the xor to be zero you need even number of ones in every bit position, the probability of which gets smaller as the number of bits increase.

            Here's my code if you need reference.

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

That deceiving scoreboard submissions got me again. For 2 hours i was trying to squeeze C with either bitset+sqrt -_-. And then read D in last 30 mins. Solution to D appeared so easy to me with just Deque use (Submission)

Btw did anyone do C without hashing? I really hope there exists some solution without hashing.

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

    here. Can this idea be hacked with some clever test case??

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

      Yes, it is very much like hashing only so hackable. Infact it is very easy to generate hack cases if prime numbers aren't random.

      Your solution fails on this case:

      1986 4
      1 3
      1 6
      1 276
      1 1986
      1
      1 4
      
»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

can anybody tell bug in my code of nasty query

simple approach through xor code

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

For Hussain set, some solutions with 10*N*log(10*N) also passed. Mine not among them :(

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

Solution for Hussain Set?

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

How to solve E ?

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

    An editorial will be posted soon I think. The idea mainly was to keep data about only some potential nodes, in this problem It's necessary only to keep data about ancestors of deleted nodes. And when deleting a node you just need to go and update its ancestors, and update their data based on the time shift occurred since the last update. Afterwards just iterate through them and make changes due the deletion of the node.

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

      "Soon"...

      It is really annoying when the editorials for a contest are not posted. This is also the case for CodeChef's recent long challenge. Only the editorials to easier problems were posted, I am still waiting for an editorial to the KILLER problem. Similar thing has happened before too. I wonder when CodeChef will fix this problem of incomplete or no editorials.

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

        I am also waiting for the editorial of E. T1duS, How many days more?

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

          I am not writing for E. I wrote the other 4. The problem required tries which I do not know yet so I asked Praveen Dhinwa. He said he'll write it for that problem.

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

      Any updates on the editorial? Or can anyone share their approaches?

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

How can I submit after the contest?

»
8 лет назад, # |
  Проголосовать: нравится +24 Проголосовать: не нравится

Is there any deterministic solution for problem D?