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; | |
typedef long long int lint; | |
typedef long double ldouble; | |
const int N = 100001; | |
int a[N]; | |
int t[4*N]; | |
void build(int cur, int l, int r) { |
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
// Solution for http://codeforces.com/contest/192/problem/E | |
// You are given a tree and in each node of the tree there is a person (called full further) | |
// which goes to another person living in different node. | |
// You need to compute for every edge how many persons will pass through it. | |
// We decompose the path from one person to another using LCA. | |
// Using LCA algorithm which requires logN operations for search | |
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long int lint; |
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
// Solution for http://codeforces.com/problemset/problem/609/E | |
// Idea: | |
// 1. Build Min Spanning Tree MST | |
// 2. For each edge: | |
// 2.1 if edge belongs to MST => just print cost(MST) | |
// 2.2 else | |
// if we add this edge to MST, it will not be a tree anymore since | |
// we introduced a loop L. | |
// Now, if we delete an edge from L with max cost (except for newly added), | |
// we get a tree again. Cost(newTree) = cost(MST) + cost(addedEdge) - cost(deletedEdge) |
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 Resistance { | |
public: | |
bool pass(int a, vector<string>& missions) { | |
for (auto& m : missions) { | |
if (m[0] == 'F') { | |
int mi = stoi(m.substr(1), nullptr, 2); | |
if ((mi & a) == 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
// Solution for http://informatics.mccme.ru/moodle/mod/statements/view.php?chapterid=3327#1 | |
// Given an array A[1,..,n] it is required to implement two operations | |
// 1) get(index) return A[index] | |
// 2) add(l, r, val) A[l,..,r] += val | |
// I used dynamic (also called implicit) segment tree | |
// this type of implementation reduces space from O(N) to O(mlogN) | |
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long int lint; |
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
// solution for http://codeforces.com/gym/100094/attachments/download/1239/20122013-tryenirovka-spbgu-b-6-zaprosy-na-otryezkye-dyeryevo-otryezkov-2-ru.pdf | |
// problem A using explicit segment tree | |
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long int lint; | |
const int N = 1e6; | |
int t[4*N+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
// solution for http://codeforces.com/gym/100094/attachments/download/1239/20122013-tryenirovka-spbgu-b-6-zaprosy-na-otryezkye-dyeryevo-otryezkov-2-ru.pdf | |
// problem A using Implicit (dynamic) segment tree | |
// For unknown reason it fails test 8 with TLE | |
// Nevertheless might be useful as an example of dynamic implementation | |
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long int lint; | |
const lint BIG = 1e9 + 1; | |
struct Node { |
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
# remap prefix to Control + q | |
set -g prefix C-q | |
unbind C-b | |
bind C-q send-prefix | |
# force a reload of the config file | |
unbind r | |
bind r source-file ~/.tmux.conf | |
# quick pane cycling |
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
// Solution of https://arc097.contest.atcoder.jp/tasks/arc097_a | |
// using string hashing | |
// Good as a source of code for general hashing with reversed element | |
// But overcomplicated for this problem -- it is possible to just generate all the | |
// sustrings, sort/unique them and return k-th | |
// | |
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long int lint; |
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; | |
typedef long long int lint; | |
// Explicit tree: using array | |
const int N = 7; | |
int tr[4*N + 1]; | |
int maxV[4*N + 1]; | |
void update(int cur, int L, int R, int l, int r) // increments by one corresponding vertices |