luogu#P3514. [POI2011] LIZ-Lollipop
[POI2011] LIZ-Lollipop
题目描述
Byteasar runs a confectionery in Byteburg.
Strawberry-vanilla flavoured lollipops are the favourite of local children.
These lollipops are composed of multiple segments of the same length, each segment of either strawberry or vanilla flavour.
The price of the lollipop is the sum of the values of its segments, where a vanilla segment costs one bythaler, while a strawberry segments costs two.
Fig. 1: An exemplary lollipop of five segments, three strawberry flavoured and two vanilla, alternately.
The price of this lollipop is bythalers.
Currently Byteasar is left with only one lollipop, though possibly very long.
As a salesman, he knows only too well that probably no one will want to buy the whole lollipop. For this reason he thinks of breaking the lollipop at the joints of the segments in order to get a shorter lollipop. Each fragment for sale, of course, must stay in one piece.
Byteasar vast experience of a salesman, as well as his understanding of children psychology, tell him that his young customers will most likely want to spend all their money on a single lollipop. With this in mind, he wonders for which values of the lollipop he has can be broken down in such a way that as a result one would get, among other pieces, a lollipop worth exactly bythalers.
Naturally, he is interested in the way of breaking the lollipop as well.
As this task overwhelms him, he asks you for help.
输入格式
In the first line of the standard input there are two integers and (), separated by a single space.
These denote, respectively, the number of segments of the last lollipop left in store, and the number of values of to consider.
The lollipop's segments are numbered from 1 to .
The second line gives an -letter description of the lollipop, consisting of letters T and W, where T denotes a strawberry flavoured segment, while W - vanilla flavoured;the -th of these letters specifies the flavour of the -th segment.
In the following lines successive values of () to consider are given, one per line.
输出格式
Your program should print out exactly lines, giving, one per line, the results for successive values of , to the standard output.
If for a given value of it is impossible to break the lollipop in such a way that there is a contiguous fragment worth exactly bythalers, then the word NIE (no in Polish) should be printed. Otherwise, two integers and (), separated by single spaces, should be printed, such that the fragment of the lollipop composed of the segments numbered from to inclusively is worth exactly bythalers. If there are multiple such pairs, your program is free to choose one arbitrarily.
题目大意
给一个只有 和 的序列,每次询问有没有一个子串的和为 。
输入格式
第一行两个整数 ()。
第二行一个长为 的只含 和 的字符串, 代表 , 代表 。
接下来 行,每行一个整数 ()表示一次询问。
输出格式
行,如果有解则输出两个整数 表示区间 的和是 ,如果无解则输出字符串 NIE
。
5 3
TWTWT
5
1
7
1 3
2 2
NIE
提示
SPJ 对于格式的要求较为严格。对于每个询问后,应紧跟一个换行符。在最后一次输出你的答案以及一个换行符后不应有任何输出。
由 zhouyonglong 提供 SPJ。