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 <bits/stdc++.h> | |
using namespace std; | |
char buf[5000001]; | |
int main() { | |
int N; | |
while(scanf("%d", &N) != EOF) { | |
bitset<1010> gate[10]; |
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 <bits/stdc++.h> | |
using namespace std; | |
using ll = long long; | |
struct UnionFind { | |
vector<ll> sz, par, cost; | |
UnionFind(ll n):sz(n, 1), par(n), cost(n, 0) { | |
iota(par.begin(), par.end(), 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
#ifndef MY_DB_UTIL_HPP | |
#define MY_DB_UTIL_HPP | |
#include <iostream> | |
#include <stdexcept> | |
#include <exception> | |
#include <memory> | |
#include <string> | |
#include <sqlite3.h> |
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 MyDB { | |
private: | |
sqlite3* db; | |
bool conn; | |
public: | |
MyDB():db(nullptr), conn(false){} | |
~MyDB() { | |
if(conn) { | |
sqlite3_close(db); | |
} |
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
std::vector<Word> get_all_words_in(const std::vector<Page>& pages) { | |
std::vector<Word> words; | |
std::map<std::string, int> word_conv; | |
int num_words = 0; | |
for(const Page& page : pages) { | |
std::vector<std::string> raw_words = filter_with_regex(get_words_in(page.url()), ".*\\.html$", false); | |
for(int i = 0; i < static_cast<int>(raw_words.size()); ++i) { | |
if(!word_conv.count(raw_words[i])) { | |
word_conv[raw_words[i]] = num_words++; | |
words.emplace_back(word_conv[raw_words[i]], raw_words[i]); |
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
std::vector<Page> get_pages(const std::vector<std::string>& urls) { | |
std::vector<Page> pages; | |
std::map<std::string, int> url_conv; | |
for(int i = 0; i < static_cast<int>(urls.size()); ++i) { | |
pages.emplace_back(i, urls[i]); | |
url_conv[urls[i]] = i; | |
} | |
for(int i = 0; i < static_cast<int>(pages.size()); ++i) { | |
std::string dirpath = [](const std::string& url) { |
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
std::vector<std::string> get_html_paths(const std::string& dirpath) { | |
std::vector<std::string> filepaths; | |
enum_dir_elements(dirpath, filepaths, false); | |
return filter_with_regex(filepaths, ".*\\.html$"); | |
} |
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
std::vector<double> PageRank(const std::vector<Page>& pages, const int K, const bool normalizable) { | |
std::map<int, int> pid_conv; | |
for(int i = 0; i < static_cast<int>(pages.size()); ++i) { | |
pid_conv[pages[i].id()] = i; | |
} | |
std::vector<double> importances(pages.size(), 1.0); | |
for(int k = 0; k < K; ++k) { | |
std::vector<double> sums(pages.size(), 0.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
std::vector<double> get_associations(const std::vector<Page>& pages, | |
const std::vector<Word>& words, | |
const std::vector<std::string>& keywords, | |
const bool normalizable) { | |
std::map<int, int> pid_conv; | |
for(int i = 0; i < static_cast<int>(pages.size()); ++i) { | |
pid_conv[pages[i].id()] = i; | |
} | |
std::map<std::string, int> word_conv; |
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 <bits/stdc++.h> | |
using namespace std; | |
using Int = __int128_t; | |
Int abs128(Int val){return val<0?-val:val;} | |
ostream &operator<<(ostream &os,Int val){ | |
if(ostream::sentry(os)){ | |
__uint128_t tmp=abs128(val); |
NewerOlder