Tuesday, July 28, 2020

CSES Subtree Queries


You are given a rooted tree consisting of n nodes. The nodes are numbered 1,2,…,n, and node 1 is the root. Each node has a value.

Your task is to process following types of queries:
1. change the value of node s to x
2. calculate the sum of values in the subtree of node s

Constraints

$1\le n, q \le 2 \cdot 10^5$
$1≤a,b,s≤n$
$1≤v_i,x≤10^9$

Saturday, July 25, 2020

CSES Exponentiation II


Problem : Find the value of $(a^{b^c})mod(10^9+7)$ where $1\le n\le 10^5$ and $1\le a,b,c \le 10^9$


In order to solve this problem, we need to understand the Fermat's little theorem:

$(a^p\equiv a) mod(p)$ Where p is a prime number.

Friday, July 24, 2020

CSES Tree Matching

Tree Matching solved with dynamic programming


Let's define :
$dp(P,0)$ : The max matching number that DOES NOT INCLUDE node P.
$dp(P,1)$ : The max matching number that INCLUDES node P.

Tuesday, July 21, 2020

Naive Bayes Classifier VS Logistic Regression


Both classification models are linear functions of features

Joint Distribution VS Conditional Distribution


Naive Bayes models the joint distribution:  $P(X,Y) = P(Y)P(X|Y)$

Logistic Regression models the conditional distribution: $P(Y|X)$

Correlated VS Independent features


CSES Subtree Queries

You are given a rooted tree consisting of n nodes. The nodes are numbered 1,2,…,n, and node 1 is the root. Each node has a value. Your...