原创 SGU 103. Traffic Lights (SPFA)

In the city of Dingilville the traffic is arranged in an unusual way. There are junctions and roads connecting the junc

原创 bzoj 2818 Gcd(莫比烏斯反演)

Description 給定整數N,求1<=x,y<=N且Gcd(x,y)爲素數的 數對(x,y)有多少對. Input 一個整數N Output 如題 Sample Input 4 Sample Output 4 H

原创 Codeforces Round #434 D. Polycarp's phone book (字典樹)

There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a dig

原创 bzoj 2005 能量採集(莫比烏斯反演)

Description 棟棟有一塊長方形的地,他在地上種了一種能量植物,這種植物可以採集太陽光的能量。在這些植物採集能量後, 棟棟再使用一個能量彙集機器把這些植物採集到的能量彙集到一起。 棟棟的植物種得非常整齊,一共有n列,每列 有m

原创 2017北京網絡賽 && hihocoder 1582 Territorial Dispute(凸包)

In 2333, the C++ Empire and the Java Republic become the most powerful country in the world. They compete with each o

原创 線性基(處理集合異或的強力工具)

看了好多篇關於線性基的博客,只是說明了怎麼求線性基,但是大都沒有說明爲什麼這樣求線性基。定義:有一個集合 S  = {a1,a2...,an},T的滿足下面條件的一個最小子集A = {a1,a2,....,ak}A的所有子集的異或和的值域

原创 SPOJ DQUERY - D-query (莫隊算法)

Given a sequence of n numbers a1, a2, ..., an and a number of d-queries. A d-query is a pair (i, j) (1 ≤ i ≤ j ≤ n). Fo

原创 Codecraft-18 and Codeforces Round #458 D. Bash and a Tough Math Puzzle(線段樹)

Bash likes playing with arrays. He has an array a1, a2, ... an of n integers. He likes to guess the greatest common

原创 hihocoder 1723 : 子樹統計 (線性基)

描述給定一棵N個節點的有根樹,樹上每個節點有一個非負整數權重Wi。定義節點集合S={i1, i2, ……, ir}的總權重爲:(⊕是異或運算)每次詢問一棵子樹內所有可能出現的總權重數量,即令E爲所詢問的子樹內節點的集合,|T|即爲可能出現

原创 2460: [BeiJing2011]元素 (線性基)

Description  相傳,在遠古時期,位於西方大陸的 Magic Land 上,人們已經掌握了用魔法礦石煉製法杖的技術。那時人們就認識到,一個法杖的法力取決於使用的礦石。一般地,礦石越多則法力越強,但物極必反:有時,人們爲了獲取更強

原创 Codeforces Round #466 (Div. 2) E. Cashback (dp+樹狀數組+RMQ)

Since you are the best Wraith King, Nizhniy Magazin «Mir» at the centre of Vinnytsia is offering you a discount.You are

原创 查詢區間內等於x的數的個數(分塊)

問題:有一個有n個數的數組,q次查詢,每次查詢l, r ,x,查詢區間[l,r]內等於x的數的個數思路:分塊。就把這題當成是分塊的入門題來講解一下分塊。分塊其實就是一種比較優美的暴力(我覺得),一般的分塊都是把長度爲n的數組分成每一塊爲s

原创 SGU 143. Long Live the Queen(樹形DP)

The Queen of Byteland is very loved by her people. In order to show her their love, the Bytelanders have decided to co

原创 SGU 134. Centroid(樹的重心)

You are given an undirected connected graph, with N vertices and N-1 edges (a tree). You must find the centroid(s) of

原创 Codeforces Round #479 F. Consecutive Subsequence(DP)

You are given an integer array of length nn.You have to choose some subsequence of this array of maximum length such th