EOJ 3441 唐納德與子串 (Easy)

題目大意:

子串的定義是在一個字符串中連續出現的一段字符。這裏,我們使用 s[lr] 來表示 s 字符串從 lr(閉區間)的子串。在本題中,字符串下標從 0 開始。顯然,對於長度爲 n 的字符串共有 n(n+1)2 個子串。

對於一個給定的字符串 s,唐納德給出 q 次詢問,第 i 次詢問包括三個參數 li,ri,zi,問在 s[liri] 的所有子串中共有多少個恰好爲 zi

Input

輸入具有如下形式:

sql1 r1 z1l2 r2 z2lq rq zq

第一行一個字符串 s

第二行一個整數 q

接下來每行:首先兩個整數 li,ri (0liri<|s|),然後是一個非空字符串 zi。整數和整數,整數和字符串間以單空格隔開。

字符串中只會出現 26 個小寫英文字母。

數據規模約定:

  • 對於 Easy 檔:1|s|100,q|zi|100
  • 對於 Hard 檔:1|s|105,q|zi|105

Output

對於每次詢問,輸出一個整數,表示答案。

Examples

Input
thisisagarbagecompetitionhahaha
5
0 30 a
1 5 is
25 30 hah
6 12 ag
7 12 ag
Output
6
2
2
2
1

解題思路:

首先一看Easy數據量果然很水暴力都能過。 所以想奔着Hard去的,然而很菜套線段樹的時候gg了只能乖乖先暴力kmp低空飄過。

代碼:

#include <iostream>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <cmath>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>

using namespace std;

/*tools:
 *ios::sync_with_stdio(false);
 *freopen("input.txt", "r", stdin);
 */

typedef long long ll;
typedef unsigned long long ull;
const int dir[9][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1, 0, 0};
const ll ll_inf = 0x7fffffff;
const int inf = 0x3f3f3f;
const int mod = 1000000;
const int Max = (int) 2e5 + 7;

char str[Max], ans[Max];
int num[Max], vis[Max];

int main() {
    //freopen("input.txt", "r", stdin);

    scanf("%d", str);
    int len = strlen(str);
    for (int i = 0; i < len; ++i) {
        num[str[i]]++;
    }

    for (int i = 0; i < Max; ++i) {
        if (num[i] > n / 2) {
            printf("impossible\n");
            break;
        }
    }
    for (int i = 0; i < n; ++i) {
        else {
            for (int j = 0; j < n; ++j) {
                if (str[i] != str[j] && !vis[j]) {
                    ans[j] = str[i];
                    vis[j] = 1;
                }
            }
        }
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章