Problem

Bounce 弹飞绵羊

Description

某天,Lostmonkey\mathrm{Lostmonkey}发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏。游戏一开始,Lostmonkey\mathrm{Lostmonkey}在地上沿着一条直线摆上nn个装置,每个装置设定初始弹力系数kik_i,当绵羊达到第ii个装置时,它会往后弹kik_i步,达到第i+kii+k_i个装置,若不存在第i+kii+k_i个装置,则绵羊被弹飞。绵羊想知道当它从第ii个装置起步时,被弹几次后会被弹飞。为了使得游戏更有趣,Lostmonkey\mathrm{Lostmonkey}可以修改某个弹力装置的弹力系数,任何时候弹力系数均为正整数。

Input

第一行包含一个整数nn,表示地上有nn个装置,装置的编号从00n1n-1,接下来一行有nn个正整数,依次为那nn个装置的初始弹力系数。第三行有一个正整数mm,接下来mm行每行至少有两个数iijj,若i=1i=1,你要输出从jj出发被弹几次后被弹飞,若i=2i=2则还会再输入一个正整数kk,表示第jj个弹力装置的系数被修改成kk

Output

对于每个i=1i=1的情况,你都要输出一个需要的步数,占一行。

Read more »

Problem

阿狸的打字机

Description

阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到一台老式的打字机。打字机上只有2828个按键,分别印有2626个小写英文字母和BBPP两个字母。
经阿狸研究发现,这个打字机是这样工作的:

  • 输入小写字母,打字机的一个凹槽中会加入这个字母(这个字母加在凹槽的最后)。
  • 按一下印有BB的按键,打字机凹槽中最后一个字母会消失。
  • 按一下印有PP的按键,打字机会在纸上打印出凹槽中现有的所有字母并换行,但凹槽中的字母不会消失。

例如,阿狸输入aPaPBbPaPaPBbP,纸上被打印的字符如下:
aa
aaaa
abab
我们把纸上打印出来的字符串从11开始顺序编号,一直到nn。打字机有一个非常有趣的功能,在打字机中暗藏一个带数字的小键盘,在小键盘上输入两个数(x,y)(x,y)(其中1x,yn1\le x,y\le n),打字机会显示第xx个打印的字符串在第yy个打印的字符串中出现了多少次。
阿狸发现了这个功能以后很兴奋,他想写个程序完成同样的功能,你能帮助他么?

Input

输入的第一行包含一个字符串,按阿狸的输入顺序给出所有阿狸输入的字符。
第二行包含一个整数mm,表示询问个数。
接下来mm行描述所有由小键盘输入的询问。其中第ii行包含两个整数xx, yy,表示第ii个询问为(x,y)(x, y)

Output

输出mm行,其中第ii行包含一个整数,表示第ii个询问的答案。

Read more »

Problem

Count on a tree

Description

给定一棵NN个节点的树,每个点有一个权值,对于MM个询问(u,v,k)(u,v,k),你需要回答u  xor  lastansu\ \ xor\ \ lastansvv这两个节点间第KK小的点权。其中lastanslastans是上一个询问的答案,初始为00,即第一个询问的uu是明文。

Input

第一行两个整数N,MN,M
第二行有NN个整数,其中第ii个整数表示点ii的权值。
后面N1N-1行每行22个整数(x,y)(x,y),表示点xx到点yy有一条边。
最后MM行每行33个整数(u,v,k)(u,v,k),表示一组询问。

Output

MM行,表示每个询问的答案。最后一个询问不输出换行符

Read more »

Problem

可持久化并查集 by zky

Description

nn个集合 mm个操作
操作:
1  a  b1\;a\;b 合并a,ba,b所在集合
2  k2\;k 回到第kk次操作之后的状态(查询算作操作)
3  a  b3\;a\;b 询问a,ba,b是否属于同一集合,是则输出11否则输出00

Input

第一行两个整数n,mn,m
以后mm行,每行三个或两个整数opt  a  bopt\;a\;bopt  kopt\;k,意义如上所述

Ouput

对于每个33操作,输出1/01/0

Read more »

Problem

Three Palindromes

Description

Can we divided a given string SS into three nonempty palindromes?

Input

First line contains a single integer T20T\le 20 which denotes the number of test cases.
For each test case , there is an single line contains a string SS which only consist of lowercase English letters.1s200001\le |s|\le 20000

Output

For each case, output the Yes or No​ in a single line.

Read more »

Problem

Matrix

Time Limit: 3000MS3000MS
Memory Limit: 65536K65536K

Description

Given an N×NN\times N matrix AA, whose elements are either 00 or 11. A[i,j]A[i, j] means the number in the ithi^{th} row and jthj^{th} column. Initially we have A[i,j]=0(1i,j<N)A[i, j] = 0 (1 \le i, j\le< N).
We can change the matrix in the following way. Given a rectangle whose upper-left corner is (x1,y1)(x_1, y_1) and lower-right corner is (x2,y2)(x_2, y_2), we change all the elements in the rectangle by using “not” operation (if it is a ‘00’ then change it into ‘11’ otherwise change it into ‘00’). To maintain the information of the matrix, you are asked to write a program to receive and execute two kinds of instructions.

  1. CC x1x_1 y1y_1 x2x_2 y2y_2 (1x1x2n,1y1y2n1\le x_1\le x_2\le n, 1\le y_1\le y_2\le n) changes the matrix by using the rectangle whose upper-left corner is (x1,y1)(x_1, y_1) and lower-right corner is (x2,y2)(x_2, y_2).
  2. QQ xx yy (1x,yn1\le x, y\le n) querys A[x,y]A[x, y].

Input

The first line of the input is an integer $X (X \le 10) $representing the number of test cases. The following X blocks each represents a test case.
The first line of each block contains two numbers NN and TT (2N10002 \le N \le 1000, 1T500001 \le T \le 50000) representing the size of the matrix and the number of the instructions. The following TT lines each represents an instruction having the format “QQ xx yy” or “CC x1x_1 y1y_1 x2x_2 y2y_2”, which has been described above.

Output

For each querying output one line, which has an integer representing A[x,y]A[x, y].
There is a blank line between every two continuous test cases.

Read more »

Problem

Intervals

Description

You are given nn closed, integer intervals [ai,bi][a_i, b_i] and nn integers c1cnc_1\sim c_n.
Write a program that:
reads the number of intervals, their end points and integers c1cnc_1\sim c_n from the standard input, computes the minimal size of a set ZZ of integers which has at least cic_i common elements with interval [ai,bi][a_i, b_i], for each i=1,2,,ni=1,2,\cdots ,n, writes the answer to the standard output.

Input

The first line of the input contains an integer nn (1n5×1041\le n\le 5\times 10^4) – the number of intervals. The following n lines describe the intervals. The (i+1)th(i+1)^{th} line of the input contains three integers aia_i, bib_i and cic_i separated by single spaces and such that 0aibi5×1040\le a_i\le b_i\le 5\times 10^4 and 1cibiai+11\le c_i\le b_i - a_i+1.

Output

The output contains exactly one integer equal to the minimal size of set ZZ sharing at least cic_i elements with interval [ai,bi][a_i, b_i], for each i=1,2,,ni=1,2,\cdots ,n.

Read more »

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment