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
class AlmostFibonacciKnapsack: | |
def getIndices(self, x): | |
A = [2, 3] | |
while A[-1] + A[-2] - 1 <= x: | |
A.append(A[-1] + A[-2] - 1) | |
N = len(A) | |
ans = [] | |
while x > 0: | |
i = bisect.bisect_left(A, x) | |
if i == N or A[i] > x: |
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
class ImportantSequence: | |
def getCount(self, B, operators): | |
INF = 10**18 | |
lb, ub = 1, INF | |
sign = 1 # if sign == 1 then '+' else '-' | |
c = 0 | |
for b, ope in zip(B, operators): | |
if ope == '+': | |
sign ^= 1 | |
c = b - c |
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 ll; | |
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++) | |
#define REP(i,x) FOR(i,0,x) | |
#define ALL(c) c.begin(), c.end() | |
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl | |
#define INF (int)1e9 |
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 ll; | |
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++) | |
#define REP(i,x) FOR(i,0,x) | |
const ll mod = 1000000009; | |
int main() { |
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
class EllysXors: | |
def getXor(self, L, R): | |
max_bitlen = (4*10**9).bit_length() | |
def count_bit_sum(N): | |
bit = [0] * max_bitlen | |
if N == 0: | |
return bit[:] | |
for i in range(N.bit_length() - 1): | |
bit[i] = 1 << (N.bit_length() - 2) | |
bit[N.bit_length()-1] = N - (1 << (N.bit_length() - 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
let S = stdin.readline | |
echo(if S[^1] == 'T': "YES" else: "NO") |
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
import strutils, sequtils | |
let | |
A = stdin.readline.split.map(parseInt) | |
B = stdin.readline.split.map(parseInt) | |
var flag = false | |
for a in A: | |
for b in B: | |
if a == b: | |
echo("YES") |
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
import strutils, sequtils | |
let N = stdin.readline.parseInt | |
var | |
A = stdin.readline.split.map(parseInt) | |
left, ans = 0.int64 | |
A.add(0) | |
while left < N: | |
var right = left + 1 | |
while A[right.int-1] < A[right.int]: right.inc |
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
import sequtils, strutils, algorithm, tables | |
type | |
SegTree[T] = object | |
dat: seq[T] | |
size: int | |
real_size: int | |
default: T | |
proc initSegTree[T](size: int, default = 0): SegTree[T] = |
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
import strutils, algorithm, sequtils | |
let N = stdin.readline.parseInt | |
var boxes: seq[(int, int)] = @[] | |
for _ in 1..N: | |
let t = stdin.readline.split.map(parseInt) | |
boxes.add((t[0], -t[1])) | |
boxes.sort(cmp) | |
var lis: seq[int] = @[] | |
for i, box in boxes: | |
let |