-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathH18.cpp
60 lines (58 loc) · 1.41 KB
/
H18.cpp
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
#include <iostream>
using namespace std;
int main()
{
int N, Q;
cin >> N >> Q;
string str;
cin >> str;
int count[N][26];
for (int i = 0; i < N; i++)
for (int j = 0; j < 26; j++)
count[i][j] = 0;
for (int i = 0; i < N; i++)
{
count[i][str[i] - 'a']++;
if (i != 0)
for (int j = 0; j < 26; j++)
count[i][j] += count[i - 1][j];
}
while (Q--)
{
int l, r;
cin >> l >> r;
l--;
r--;
int arr[26] = {0};
if (l == 0)
for (int i = 0; i < 26; i++)
arr[i] = count[r][i] % 26;
else
for (int i = 0; i < 26; i++)
arr[i] = (count[r][i] - count[l - 1][i]) % 26;
string answer;
for (int i = 0; i < 26; i++)
answer += arr[i] + 'a';
///Suffix Length
for (int i = 25; i >= 0; i--)
{
bool flag = true;
for (int j = 26 - i, k = 0; j < 26; j++, k++)
if (answer[j] != answer[k])
{
flag = false;
break;
}
if (flag == true)
{
if (i == 0)
cout << "None";
for (int j = 0; j < i; j++)
cout << answer[j];
break;
}
}
cout << endl;
}
return 0;
}