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

Автор AminAnvari, 11 лет назад, По-английски
  • Проголосовать: нравится
  • +168
  • Проголосовать: не нравится

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

cheers! :) :D

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

Would be nice to have SQRT decomposition tag for those problems. Now, I guess, all of them in data structures

http://codeforces.me/problemset/tags/data%20structures

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

timus 1846 also nice sqrt-decomp problem.

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

    Can you, please, elaborate a bit?

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

      I'm thinking of splitting the queries in chunks of sqrt(N) and processing them similar to the disjoint-set-union split as described on e-maxx.

      First of all, we will call a set a DS which can handle the insert and erase operations in O(1).

      Let active set and temp. set be 2 empty sets

      For every chunk of sqrt(N) queries:

      1. Go through all the remove operations (query type '-') and, if possible, remove those numbers from the active set of numbers, and add them in a temp. set. This loop will take O(sqrt(N)).

      2. Let currGcd be the gcd of all the keys in our active set. There are at most O(N) of them.

      3. Process the chunk again and take 2 cases:

      • The query asks to remove X. We will erase it from our temp. set.
      • The query asks to insert X. We will insert it in the temp. set.

      The answer for every query will be the gcd of all the keys in the temp. set and our currGcd. There are at most O(sqrt(N)) items in the temp. set, so this loop will take O(N).

      At the end of a chunk, move all the items from the temp set to the active set (and clear the temp set).

      The overall complexity is O(N * sqrt(N))

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

      можно хранить наши элементы по блокам (gcd всех элементов в нем) + хранить мапу, где запоминаем, в каком блоке лежит число, для ответа пройдемся по блокам и пересчитаем gcd, для добавления/удаления пересчитаем gcd только в одном блоке код

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

    It easily solves with segment tree, each leaf node stores x, non-leaf nodes gcd of its children.

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

Are Mo Algorithm and SQRT decomposition considered the same?

In SQRT decomposition we divide the array in buckets, solve the task in these buckets and answer each query in O() time (worst case). However, using Mo Algorithm the queries are sorted according to the bucket the left end of the queries falls into ...

I think both methods have the same time complexity, but are they considered the same?

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

I got stuck with the problem 446C — DZY Loves Fibonacci Numbers and here's my submissions

could someone help ?

thanks in advance

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

Can 13E - Holes solved using MO's algorithm? Or There are other kind of Sqrt-Decomposition? I have solved the first two in the list. But can't find an idea about this one.

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

242E - XOR on Segment can also be solved with SQRT-decomposition. Although it's slower than the intended solution, it can still AC.

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

One more very nice SQRT-decomposition problem I encountered at the Innopolis Open Elimination round (2016-2017): http://codeforces.me/gym/101182/problem/E

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

Why i am getting TLE at 220B - Little Elephant and Array? My Submission 29417078 .Could anyone help me!

Edited: I have changed my solution from map to array.But this also gives me a TLE! 29417554

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

    Maybe you have to create a struct for the query, add and remove method you can improve it because you have a lot process and you can put this in you cmp.

    bool cmp(const query& p,const query& q){
        if(p.l/nb != q.l/nb)
            return p.l/nb<q.l/nb;
        return ((p.r<q.r)^((p.l/nb)&1));
    }
    
»
9 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

https://www.codechef.com/AUG17/problems/HILLJUMP Another good problem on this topic.

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

It's great to see guys like you guide beginners like us ! Thank you so much !

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

446C DZY Loves Fibonacci Numbers gives TLE with sqrt decomposition. My code gives TLE although its complexity is O(N*sqrt(N))?? Any help would be appreciated.

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

Another good problem on this topic: Chef and Graph Queries

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

I solved Timus 1390 using SQRT optimization

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

How to solve 506D using SQRT decomposition. I've solved it using DSU

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

I just ACed 446C using segment tree with ~2s time. I wonder how algorithms can avoid TLE

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

another problem on this topic: here

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

I have started learning this technique just now. Can somebody suggest some beginner friendly problems on this concept. Any platform would work, Codeforces, Codechef, GFG, SPOJ, any.

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

sqrt solution of 444C — DZY Loves Colors.. not by me .. code