标签归档:线段树

[bzoj 1809][IOI2005] mou

Description

游乐园已经开始运行一个崭新的模拟过山车。模拟的轨道由n 段铁轨组成,并且首尾相连。第一段铁轨从高度0开始。操作员Byteman能通过调整连续几段的铁轨高度来改造这条轨道。在被改造的一段前面的铁轨高度不受影响。 每一次铁轨被调整。后面的轨必须升起或降低来保持连通,并保证起点高度为0。下页举例说明轨道改造过程。 每次开始时车都有足够能量到达高度h。也就是说,只要轨道的高度不超过 h车就一直开下去, 甚至直到结束。 给出每天的运行和改造情况, 为每次运行计算在车停止前,到达的铁轨数。铁轨以一个n个数的数列形式表示 ,一个数对应一段铁轨。第i个di表示在第i段铁轨上的高度变化。也就是说,在到达铁轨i前,如果车的高度是h,那么经过铁轨i后,高度变为h+di。最初轨道是一条水平线。就是说对于所有的i都是di=0。运行和改造交错进行。 每个改造用三个数表示: a , b 和 D。表示从a到b(包括a,b)的所有di改为di=D。每次运行给定一个数字h ——车能到达的最大高度。

继续阅读

[Codeforces 718C] Sasha and Array

Problem Description

Sasha has an array of integers a1, a2, ..., an. You have to perform m queries. There might be queries of two types:

  1. 1 l r x — increase all integers on the segment from l to r by values x;
  2. 2 l r — find , where f(x) is the x-th Fibonacci number. As this number may be large, you only have to find it modulo 109 + 7.

In this problem we define Fibonacci numbers as follows: f(1) = 1, f(2) = 1, f(x) = f(x - 1) + f(x - 2) for all x > 2.

Sasha is a very talented boy and he managed to perform all queries in five seconds. Will you be able to write the program that performs as well as Sasha?

继续阅读

bzoj-USACO除草计划A

我已经做了30/30


继续阅读

AIO2012 Solution(Chinese)

NORT

It is the year 1982. Malcolm Fraser is the Prime Minister of Australia, you frequently listen to Down Under by Men at Work on your boombox and roller blading is the default mode of transport. As a budding computer scientist, you spend most weekends at the local arcade trying to top your score in the popular video game NORT.

NORT is played on a rectangular grid of square cells with H columns and W rows. You ride a light-bike through the grid, starting in the top-left corner cell. Each second, you can move your light-bike up, down, left or right to any of the four adjacent grid cells (as long as you don't go off the grid!). As you move, your bike's exhaust pipe creates an impenetrable wall of light in the cell you were previously in. If you ever move into a cell containing a wall of light (i.e. a cell you have travelled through before), your bike will disintegrate into pixels in a dramatic 8-bit explosion. The only exception is if you return to the top-left corner cell where you started, in which case the wall of light will be connected and your score for the game will be the total length of wall you have created.

Your goal is therefore to plan the longest possible route through the grid starting and ending in the top-left cell without ever passing through a cell more than once.

继续阅读

AIO2015 Solution(English)

Wet Chairs

As luck would have it, it has rained on the morning of the concert. To make matters worse, the staff did a very rushed job drying the seats! Now it is up to you to decide how to seat everyone.

The seats are arranged in a single long line in front of the stage. In particular there are chairs in the line, and each seat is either wet or dry.

However, all is not lost. Out of the N friends you are bringing to the concert K of them are happy to sit on a wet chair. The other N-K of your friends insist on sitting on a dry chair.

Since this concert is best enjoyed with friends, you would also like your group to be seated as close together as possible so that the distance between the leftmost person and rightmost person is as small as possible. Output the smallest distance possible between the leftmost and rightmost friend at the concert.

Your task is to write a program that outputs this smallest possible distance.

继续阅读