This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |