apamineralasauplata's blog

By apamineralasauplata, history, 18 months ago, In English

What's the most interesting beautiful you know about?

| Write comment?
»
18 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Using map<int, vector < int >> as a data structure for making several implementation easy

  • »
    »
    18 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I also sometimes do it but I don't see it generally in the codes of people who are very good. So can anyone tell is this way good or is there any better way that I might be missing.

    • »
      »
      »
      18 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      people either use unordered map or vector of pairs + binary search instead of map , but they are all for the same purpose

  • »
    »
    18 months ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it

    .

»
18 months ago, # |
  Vote: I like it +29 Vote: I do not like it

FFT.

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Pie for a pie trick.

»
18 months ago, # |
  Vote: I like it +102 Vote: I do not like it

I like monotonic stack. The idea is pretty simple but you can do a lot of stuff with it

  • »
    »
    18 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    recently used this to implement a solution which was not the intended solution (or simplest)

    my soln to Ranom numbers

    when decreasing s[i] to lower character it will affect only those indices for which next_greater_character index is 'i' (if next_great[j] < i or next_great[j] > i then its contribution is negative irrespective of value at index 'i')

»
18 months ago, # |
  Vote: I like it +48 Vote: I do not like it

WQS Binary Search

»
18 months ago, # |
  Vote: I like it +34 Vote: I do not like it

Grundy Numbers with Infinity

»
18 months ago, # |
  Vote: I like it +5 Vote: I do not like it

My fav is LCA with binary lifting, least fav is probably sqrt decomposition

»
18 months ago, # |
  Vote: I like it +40 Vote: I do not like it

seg tree best

»
18 months ago, # |
  Vote: I like it +28 Vote: I do not like it

To be honest, the humble DFS: it's simple, but very flexible and you can do quite a lot of things with it: finding cycles, topological sorting, strong connectivity, finding bridges, tree DP (and a lot of tree calculations in general), Euler tours, some ad-hoc applications etc. etc.

»
18 months ago, # |
  Vote: I like it +34 Vote: I do not like it

Union find all the way

»
18 months ago, # |
Rev. 2   Vote: I like it +9 Vote: I do not like it

Vjudgian algorithm with black holes

  • »
    »
    18 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    what is that? is this means Virtual Judges? are you making jokes about something? I am a newbie here, would like to know what this could be related to?

»
18 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Matrix Exponentiation

  • »
    »
    4 days ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    isn't this a trick to get transitive closure of a graph?

»
18 months ago, # |
  Vote: I like it +1 Vote: I do not like it

the simple binary search

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Optimizing bitset memory usage from O(n^2) to O(n)

  • »
    »
    18 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    wait how to do it, can you provide some blog etc

    • »
      »
      »
      18 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Sorry, it's not O(n) but O(n*b) where b >= 64 (or 256 if we want to use SIMD)

    • »
      »
      »
      18 months ago, # ^ |
        Vote: I like it +37 Vote: I do not like it

      I also absolutely love this technique.

      It's mentioned in this blog by -is-this-fft-, the editorial of Aimtech Poorly Prepared Contest problem B (where I first learned it). I also described it as a solution to one of the recent cf problems.

»
18 months ago, # |
  Vote: I like it +55 Vote: I do not like it

Linearity of expectation of a sum of dependent variables; in cp it's mostly used to turn the problem "find the expected number of objects" into the problem "sum the probability that an object appears for each object"

»
18 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Disjoint Set Data structure.

»
18 months ago, # |
  Vote: I like it +14 Vote: I do not like it

My favourite technique, the Goemans Williamson MAX-CUT algorithm doesn't come from competitive programming, but from the field of approximation algorithms. It's one of the most elegant algorithms I've come across in computer science, so I'd recommend others to check it out too.

»
18 months ago, # |
  Vote: I like it -17 Vote: I do not like it

The most interesting and beautiful thing I know is Talia Al Ghul.

»
18 months ago, # |
Rev. 2   Vote: I like it +7 Vote: I do not like it

whenever I come across a question like "print a permutation which satisfies [some] conditions", I usually generate all of the possible permutations using std::next_permutation(c++) and print the permutations which satisfy the given conditions. I analyse all of the correct permutations and search for patterns.

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

DSU, seg tree, Fenwick, Dijkstra, DP and binary search maybe.

»
18 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Binary Search. Simple but Gorgeous

»
18 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Segment Tree and Hashing

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Dynamic Programming.

»
18 months ago, # |
  Vote: I like it +9 Vote: I do not like it

Mo's algorithm.

»
18 months ago, # |
  Vote: I like it +12 Vote: I do not like it

I never thought Lexicographically Minimal String Rotation could be solved better than $$$O(n \log n)$$$ — using hashing, but when I tried to do some research and read papers, I then know much more:

Spoiler

Other than that, I also discover a technique to find a dominant element on $$$[l, r]$$$ in $$$O(\log n)$$$ using a segment tree (yes, it also allow for updates)

»
18 months ago, # |
  Vote: I like it +4 Vote: I do not like it

(Don't know much but)calculating stuff such as square roots and cube roots using binary search.

»
18 months ago, # |
Rev. 3   Vote: I like it +9 Vote: I do not like it

Beautiful but not that useful: Turtle and hare It has the O(n) complexity, but uses constant memory

»
18 months ago, # |
  Vote: I like it +5 Vote: I do not like it

It's definitely parallel binary search, it's really simple yet appears in the hardest problems

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I found dp beautiful

»
18 months ago, # |
  Vote: I like it -8 Vote: I do not like it

Yarin Sieve when the time/memory limit is strict. It is at least 3 times faster than the standard Sieve. Another one is the Fast Inverse Square root algorithm — the code doesn't make sense at first glance. It's still one of the most widely used algorithms in Game development.

»
18 months ago, # |
  Vote: I like it +12 Vote: I do not like it

I like treap. Treap is a very powerful structure that can do many crazy things.

Also like +-300 dp optimization

»
18 months ago, # |
  Vote: I like it +11 Vote: I do not like it

This one from Blogewoosh.

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Mo‘s!

relatively easy to implement, can support nearly every type of query, can adapt onto trees, supports updates, sqrt(n) time which is ok..., offline...

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Using Trie as a replacement for most data structures, like a hashmap with constant lookup time, finding Kth smallest element in Trie, Counting number of elements smaller than some number in Trie.

»
18 months ago, # |
  Vote: I like it -8 Vote: I do not like it

recursion/ induction/ dp. It's simple to write and it proves itself

»
18 months ago, # |
  Vote: I like it +6 Vote: I do not like it

Bitset, the niche observation that if $$$N$$$ integers sums up to $$$M$$$, then there must be no more than $$$\sqrt{2M}$$$ distinct value, dynamic segment tree (I swear to god these things always are the unintended solutions somehow, not complaining though since they saved my neck more than I could count).

Oh and there's BFS, DFS, binary search, DSU, stack and deque (daddy Um_nik would be happy)

And there's the magbum onuts square decomposition. God dayum they are just the most satisfying thing to pull off.

»
18 months ago, # |
  Vote: I like it +10 Vote: I do not like it

Lazy persistent segment tree. Once I implemented in one of the codechef long challenges from 2017's, and I got pretty descent rank and also earned money for being 2'nd in India. I learned the trick during 10 days contest and also implemented one of the most difficult problems in my life.

That was my first earning in my life in software career. :)

Thank you CodeChef_admin . Please bring back those long challenges, those were very good for learning experience for new comers :) .

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

thinking

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Codeforces <3

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it
  1. REROOTING TECHNIQUE ON TREE.
  2. HASHING.
  3. DP.
»
18 months ago, # |
  Vote: I like it +15 Vote: I do not like it

Binary search

»
18 months ago, # |
  Vote: I like it +16 Vote: I do not like it

The fact that total number of distinct frequency of element in an array is at most sqrt(n).

»
18 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

vector arr = {1, 2, 3, 2, 1};

set st = set< int >(arr.begin(), arr.end()); // convert a vector into set

arr = vector< int >(st.begin(), st.end()); // convert a set into vector.

»
18 months ago, # |
  Vote: I like it +33 Vote: I do not like it

XOR Basis

»
18 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Monotonic queue

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

string hashing

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it
  1. Priority queue
  2. Monotonic stack
  3. String hashing
  • »
    »
    18 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    suggest some questions monotonic stack

»
18 months ago, # |
  Vote: I like it +5 Vote: I do not like it

PRACTICE

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

how is no one metion dp:)

»
18 months ago, # |
Rev. 3   Vote: I like it +47 Vote: I do not like it

I came up with it myself. If you want to take 3 integers as input and sort them. Just do this:

int a, b, c;
cin >> a >> b >> c;
sort(&a, &a+3);

Some compilers do catch these types of memory mishandling. But you can always find one that doesn't.

  • »
    »
    18 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    wow can we use this on codeforces ?? never seen this thing before.

    very useful it seems.

    I am suscpicious though with compiler optimisation, it is possible that memory allocation order gets changed, so using statements like

    sort(&a + 1, &a + 3); could lead to disaster. Someone expert on compiler optimisation, can please confirm this. nor

    • »
      »
      »
      18 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Doesn't really work, for instance, GCC 13.1 fails a certain assert here.

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Stars and bars

»
18 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Alien trick

»
18 months ago, # |
  Vote: I like it -8 Vote: I do not like it

suffix automaton

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

The one I really love is number 2 Here

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

dsu

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

segtree

»
4 days ago, # |
  Vote: I like it +1 Vote: I do not like it

It has to be the Delta Encoding !

»
4 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Karatsuba algorithm: splits large numbers in a symmetrical manner

»
4 days ago, # |
  Vote: I like it 0 Vote: I do not like it

dsu,bs with prefix sum

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Partitioning ans Mo's algorithm.

»
3 days ago, # |
  Vote: I like it +1 Vote: I do not like it

Here Are Some Of The Techniques Or Mathematical Theorems I Like :- Of Course; Binary Search, DP, Prefix Sum, 2 Pointers And DFS Are God Level Techniques But Still Any Beginner Should Know About Given Techniques Also :-

- Difference Array Technique.
- Chicken McNugget Theorem.
- Chinese Remainder Theorem.
- Bars And Stars / Beggars Method.
- Disjoint Set (Union Find).
- Sieve Of Eratosthenes.
- Rolling Hash Function.
- 2Sat (Can Be Tough To Implement (SCC), Still Comes Handy In Some Complicated Problems).

There Are Many More Beautiful Techniques Like FFTs, Square Root Decomposition, Binary Lifting (LCA), Etc. But, I Am Yet To Explore Them.

Thanks To Peer Programmers For Mentioning Such Innovative Ideas (Will Definitely Give A Try)...

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Rerooting.

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Dynamic connectivity

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

prefix function, segtree, small to large, bitset optimizations, hashing, djikistra based dp.

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

BINARY SEARCH

»
3 days ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it
  1. Finding Sliding Window Median
  2. Use of PBDS Data Structure.
  3. Monotonic Stack