이 제출은 이전 버전의 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 && a[i - lt[l + 1]] <= a[i] && a[i - rt[l + 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 <= m; ++i) {
cin >> a[i + n];
}
for (int i = n; i; --i) {
int l = prv[a[i]], r = nxt[a[i]];
nxt[l] = r;
if (r != n + 1) {
rt[i] = i - pos[r];
}
if (l) {
lt[i] = i - pos[l];
}
prv[r] = l;
}
vector<int> res;
for (int i = 2; i <= m + n; ++i) {
int j = kmp[i - 1];
while (j && !check(j, i)) {
j = kmp[j];
}
kmp[i] = j + check(j, i);
// if(check(j,i))cout<<j<<' '<<i<<' '<<a[i-lt[j+1]]<<' '<<a[i-rt[j+1]]<<'\n';
if (kmp[i] == n) {
// cout<<j<<' '<<i<<' '<<a[i-lt[j+1]]<<' '<<a[i-rt[j+1]]<<'\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... |