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 <algorithm> | |
#include <cmath> | |
#include <iostream> | |
#include <numeric> | |
#include <queue> | |
#include <time.h> | |
#include <vector> | |
using namespace std; | |
using vi = vector<int>; |
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
from bisect import bisect_left | |
n = int(input()) | |
a = list(map(int, input().split())) | |
INF = n + 1 | |
dp = [INF] * n | |
c = [0] * n | |
m = 0 | |
for i, e in enumerate(a): | |
k = bisect_left(dp, e) |
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
from array import array | |
def lower_divisors(N): | |
lower_divisors = array("i") | |
i = 1 | |
for i in range(1, N + 1): | |
if i * i > N: | |
break | |
if N % i == 0: |
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
from array import array | |
def lower_divisors(N): | |
lower_divisors = array("i") | |
i = 1 | |
for i in range(1, N + 1): | |
if i * i > N: | |
break | |
if N % i == 0: |
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
n = int(input()) | |
s = input() | |
prev = -1 | |
ans = 0 | |
for i in range(n - 1): | |
if s[i] != s[i + 1]: | |
# 前半部分と後半部分を掛け合わせる | |
ans += (n - i - 1) * (i - prev) | |
prev = 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
# MEMO:Pythonなのでmodの取り方はもっと雑でもいい | |
def interval_sum(x, y): | |
# x + (x+1) + ... + (y-1) | |
x %= mod | |
y %= mod | |
return ((y * (y - 1) - x * (x - 1)) // 2) % mod | |
def solve(x): | |
# L = 1, R = x についての答え |
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; | |
using ll = long long; | |
constexpr ll mod = 1e9 + 7; | |
ll interval_sum(ll x, ll y) { | |
x %= mod; | |
y %= mod; | |
return (y * (y - 1) - x * (x - 1)) / 2 % mod; | |
} |
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
n = int(input()) | |
a = list(map(int, input().split())) | |
s = sum(a) | |
a += a | |
r = 0 # 右端 | |
c = 0 # sum(a[l:r]) | |
for l in range(n): | |
while 10 * c < s: | |
c += a[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
input();i=-1;print(sum(ord(c)-97<<(i:=i+1)for c in input())) |
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
# 偶奇で重みをy - x = v か y - x = -v かで変えて重み付きUnionFindでクエリに答える. | |
# People on a Line に似ている. | |
class WeightedUnionFind: | |
__slots__ = ("root", "diff_weight") | |
def __init__(self, N): | |
"""root[v] = vの親, diff_weight[v] = 根からの重み""" | |
N += 1 | |
self.root = [-1] * N |
NewerOlder