이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin >> n >> m;
vector<int> s(n+1,0);
for(int i=1;i<=n;i++) cin >> s[i];
vector<int> h(m+1,0);
for(int i=1;i<=m;i++) cin >> h[i];
deque<int> d;
auto add=[&](int i)
{
while(!d.empty()&&h[d.back()]>h[i]) d.pop_back();
d.push_back(i);
};
auto rm=[&](int i)
{
if(!d.empty()&&d.front()==i) d.pop_front();
};
vector<int> res;
auto ch=[&](int l)
{
vector<array<int,2>> v;
for(int i=l;i<=l+n-1;i++) v.push_back({h[i],i-l+1});
sort(v.begin(),v.end());
bool ok=1;
for(int i=0;i<n;i++) ok&=(v[i][1]==s[i+1]);
if(ok) res.push_back(l);
};
for(int i=1;i<n;i++) add(i);
for(int i=n;i<=m;i++)
{
add(i);
int l=i-n+1;
if(l+s[1]-1==d.front()) ch(l);
rm(l);
}
cout << res.size() << "\n";
for(int a:res) cout << a << " ";
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... |