이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |