Skip to content

Instantly share code, notes, and snippets.

@KirillLykov
KirillLykov / cf_539b_split_array.cpp
Created February 10, 2019 21:11
Simple but interesting problem B
// http://codeforces.com/contest/1114/problem/B
#include <bits/stdc++.h>
using namespace std;
int main(int, char**) {
int n, m, k;
cin >> n >> m >> k;
vector< pair<int,int> > data(n);
for (int i = 0; i < n; ++i) {
@KirillLykov
KirillLykov / gcd.cpp
Created February 3, 2019 10:49
just to copy-paste from somewhere
// recursive
int gcd(int a , int b)
{
if (b == 0) return a;
a %= b;
return gcd(b, a);
}
// iterative
int gcd(int a , int b)
@KirillLykov
KirillLykov / subs.cpp
Last active July 6, 2018 12:59
longest substring having XXX repeating/distinct elements
// find max substring which has no repeating characters
// https://leetcode.com/problems/longest-substring-without-repeating-characters/description/
class Solution {
public:
int lengthOfLongestSubstring(string s) {
if (s.length() == 0) return 0;
int i = 0;
int j = 0;
vector<int> i2l(256, -1);
@KirillLykov
KirillLykov / seg_lazy.cpp
Created June 21, 2018 21:56
Two lazy tree implemented using array and dynamic memory
#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
@KirillLykov
KirillLykov / arc97_a.cpp
Last active October 21, 2020 13:06
solution for atcoder contest arc97, A
// 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;
@KirillLykov
KirillLykov / .tmux.conf
Last active March 1, 2022 09:58
My TMUX config
# 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
@KirillLykov
KirillLykov / cf_spb_seg2_a_dyn.cpp
Created April 28, 2018 20:33
Implicit segment tree problem
// 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 {
@KirillLykov
KirillLykov / cf_spb_seg2_a.cpp
Created April 28, 2018 20:31
Explicit segment tree problem
// 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];
@KirillLykov
KirillLykov / mccme_3327.cpp
Created April 27, 2018 21:06
Solution of a problem using dynamic segment tree
// 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;
@KirillLykov
KirillLykov / tc_tco18_r1a_b.cpp
Created April 21, 2018 17:55
Topcoder TCO2018, Round1A, B
#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)