A high-performance laboratory for mastering Data Structures and Algorithms. This repository features industrial-grade templates, optimized competitive programming solutions, and structured implementations.
Tip
Click on the icons or headers to navigate to the specific modules.
|
Progressive problem-solving through the CP-31 curated list.
|
Modular, reusable templates for core DSA.
|
|
Collection of solutions from various OJs.
|
The "Must-Do" classics categorized by topic.
|
To maintain high performance and code clarity, all competitive programming solutions in this repository utilize a Triple-Layer Architecture. This decouples I/O stream synchronization from the core algorithmic logic.
#include <bits/stdc++.h>
using namespace std;
/**
* @brief Optimizes C++ I/O operations by desyncing with
* stdio and untying cin from cout.
*/
inline void fastIO() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
class Solver {
public:
/** @brief Entry point for handling multiple test cases. */
static void execute() {
int testCases = 1;
// Comment this out for single test case problems
if (!(cin >> testCases)) return;
while(testCases--) solve();
}
/**
* @brief Interface Layer: Handles data ingestion and output dispatch.
*/
static void solve() {
// 1. Ingest input parameters
int n;
if (!(cin >> n)) return;
// 2. Execute computational logic
auto result = process(n);
// 3. Dispatch result to output stream
cout << result << "\n";
}
/**
* @brief Engine Layer: Pure logic for a single test case unit.
* @param n Input parameter (Update signature as per problem)
* @return Processed result (Update return-type as per problem)
*/
static int process(int n) {
int result = 0;
// --- Implementation Logic Start ---
// --- Implementation Logic End ---
return result;
}
};
int main() {
fastIO();
Solver::execute();
return 0;
}Our implementations focus on cache efficiency and generic usability.
- Segment Tree: Supports vEB (van Emde Boas) layout for better CPU cache locality. Level-aware combine logic allows for complex range queries.
Note
Performance Optimization (vEB Layout):
By arranging nodes in a van Emde Boas layout, this implementation significantly reduces CPU cache misses compared to the traditional
- Splay Tree: A self-adjusting BST that moves frequently accessed nodes to the root.
- Shortest Path:
Dijkstra,Bellman-Ford - MST:
Prim's,Kruskal's - Connectivity:
Kosaraju(SCC)
| Template | Build | Query | Space |
|---|---|---|---|
| Segment Tree | |||
| Splay Tree |
* Denotes amortized time complexity.
Our Segment Tree is highly flexible, allowing for custom combine logic and level-aware operations.
// Example: Range Sum
std::vector<int> arr = {1, 2, 3, 4, 5};
SegmentTree<int> st(arr);
int sum = st.query(1, 3); // Returns 9 (2 + 3 + 4)
st.update(2, 10); // Update index 2 to value 10The Splay Tree is ideal for scenarios where recently accessed elements need to be retrieved quickly.
// Example: Self-adjusting BST
SplayTree tree = {10, 20, 30, 40};
tree.insert(25); // Inserts 25 and splays it to the root
bool found = tree.contains(20); // Moves 20 to the root if found
tree.erase(30); // Removes 30 and restructures optimally