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

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

Hello Codeforces!

I implemented a solution with a range tree as bmerry explains here.

It passes the 3 first subtasks but I get Memory Limit on the 2 last subtasks, though I'm using a sparse segment tree.

I store the tree with pointers (each Node has pointers to left son and right son).

I only allocate memory for a node if it is visited during an update.

If I arrive to a node which doesn't exist during a query, I don't create it, I just return 0 (because all the elements covered by this node are zeroes).

So, my memory complexity is O(logR·logC·Nu), which seems to be too big :'( Do you have a trick to reduce the ML ?

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

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

You might find this helpful: http://qr.ae/7ZIfCd

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

    It's helpful, but since treaps are outside of the IOI syllabus, I was hoping for something more elementary. Personally, I don't know anything about treaps so I won't try to solve the problem like this.

    It's sad that there aren't any official solutions for IOI 2013 :'(

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

You can store many updates (say k updates) in one single node, and create its children only when you are attempting to insert the (k + 1)-th update. When querying, don't propagate the updates but consider all of them in O(k) time.
With this strategy, you should save a considerable amount of memory. You can find the best choice of k after some experiments.

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

Bruce's last sentence explains the necessary update: "I think it might also be possible to make it work by sticking with segment trees, but compressing the representation by compacting chains of nodes with one child." As far as I remember, this was indeed enough to get 100 points. (Also, you may consider using 4-byte ints instead of 8-byte pointers everywhere.)

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

I don't know it's ok for you, but you can like it :)

http://ideone.com/6KL5fi

K-d tree is a BST too. But haven't a stupid implememtation. And I'm not sure about complexity of solution. I choose K = 92 at start. But there're, N, M, K, N / K, N * log(N), gcd. It's smaller than billion, I think.

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

    No, I didn't try to optimize more my other method.

    Thanks for the link, but since I don't know how this kind of stuff works, it isn't really helpful. I don't say it doesn't work but I don't know how it works :D

    Remember that for the IOI, I would have to code one myself!

    So, I'll try to learn BSTs before next year's IOI but for this year I have higher priorities of training.

    I hope they won't put too much questions doable with topics outside of the IOI syllabus...

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

      Actually, the new IOI syllabus lists BSTs as "included".

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

        Yes, but I think (I hope) that using the BSTs from the library will be enough.

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

          What are your priorities while studying IOI? (I'm asking this since you said you have higher priorities of training.)

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

            I'm not learning out-of-focus topics but I prefer developing my problem solving skills which are super important at the IOI, lots of tasks don't require any classical algorithms, check IOI 2013 — Robots for example.

            So, my goals for my training are :

            • to finish the "more advanced topics" chapter in CP3 (if you want to see where I am in CP3, my UVa username is damien_g too)

            • to do IOI tasks : I upsolved my IOI 2014 tasks, I still have 2 tasks to do in IOI 2013. Then, I'll do 5h blocks of training with IOI 2012 tasks (in "real" conditions)

            • to learn some tricks which will be useful, some optimizations, some harder topics, ...

            So, I don't want to spend a week now to master max flow if it isn't needed while I could improve my DP skills for example.

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

          To be honest I don't see why coding BST should be excluded. The structures aren't that difficult compared to other things given at IOI. What is more, there is no math in them, so I see no reason for them to be excluded. I personally use Treap and I believe its implementation is very easy to code.

          I did actually participate in the olympiad in Australia and got 63/100 on this problem, precisely because my 2D segment tree wasn't optimised on memory or time limit, even though it was correct, so I can really relate to your comment. That's why as soon as I got back I learned Treap and replaced the inner structure with it — worked perfectly. You should give BSTs a chance! :D

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

        Plot twist : check my new post here!

        Coding BSTs is not needed for this year. So, my intuition was right, the library should be enough.

        Well, you can argue that coding BSTs was also excluded at IOI 2013 and some contestants used them to get 100/100 :D

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

I solved it with 2d segtrees. You keep a pointer segtree , for 80 points its just a normal pointer 2d segtree , for 100 you need to keep a segtree with 3 children instead of 2.