Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

Автор apamineralasauplata, история, 16 месяцев назад, По-английски

What's the most interesting beautiful you know about?

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

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

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

»
16 месяцев назад, # |
  Проголосовать: нравится +29 Проголосовать: не нравится

FFT.

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

Pie for a pie trick.

»
16 месяцев назад, # |
  Проголосовать: нравится +102 Проголосовать: не нравится

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

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

    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')

»
16 месяцев назад, # |
  Проголосовать: нравится +48 Проголосовать: не нравится

WQS Binary Search

»
16 месяцев назад, # |
  Проголосовать: нравится +34 Проголосовать: не нравится

Grundy Numbers with Infinity

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

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

»
16 месяцев назад, # |
  Проголосовать: нравится +40 Проголосовать: не нравится

seg tree best

»
16 месяцев назад, # |
  Проголосовать: нравится +28 Проголосовать: не нравится

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.

»
16 месяцев назад, # |
  Проголосовать: нравится +34 Проголосовать: не нравится

Union find all the way

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

Vjudgian algorithm with black holes

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

Matrix Exponentiation

»
16 месяцев назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

the simple binary search

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

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

»
16 месяцев назад, # |
  Проголосовать: нравится +55 Проголосовать: не нравится

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"

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

Disjoint Set Data structure.

»
16 месяцев назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

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.

»
16 месяцев назад, # |
  Проголосовать: нравится -17 Проголосовать: не нравится

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

»
16 месяцев назад, # |
Rev. 2   Проголосовать: нравится +7 Проголосовать: не нравится

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.

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

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

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

Binary Search. Simple but Gorgeous

»
16 месяцев назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Segment Tree and Hashing

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

Dynamic Programming.

»
16 месяцев назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

Mo's algorithm.

»
16 месяцев назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

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)

»
16 месяцев назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

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

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

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

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

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

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

I found dp beautiful

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

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.

»
16 месяцев назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

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

Also like +-300 dp optimization

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

This one from Blogewoosh.

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

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...

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

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.

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

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

»
16 месяцев назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

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.

»
16 месяцев назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

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 :) .

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

thinking

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

Codeforces <3

»
15 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
  1. REROOTING TECHNIQUE ON TREE.
  2. HASHING.
  3. DP.
»
15 месяцев назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится

Binary search

»
15 месяцев назад, # |
  Проголосовать: нравится +16 Проголосовать: не нравится

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

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

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.

»
15 месяцев назад, # |
  Проголосовать: нравится +33 Проголосовать: не нравится

XOR Basis

»
15 месяцев назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Monotonic queue

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

string hashing

»
15 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
  1. Priority queue
  2. Monotonic stack
  3. String hashing
»
15 месяцев назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

PRACTICE

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

how is no one metion dp:)

»
15 месяцев назад, # |
Rev. 3   Проголосовать: нравится +47 Проголосовать: не нравится

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.

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

    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

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

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

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

Stars and bars

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

Alien trick

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

suffix automaton

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

The one I really love is number 2 Here

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

dsu

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

segtree