Spoj-NPC2015A Eefun Guessing Words
Eefun Guessing Words
Eefun is currently learning to read. His way of learning is unique, by trying to make every possible substring from a given string. However, when the string becomes longer, he can no longer remember all the substring. His friends want to test Eefun's skill by asking questions, given a string S, is there any substring that begins with letter X and ends with letter Y? According to Eefun, each substring contains at least 2 letters. As the given string S is pretty big, Eefun need your help to answer his friend's questions
Input
First line of input contain a single string S which was given by his friends.
Second line contain a number N, the number of questions that Eefun's friends ask.
Next N lines each consists of 2 characters, X and Y
Output
For each questions, output a single string "YA" if the substring exists, or "TIDAK" otherwise
(YA means yes and TIDAK means no in Indonesian)
Example
Input:
HALO
4
H O
L O
A O
O L
Output:
YA
YA
YA
TIDAK
Constraints:
- 'A' ≤ X,Y ≤ 'Z'
- 1 ≤ |S| ≤ 1.000.000
- 1 ≤ N ≤ 1.000.000
记一下每个字母第一次和最后一次出现的位置就好了
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
#define mod 100007
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int fst[],lst[];
char s[],x,y;
int n,q;
int main()
{
while (~scanf("%s",s+))
{
memset(fst,,sizeof(fst));
memset(lst,,sizeof(lst));
n=strlen(s+);
for (int i=;i<=n;i++)
{
if (!fst[s[i]])fst[s[i]]=i;
lst[s[i]]=i;
}
q=read();
for (int i=;i<=q;i++)
{
scanf(" %c %c",&x,&y);
if (fst[x]&&fst[y]&&fst[x]<lst[y])puts("YA");
else puts("TIDAK");
}
}
}
Spoj NPC2015A
Spoj-NPC2015A Eefun Guessing Words的更多相关文章
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
- 2632: [neerc2011]Gcd guessing game
2632: [neerc2011]Gcd guessing game Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 144 Solved: 84[S ...
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- 【填坑向】spoj COT/bzoj2588 Count on a tree
这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...
- SPOJ bsubstr
题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...
- 【SPOJ 7258】Lexicographical Substring Search
http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...
- 【SPOJ 1812】Longest Common Substring II
http://www.spoj.com/problems/LCS2/ 这道题想了好久. 做法是对第一个串建后缀自动机,然后用后面的串去匹配它,并在走过的状态上记录走到这个状态时的最长距离.每匹配完一个 ...
- 【SPOJ 8222】Substrings
http://www.spoj.com/problems/NSUBSTR/ clj课件里的例题 用结构体+指针写完模板后发现要访问所有的节点,改成数组会更方便些..于是改成了数组... 这道题重点是求 ...
随机推荐
- ejb2.0用本地引用提高EJB访问效率
用本地引用提高EJB访问效率 EJB 1.0和1.1规范只定义了一种在EJB组件中引用另一组件的方法,即通过Bean的远程接口.如果两个Bean都在同一个容器之内,则这种网络开销是不必要的.为解决这个 ...
- FZU 1977 Pandora adventure (插头DP,常规)
题意:有一个n*m矩阵,其中有些格子必走,有些格子不可走,其他格子是可走也可不走,问有多少条哈密顿回路? 思路: 本来是一道很简单的题,代码写多了连白痴bug都查不出了,竟然用i>=ex& ...
- navicate与mysql连接的中文乱码问题
1. 在navicate中查看 show variables like'char%'; show variables like 'collation_%'; 2.在mysql中查看 通过对比可以发现两 ...
- 微软OneDrive使用体验
OneDrive是微软推出的一款软件,提供类似百度网盘的功能,能够在线存储照片和文档, 号称从任意电脑.Mac 电脑或手机都可访问. 一起来看看吧,第一次用之前需要进行简单配置. 因为是一个同步盘,需 ...
- Asp.Net Core 进阶(二) —— 集成Log4net
Asp.Net Core 支持适用于各种内置日志记录API,同时也支持其他第三方日志记录.在我们新建项目后,在Program 文件入口调用了CreateDefaultBuilder,该操作默认将添加以 ...
- WINDOWS-API:取得当前用户账户名-GetUserName
bool TFormMain::GetCurrentProcessUser(AnsiString& strUserName) { bool bRet = false; //strUserNam ...
- PAT (Basic Level) Practise (中文)-1029. 旧键盘(20)
PAT (Basic Level) Practise (中文)-1029. 旧键盘(20) http://www.patest.cn/contests/pat-b-practise/1029 旧键盘上 ...
- iOS旋屏
横竖屏切换,视图乱了怎么办? 首先,我们必须了解一下下列4种状态,它们被用来描述设备旋转方向: UIInterfaceOrientationLandscapeLeft 向左,即HOME键在右 UIIn ...
- 将 PROTOCOL 的方法声明为 MUTATING
将 PROTOCOL 的方法声明为 MUTATING 由 王巍 (@ONEVCAT) 发布于 2014/08/17 Swift 的 protocol 不仅可以被 class 类型实现,也适用于 str ...
- GIMP素描效果
1/打开图片,拖动图片到GIMP软件 2/复制两次图层 3/选中最上面的一个图层,mode改为Dodge 4/点击Color,选择Invert,可以看到图片变淡了 5/点击Filters,Distor ...