이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 1e6 + 5;
int n, m;
int pos[N], a[2 * N], nxt[N], prv[N], lt[N], rt[N], kmp[2 * N];
bool check(int l, int i) {
return l != n && !(lt[l + 1] && a[i - l + lt[l + 1] - 1] >= a[i]) && !(rt[l + 1] && a[i - l + rt[l + 1] - 1] <= a[i]);
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> pos[i];
a[pos[i]] = i;
prv[i] = i - 1;
nxt[i] = i + 1;
}
for (int i = 1; i <= n; ++i) {
cout << a[i] << " \n"[i == n];
}
for (int i = 1; i <= m; ++i) {
cin >> a[i + n];
}
for (int i = n; i; --i) {
int l = prv[a[i]], r = nxt[a[i]];
nxt[l] = r;
rt[i] = pos[r];
prv[r] = l;
lt[i] = pos[l];
}
vector<int> res;
for (int i = 1; i <= m + n; ++i) {
int j = kmp[i - 1];
while (j && !check(j, i)) {
j = kmp[j - 1];
}
kmp[i] = j + check(j, i);
if (i >= 2 * n && kmp[i] == n) {
res.push_back(i - 2 * n + 1);
}
}
cout << res.size() << "\n";
for (int x : res) {
cout << x << " ";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |