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
// | |
// segment_tree_max_sum.cpp | |
// Competitive Programming | |
// | |
// Created by Shahed Bin Satter on 24/9/20. | |
// Copyright © 2020 Shahed Bin Satter. All rights reserved. | |
// | |
#include <stdio.h> | |
#include <iostream> |
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
// | |
// multiset.cpp | |
// Competitive Programming | |
// | |
// Created by Shahed Bin Satter on 24/9/20. | |
// Copyright © 2020 Shahed Bin Satter. All rights reserved. | |
// | |
#include <stdio.h> | |
#include <iostream> |
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
// | |
// supercomputer.cpp | |
// Competitive Programming | |
// | |
// Created by Shahed Bin Satter on 25/9/20. | |
// Copyright © 2020 Shahed Bin Satter. All rights reserved. | |
// | |
#include <iostream> | |
using namespace std; |
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 <iostream> | |
using namespace std; | |
const int nmax = 1e5 + 1; | |
const int MIN = -1; | |
int arr[nmax]; | |
pair<int, int> tree [nmax * 4]; | |
void build(int id, int l, int r) { | |
if (l == r) { |
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
// [left, right] => range spanned by current node | |
void build(int id, int left, int right) { // O (n) | |
if (left == right) { | |
// when we divide and conquer on the middle element, left and right becomes equal when we reach the leaf nodes | |
tree[id] = arr[left]; | |
return; | |
} | |
int mid = (left + right)/2; | |
// build left child first | |
build(2 * id, left, mid); |
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
int n; // size of array | |
int arr[n]; // global array of elements that are provided as input | |
int tree[4 * n]; // global structure for containing segment tree | |
// initialize with global array arr | |
build(1, 1, n); | |
// query | |
query(1, 1, n, a, b); // query against range [a, b] | |
// update | |
update(1, 1, n, idx, val); |
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
# Enter your code here. Read input from STDIN. Print output to STDOUT | |
n = int(input()) | |
arr = list(map(int, input().split())) | |
w = list(map(int, input().split())) | |
s = 0 | |
for i in range(n): | |
s = s + arr[i] * w[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
# Enter your code here. Read input from STDIN. Print output to STDOUT | |
n = int(input()) | |
array = sorted(list(map(int, input().split()))) | |
# print(array) | |
mean = sum(array) / n | |
if n % 2 == 0: | |
n1 = n//2 | |
n0 = n1 - 1 |
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
# Enter your code here. Read input from STDIN. Print output to STDOUT | |
import numpy as np | |
def cost(y, y_): | |
m = y.shape[1] | |
cost = 1/(2*m) * np.sum(np.square(y-y_)) | |
return cost | |
dimensions = input() |
NewerOlder