- skyline.cpp
template
rbtree.cpp
template
mqueue.cpp- prob239.cpp
Segment Tree: divide & conquer algorithm.
template
array-based fixed range-sum: segtree.cpptemplate
fixed RMQ: rmq.cpp- dynamic range-query: range-module.cpp
template
interval_tree.cpp
template
: bit.cpp- prob307-2.cpp, prob-308-bit.cpp
- Recursive solution
- Euler tour + RMQ
- Binary lifting
- DFS
- in-degree
- LCS: longest_common_subsequence.cpp
- Linear Scan Register Allocation: meetingRoom2.cpp
faster IO: disable the synchronization between stdio and c++ stream library; untie cin from cout.
int speed_up = []{
ios::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
return 0;
}();
I encoutnered another hackery in 121. Best Time to Buy and Sell Stock. Someone just hijacks stdout
and parses out inputs by themselves. This can reduce execution time to 0ms from about 90ms.
int init = [] {
cin.tie(nullptr)->sync_with_stdio(false);
freopen("user.out", "w", stdout);
for (string s; getline(cin, s);) {
int solution = 0, minPrice = INT_MAX;
for (int _i = 1, _n = s.length(); _i < _n; ++_i) {
// parse out input, for instance [7,1,5,3,6,4]
int price = s[_i++] & 15;
while ((s[_i] & 15) < 10) price = price * 10 + (s[_i++] & 15);
// real computation moved from Solution::maxProfit.
minPrice = min(minPrice, price);
solution = max(solution, price - minPrice);
}
cout << solution << '\n';
}
return 0;
}();
class Solution {
public:
int maxProfit(vector<int>& arr) {
return 0;
}
};