apamineralasauplata's blog

By apamineralasauplata, history, 3 years ago, In English

What's the most interesting beautiful you know about?

| Write comment?
»
3 years ago, hide # |
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

»
3 years ago, hide # |
 
Vote: I like it +29 Vote: I do not like it

FFT.

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

Pie for a pie trick.

»
3 years ago, hide # |
 
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

  • »
    »
    3 years ago, hide # ^ |
     
    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')

»
3 years ago, hide # |
 
Vote: I like it +48 Vote: I do not like it

WQS Binary Search

»
3 years ago, hide # |
 
Vote: I like it +34 Vote: I do not like it

Grundy Numbers with Infinity

»
3 years ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

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

»
3 years ago, hide # |
 
Vote: I like it +40 Vote: I do not like it

seg tree best

»
3 years ago, hide # |
 
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.

»
3 years ago, hide # |
 
Vote: I like it +34 Vote: I do not like it

Union find all the way

»
3 years ago, hide # |
Rev. 2  
Vote: I like it +9 Vote: I do not like it

Vjudgian algorithm with black holes

»
3 years ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

Matrix Exponentiation

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

the simple binary search

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

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

»
3 years ago, hide # |
 
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"

»
3 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Disjoint Set Data structure.

»
3 years ago, hide # |
 
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.

»
3 years ago, hide # |
 
Vote: I like it -17 Vote: I do not like it

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

»
3 years ago, hide # |
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.

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

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

»
3 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Binary Search. Simple but Gorgeous

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

Segment Tree and Hashing

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

Dynamic Programming.

»
3 years ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

Mo's algorithm.

»
3 years ago, hide # |
 
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)

»
3 years ago, hide # |
 
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.

»
3 years ago, hide # |
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

»
3 years ago, hide # |
 
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

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

I found dp beautiful

»
3 years ago, hide # |
 
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.

»
3 years ago, hide # |
 
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

»
3 years ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

This one from Blogewoosh.

»
3 years ago, hide # |
 
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...

»
3 years ago, hide # |
 
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.

»
3 years ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

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

»
3 years ago, hide # |
 
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.

»
3 years ago, hide # |
 
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 :) .

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

thinking

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

Codeforces <3

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

Binary search

»
3 years ago, hide # |
 
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).

»
3 years ago, hide # |
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.

»
3 years ago, hide # |
 
Vote: I like it +33 Vote: I do not like it

XOR Basis

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

Monotonic queue

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

string hashing

»
3 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
  1. Priority queue
  2. Monotonic stack
  3. String hashing
»
3 years ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

PRACTICE

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

how is no one metion dp:)

»
3 years ago, hide # |
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.

  • »
    »
    3 years ago, hide # ^ |
    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

    • »
      »
      »
      3 years ago, hide # ^ |
       
      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.

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

Stars and bars

»
3 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Alien trick

»
3 years ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

suffix automaton

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

The one I really love is number 2 Here

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

dsu

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

segtree

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

It has to be the Delta Encoding !

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

Partitioning ans Mo's algorithm.

»
16 months ago, hide # |
 
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)...

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

Rerooting.

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

Dynamic connectivity

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

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

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

BINARY SEARCH