What's the most interesting beautiful you know about?
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3741 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3489 |
7 | Radewoosh | 3483 |
8 | Kevin114514 | 3442 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | atcoder_official | 162 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | nor | 150 |
What's the most interesting beautiful you know about?
Name |
---|
Using map<int, vector < int >> as a data structure for making several implementation easy
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.
people either use unordered map or vector of pairs + binary search instead of map , but they are all for the same purpose
.
FFT.
Pie for a pie trick.
I like monotonic stack. The idea is pretty simple but you can do a lot of stuff with 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')
WQS Binary Search
Grundy Numbers with Infinity
My fav is LCA with binary lifting, least fav is probably sqrt decomposition
seg tree best
agreed
i love to do it too!
At first I thought you were talking about seg tree beats
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.
Union find all the way
Vjudgian algorithm with black holes
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?
Only legends know about it
I will be legend one day, and then I will figure it out by myself :)
Matrix Exponentiation
the simple binary search
Optimizing bitset memory usage from O(n^2) to O(n)
wait how to do it, can you provide some blog etc
Sorry, it's not O(n) but O(n*b) where b >= 64 (or 256 if we want to use SIMD)
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.
Thanks so much
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"
I agree, example problem
Disjoint Set Data structure.
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.
The most interesting and beautiful thing I know is Talia Al Ghul.
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.
You shouldn't be very proud of that lol
DSU, seg tree, Fenwick, Dijkstra, DP and binary search maybe.
Binary Search. Simple but Gorgeous
Segment Tree and Hashing
Dynamic Programming.
Mo's algorithm.
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:
I tried to apply Sqrt Decomposition into Hashing and I get Logarithm Decomposition — $$$O(n \log n) ↦ O(n \log \log n)$$$
I got confused and draft a bunch of pages to understand KMP Booth from KMP — $$$O(n^2) ↦ O(n)$$$
I still failed to implement DC3 from da papers — SA in $$$O(n \log n) ↦ O(n)$$$
Beautiful, simple, and fast algorithm Lyndon-Duval $$$O(n)$$$, tho its idea seems hard to come up with.
Finding the motivation, I optimize my own $$$O(n \log n)$$$ algorithm with the expectation to find a $$$O(n \log \log n)$$$ and failed 3 times (implementation A, B, C). But then by proving, I realize it is just $$$O(n)$$$ (implementation D). Tho I think my trick cant be applied to more problems.
I dunno, it is just a bunch of random pieces of code that somehow optimize the problem into linear solution $$$O(n)$$$, but it was beautiful for me at that time.
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)
(Don't know much but)calculating stuff such as square roots and cube roots using binary search.
Beautiful but not that useful: Turtle and hare It has the O(n) complexity, but uses constant memory
this problem uses this trick 1137D - Cooperative Game
this problem was described in the Antti's "Competetive Programming" book a few years before the contest itself, so it was an unoriginal one
It's definitely parallel binary search, it's really simple yet appears in the hardest problems
I found dp beautiful
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.
I like treap. Treap is a very powerful structure that can do many crazy things.
Also like +-300 dp optimization
This one from Blogewoosh.
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...
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.
recursion/ induction/ dp. It's simple to write and it proves itself
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.
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 :) .
thinking
Codeforces <3
Binary search
The fact that total number of distinct frequency of element in an array is at most sqrt(n).
where this fact can be used? wanted to know
In this problem: https://mirror.codeforces.com/contest/1841/problem/E
My solution:
https://mirror.codeforces.com/contest/1841/submission/209665291
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.
XOR Basis
Monotonic queue
string hashing
suggest some questions monotonic stack
PRACTICE
how is no one metion dp:)
I came up with it myself. If you want to take 3 integers as input and sort them. Just do this:
Some compilers do catch these types of memory mishandling. But you can always find one that doesn't.
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
Doesn't really work, for instance, GCC 13.1 fails a certain assert here.
Stars and bars
Alien trick
suffix automaton
The one I really love is number 2 Here
dsu
segtree