*点击

[COCI2017-2018#3] Programiranje

题目

Description

Little Leticija is preparing for a programming exam. Even though she has solved a lot of tasks, there’s one still left unsolved, so she is asking you for help. You are given the word S and Q queries. In each query, you are given positive integers A, B, C and D. Let’s say that word X consists of letters between positions A and B in word S, and word Y from letters between positions C and D in word S. For each query, you must answer if it is possible to somehow rearrange the letters in word Y and obtain word X.

Little Leticija正在准备编程考试。虽然她已经解决了很多任务,但还有一个任务尚未解决,所以她正在向你寻求帮助。您将获得单词S和Q查询。在每个查询中,给出正整数A,B,C和D.假设单词X由单词S中位置A和B之间的字母组成,而单词S中位置C和D之间的字母组成单词Y.如果可以以某种方式重新排列单词Y中的字母并获得单词X,则必须回答。

Input

The first line of input contains the word S (1 ≤ |S| ≤ 50 000). |S| denotes the number of characters in word S, which consists of lowercase letters of the English alphabet. The second line of input contains the positive integer Q (1 ≤ Q ≤ 50 000).

Each of the following Q lines contains four integers A, B, C i D (1 ≤ A ≤ B ≤ |S| and 1 ≤ C ≤ D ≤ |S| ) from the task.

** 输入格式:

** 第一行输入包含单词S(1≤| S |≤50000)。| S | 表示单词S中的字符数,由英文字母的小写字母组成。第二行输入包含正整数Q(1≤Q≤50000)。

以下Q行中的每一行包含来自任务的四个整数A,B,C i D(1≤A≤B≤| S |且1≤C≤D≤| S |)。 

Output

For each query, output “DA” (Croatian for yes) if it is possible, and “NE” (Croatian for no) if it is not.

** 输出格式:

** 对于每个查询,如果可能,输出“DA”(克罗地亚语为yes),如果不可能,则输出“NE”(克罗地亚语为否)。

Sample Input

vodevovode
2
5 8 3 6
2 5 3 6

Sample Output

NE
DA

思路

一道很水的题;

我们可以设 $f[i][j]$ 表示第 $1-i$ 个位置 第 $j$ 个字母出现的次数;

然后枚举判断一下就好了;

 

代码

#include<bits/stdc++.h>
#define re register
typedef long long ll;
typedef unsigned long long ull;
using namespace std; 
inline ll read()
{
    ll a=0,f=1; char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();}
    while (c>='0'&&c<='9') {a=a*10+c-'0'; c=getchar();}
    return a*f;
}
char s[50010];
ll n,m;
ll f[50010][30];
int main()
{
    scanf("%s",s+1);//读入
    n=strlen(s+1);
    for(re ll i=1;i<=n;i++)
    {
        ll x=s[i]-'a';
        for(re ll j=0;j<26;j++)
            f[i][j]=f[i-1][j];
        f[i][x]++;//记录 1-i ,中每个字母出现的次数
    }
    m=read();
    for(re ll i=1;i<=m;i++)
    {
        ll a=read(),b=read(),c=read(),d=read();
        ll flag=1;
        for(re ll i=0;i<26;i++)
        {
            if(f[b][i]-f[a-1][i]!=f[d][i]-f[c-1][i])//判断不多解释
            {
                flag=0;
                break;
            }
        }
        if(flag)
            puts("DA");
        else
            puts("NE");
    }
}

 

posted @ 2020-08-25 22:04  木偶人-怪咖  阅读(223)  评论(0编辑  收藏  举报
*访客位置3D地图 *目录