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;
const int maxn = 1e6 + 5, inf = 1e9 + 5;
int mi[maxn*2];
int mini(int l, int r)
{
int ans = inf;
for (l += maxn, r += maxn + 1; l < r; l >>= 1, r >>= 1)
{
if (l&1) ans = min(ans, mi[l++]);
if (r&1) ans = min(ans, mi[--r]);
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> s(n), h(m);
for (int i = 0; i < n; i++) cin >> s[i], s[i]--;
for (int i = 0; i < m; i++) cin >> h[i], mi[maxn + i] = h[i];
for (int i = maxn-1; i > 0; i--) mi[i] = min(mi[i<<1], mi[(i<<1)|1]);
vector<int> ans;
for (int i = 0; i + n - 1 < m; i++)
{
int m1 = mini(i, i + s[0] - 1), m2 = h[i + s[0]], m3 = mini(i + s[0] + 1, i + n - 1);
if (m1 < m2 || m3 < m2) continue;
bool ok = true;
for (int j = 1; j < n; j++)
{
//cout << i+s[j-1] << " " << i+s[j] << endl;
if (h[i+s[j-1]] > h[i+s[j]])
{
ok = false;
break;
}
}
if (ok) ans.push_back(i+1);
}
cout << ans.size() << "\n";
for (int i : ans) cout << i << " ";
cout << "\n";
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... |