-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.cpp
More file actions
87 lines (87 loc) · 1.85 KB
/
Copy pathhash.cpp
File metadata and controls
87 lines (87 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<bits/stdc++.h>
using namespace std;
#define MX 10000007
#define ll long long
#define base 29
#define mod 1000000007
#define ull unsigned long long
string s,s1;
ull pw[MX],hf,hb,h;
int main()
{
ll tc,i,j,n,k,m,c,l,t;
char ch,ch1;
pw[0]=1;
for(i=1; i<=MX; i++)
{
pw[i]=pw[i-1]*base;
}
cin>>tc;
t=1;
while(tc--)
{
cin>>s;
l=s.size();
cout<<"Case "<<t++<<":"<<endl;
hf=0;
hb=0;
h=0;
for(i=0; i<l; i++)
{
h=h*base+s[i]-96;
}
hf=h;
h=0;
for(i=l-1; i>=0; i--)
{
h=h*base+s[i]-96;
}
hb=h;
cin>>n;
for(i=0; i<n; i++)
{
cin>>ch>>ch1>>k;
if(ch=='L')
{
h=0;
for(j=0;j<k;j++)
{
h=h*base+ch1-96;
hb=hb*base+ch1-96;
}
hf=h*pw[l]+hf;
l+=k;
//cout<<hf<<" "<<hb<<endl;
if(hf==hb)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
else
{
h=0;
for(j=0;j<k;j++)
{
h=h*base+ch1-96;
hf=hf*base+ch1-96;
}
hb=h*pw[l]+hb;
l+=k;
//cout<<hf<<" "<<hb<<endl;
if(hf==hb)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
}
}
return 0;
}