UPC TrBBnsformBBtion

Learning is like rowing upstream

UPC TrBBnsformBBtion

Title Description

Let us consider the following operations on a string consisting of A and B:
Select a character in a string. If it is A, replace it with BB. If it is B, replace with AA.
Select a substring that is equal to either AAA or BBB, and delete it from the string.
For example, if the first operation is performed on ABA and the first character is selected, the string becomes BBBA. If the second operation is performed on BBBAAAA and the fourth through sixth characters are selected, the string becomes BBBA.
These operations can be performed any number of times, in any order.
You are given two string S and T, and q queries ai,bi,ci,di. For each query, determine whether SaiSai+1…Sbi, a substring of S, can be made into TciTci+1…Tdi, a substring of T.
Constraints
1≤|S|,|T|≤105
S and T consist of letters A and B.
1≤q≤105
1≤ai≤bi≤|S|
1≤ci≤di≤|T|

translation

Let us consider the string performed by the A and B consisting of the following: Select the string of characters, if it is A BB can replace, if B can use AA instead. You can also select a AAA or BBB string deleted. For example, if the first operation performed on the selected first and ABA character, the string will become BBBA. If performing a second operation on BBBAAAA, and selects the fourth to sixth characters, the string becomes BBBA.
These operations can perform any number of times.
Given two strings S and T, and q queries
for each query will give A I , B I , C I , D I . For each query, it is determined by the S selected sub-string can be converted by the sub-string T is formed.
Restrictions
1≤ | S |,
.

| T | ≤ 105
S and T by the letters A and B.
1≤q≤10 . 5
1 ≦ a I ≤b I ≤ | S |
the relationship of 1≤C I ≦ d I ≤ | T |

Entry

Input is given from Standard Input in the following format:
S
T
q
a1 b1 c1 d1

aq bq cq dq

translation

Input from the input standard format:
S
T
Q
A . 1 B . 1 C . 1 D . 1
...
A Q B Q C Q D Q

Export

Print q lines. The i-th line should contain the response to the i-th query. If SaiSai+1…Sbi can be made into TciTci+1…Tdi, print YES. Otherwise, print NO.

translation

Q print line. The i-th line should contain the i-th query results right. If you can complete the conversion, print YES. Otherwise, print NO.

Sample Input

BBBAAAABA
BBBBA
4
7 9 2 5
7 9 4 1
1 2 5 7
1 4 2 7

Sample Output

YES
NO
YES
NO

Hint

The first query asking whether the string ABA can generate BBBA. As explained in the problem statement, it can be accomplished by the first operation.
The second query asking whether ABA can generate BBBB, fourth query asking whether bbbaaa can generate BBB. Both are impossible.
The third query asking whether the string BBBAAAA can generate BBBA. As explained in the statement of the problem, it can be accomplished by a second operation.

Resolved
by trying to convert, you will find, in any case would not convert the original A one more or one less
to say if all of the simple to the most simple, will not there is more or less a case of an A or B
That is, if the same content and different positions is output YES, if the content is not identical output nO.

Time to AC
Attach Code

#include<iostream>
#include<algorithm>
#include<string.h>
#include<map>
#include<string>
#include<math.h>
#include<stdio.h>
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
const int MAXN=10010;
const ll long_inf=9223372036854775807;
const int int_inf=2147483647;
inline ll read() {
	ll c=getchar(),Nig=1,x=0;
	while(!isdigit(c)&&c!='-')c=getchar();
	if(c=='-')Nig=-1,c=getchar();
	while(isdigit(c))x=((x<<1)+(x<<3))+(c^'0'),c=getchar();
	return Nig*x;
}
char s[500005];
char t[500005];
int ans1[500005];
int ans2[500005];
int main() {
	int ans=0;
	scanf("%s%s",s+1,t+1);
	for(int i=1; s[i]; i++) {
		if(s[i]=='B')
			ans1[i]=ans1[i-1]+2;
		else
			ans1[i]=ans1[i-1]+1;
	}
	for(int i=1; t[i]; i++) {
		if(t[i]=='B')
			ans2[i]=ans2[i-1]+2;
		else
			ans2[i]=ans2[i-1]+1;
	}
	int T=read();
	int a,b,c,d;
	for(int i=0; i<T; i++) {
		a=read(),b=read(),c=read(),d=read();
		int TEMP1=ans1[b]-ans1[a-1];
		int TEMP2=ans2[d]-ans2[c-1];
		if((TEMP1%3)==(TEMP2%3))
			puts("YES");
		else
			puts("NO");
	}
}

Thinking
The following paragraph has recorded how many of each, and then take more than 3 because only appear one and two, so this is to simplify, and then determine whether the same, that is contained in the content is the same, if it is then output YES, otherwise output NO.
PS simplification is possible here to convert A into B, or both B into A.So the first direct unity reduces to A and then delete all only can not delete, A top two B A. So encountered B 1 plus 2 plus one encounter. The last count enough.
If that is the
AAA and ABBBAA this case
to become
AAA and AAAAAAAAA
then deleted,
A, A will become so. So I want to take on the 3. Because this is a three cycles. A or A AA is AA AAA is '' so to take more than 3.

By- wheel month

book mountain road to, learning is endless suffering for the boat.

Published 32 original articles · won praise 12 · views 1191

Guess you like

Origin blog.csdn.net/qq_35339563/article/details/104171784