Last active
July 9, 2025 08:35
-
-
Save sitano/effb2554fa5cb50df2c4fcb6ace3a107 to your computer and use it in GitHub Desktop.
leetcode c++ headers
This file contains hidden or 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
#pragma GCC optimize("Ofast,unroll-loops") | |
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,mmx,abm,popcnt,tune=native") | |
int const _ = [] { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; } (); | |
template <class T> using vec = vector<T>; | |
using T = TreeNode; | |
using ll = long long; | |
using vi = vec<int>; | |
// auto __unsync_with_stdio = std::ios::sync_with_stdio(false); | |
// auto __uncin_tie = std::cin.tie(nullptr); | |
//////////////////////////////////////////////////////////////////////////////////// | |
#pragma GCC optimize("O3,unroll-loops,Ofast") | |
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") | |
static const auto harsh = []() { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
cout.tie(nullptr); | |
return 0; | |
}(); | |
#define LC_HACK | |
#ifdef LC_HACK | |
const auto __ = []() { | |
struct ___ { static void _() { std::ofstream("display_runtime.txt") << 0 << '\n'; } }; | |
std::atexit(&___::_); | |
return 0; | |
}(); | |
#endif | |
//////////////////////////////////////////////////////////////////////////////////// | |
template <class T> using vec = vector<T>; | |
using T = TreeNode; | |
using T = ListNode; | |
using vvi = vector<vector<int>>; | |
using vvc = vector<vector<char>>; | |
using vi = vector<int>; | |
using str = string; | |
using pii = pair<int, int>; | |
using pis = pair<int, string>; | |
using vs = vector<string>; | |
// strigbuf | |
std::stringstream ss(std::string(reserve, '\0')); | |
string(ss.str()); | |
// reading words | |
stringstream ss(s); | |
string word; | |
stack<string> stk; | |
while(ss >> word) stk.push(word); | |
// priority queue / heap | |
make_heap(p.begin(), p.end()); | |
pop_heap(p.begin(), p.end()); | |
push_heap(p.begin(), p.end()); | |
using pi = pair<int, int> | |
priority_queue<int> max_heap; max_heap.top(); max_heap.pop(); max_heap.push(x); | |
priority_queue<pi, vector<pi>, greater<pi> > min_heap; // over pi.first | |
sort(v.begin(), v.end(), [](const T & a, const T & b) -> bool { return a.t > b.t; }); | |
auto comp = []( adjist a, adjlist b ) { return a.second > b.second; }; | |
priority_queue< adjlist_edge , vector<adjlist_edge>, decltype( comp ) > | |
adjlist_pq( comp ); | |
/// vector slices | |
vector<int> s = {10, 20, 30, 40, 50, 60}; | |
vector<int> d(s.begin(), s.end() - 1); // vector copy | |
span sp(s); // since 0x20 | |
span ss = sp.subspan(2, 5); // (offset, count) |
prefix sums in c++
const int kLimit = *max_element(potions.begin(), potions.end());
// get freq array up to max potion (10^5 * 4 bytes ~ 0.5MB)
vector<int> freq(kLimit + 1, 0);
for (int p : potions) {
freq[p]++;
}
// suffix sums
partial_sum(freq.rbegin(), freq.rend(), freq.rbegin());
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hash map with custom key:
for array<int, X>: