This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define THROW_IF(arg, msg) \ | |
if (arg) throw runtime_error(msg); | |
using namespace std; | |
int main() { | |
sockaddr_in addr{ | |
.sin_family = AF_INET, | |
.sin_port = htons(PORT), | |
.sin_addr = {.s_addr = INADDR_ANY}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() { | |
int socketFd = socket(AF_INET, SOCK_STREAM, 0); | |
assert(socketFd != 0); | |
sockaddr_in addr{}; | |
socklen_t addrLen = sizeof(addr); | |
int opt = 1; | |
assert(setsockopt(socketFd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt, sizeof(opt)) == 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <stack> | |
#include <iostream> | |
using namespace std; | |
int main() { | |
vector<vector<int>> graph{ | |
{2, 3}, | |
{0}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
using namespace std; | |
void quick_sort(vector<int>& arr, int l, int r); | |
int quick_partition(vector<int>& arr, int l, int r); | |
int quick_partition(vector<int>& arr, int l, int r) { | |
int pivot = (l + r) >> 1; | |
swap(arr[pivot], arr[r]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
using namespace std; | |
void heap_sort(vector<int>& arr); | |
void build_heap(vector<int>& arr, int n); | |
void heapify(vector<int>& arr, int n, int root); | |
void heap_sort(vector<int>& arr) { | |
build_heap(arr, arr.size()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <iostream> | |
using namespace std; | |
void merge_sort(vector<int>& arr); | |
void func(vector<int>& arr, int l, int r); | |
void merge(vector<int>& arr, int l, int m, int r); | |
void merge_sort(vector<int>& arr) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
// 8 | |
// / \ \ | |
// 4 6 7 | |
// / \ \ | |
// 2 3 5 | |
// / | |
// 1 | |
class FenwickTree { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SegmentTreeNode { | |
public: | |
int start; | |
int end; | |
int sum; | |
SegmentTreeNode *left; | |
SegmentTreeNode *right; | |
SegmentTreeNode(int start, int end, int val) | |
: start(start), end(end), sum(val), left(nullptr), right(nullptr) {} | |
SegmentTreeNode(int start, int end, int val, SegmentTreeNode *left, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
class SegmentTree { | |
private: | |
// number of elements | |
int _N; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
bool default_predicate(int a, int b) { return a > b; } | |
struct Heap { | |
private: |
NewerOlder