0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-09 16:58:48 +00:00

#1804. 【2017.3长乐省选集训Day2T2】字符串匹配

https://sjzezoj.com/submission/65996
This commit is contained in:
Baoshuo Ren 2022-12-18 20:05:20 +08:00
parent dd6f260b29
commit 1a7308aec6
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
22 changed files with 129 additions and 0 deletions

66
S2OJ/1804/1804.cpp Normal file
View File

@ -0,0 +1,66 @@
#include <iostream>
#include <unordered_map>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int t, c;
cin >> t >> c;
while (t--) {
int n, m;
cin >> n >> m;
std::vector<int> s(1), t(1);
std::unordered_map<int, int> lst_s, lst_t;
for (int i = 1, x; i <= n; i++) {
cin >> x;
s.emplace_back(i - lst_s[x]);
lst_s[x] = i;
}
for (int i = 1, x; i <= m; i++) {
cin >> x;
t.emplace_back(i - lst_t[x]);
lst_t[x] = i;
}
std::vector<int> nxt(m + 1);
for (int i = 2, j = 0; i <= m; i++) {
while (j && t[j + 1] != std::min(t[i], j + 1)) j = nxt[j];
if (t[j + 1] == std::min(t[i], j + 1)) j++;
nxt[i] = j;
}
std::vector<int> ans;
for (int i = 1, j = 0; i <= n; i++) {
while (j && t[j + 1] != std::min(s[i], j + 1)) j = nxt[j];
if (std::min(s[i], j + 1) == t[j + 1]) j++;
if (j == m) {
ans.emplace_back(i - m + 1);
j = nxt[j];
}
}
cout << ans.size() << endl;
for (int x : ans) cout << x << ' ';
cout << endl;
}
return 0;
}

BIN
S2OJ/1804/data/match1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/match9.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1804/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.