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
#include <bits/stdc++.h> | |
using namespace std; | |
// unordered_map leads to TLE on some tests | |
#define MAP map | |
int get(MAP<long long, int>& m, long long key) { | |
auto it = m.find(key); | |
if (it == m.end()) | |
return 0; |
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
// Just template to play with grundy theorem | |
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
const vector<int> moves = {2, 3, 5}; // moves you can make |
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
#include <bits/stdc++.h> | |
using namespace std; | |
double f(long double r, long double h) { | |
return r * r* M_PI + 2.0*M_PI*r*h; | |
} | |
struct Comparator { | |
const vector<long double>& data; | |
Comparator(const vector<long double>& indata) : data(indata) {} |
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
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
class disjoint_sets | |
{ | |
vector<int> parent; |
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
#include <bits/stdc++.h> | |
using namespace std; | |
// first is vtx, second is weight | |
typedef vector< list< pair<int, int> > > TGraph; | |
int prim(int root, const TGraph& graph) | |
{ | |
// NOTE first is weight, second is vtx | |
set< pair<int, int> > q; |
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
#include <bits/stdc++.h> | |
using namespace std; | |
struct Point { | |
int x,y,id; | |
}; | |
struct ClosestPair { | |
int dist2, p1, p2; | |
vector<Point> bigBuffer; |
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
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
class disjoint_sets | |
{ | |
vector<int> parent; |
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
#include <bits/stdc++.h> | |
using namespace std; | |
struct Node { | |
int w; | |
pair<int, int> c; | |
Node(int wi, int xi, int yi) | |
: w(wi), c(xi, yi) | |
{} | |
bool operator< (const Node& another) const { |
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
#include <bits/stdc++.h> | |
using namespace std; | |
class UnionOfIntervals { | |
public: | |
int nthElement(vector <int> lowerBound, vector <int> upperBound, int n) { | |
vector< pair<int, int> > events; | |
for (int i = 0; i < lowerBound.size(); ++i) { | |
events.push_back( make_pair(lowerBound[i], 1) ); | |
events.push_back( make_pair(upperBound[i]+1, -1) ); | |
} |
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
/** | |
My bugs: | |
1) temp[i] += i*k; -> temp[i] += (i+1)*k; | |
2) lint r = c.size(); -> lint r = c.size() + 1; | |
3) used int at some places -> long long everywhere | |
My timing: | |
18m - had solution on paper | |
24m - wrote the first version | |
39m - accepted solution | |
*/ |