이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000000;
int tree[2097149+1];
int sz[2097149+1];
const int p=1000037;
const int mod=1000000007;
int add(int a,int b){return a+b-(a+b>=mod?mod:0);}
int mul(int a,int b){return (ll(a)*b)%mod;}
int pw[N+1];
void update(int idx,int l,int r,int pos,int val,int s)
{
if(l==r)
{
tree[idx]=val;
sz[idx]=s;
}
else
{
int m=(l+r)/2;
if(pos<=m) update(2*idx,l,m,pos,val,s);
else update(2*idx+1,m+1,r,pos,val,s);
tree[idx]=add(mul(pw[sz[2*idx+1]],tree[2*idx]),tree[2*idx+1]);
sz[idx]=sz[2*idx]+sz[2*idx+1];
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin >> m >> n;
pw[0]=1;
for(int i=1;i<=m;i++) pw[i]=mul(pw[i-1],p);
int r=0;
int s=0;
for(int i=1;i<=m;i++)
{
int b;
cin >> b;
r=add(mul(p,r),b);
s=add(s,pw[i-1]);
}
vector<array<int,2>> h(n);
for(int i=0;i<n;i++)
{
cin >> h[i][0];
h[i][1]=i+1;
}
sort(h.begin(),h.end());
vector<int> pos(n+1,0);
for(int i=0;i<n;i++) pos[h[i][1]]=i+1;
auto add_t=[&](int i){update(1,1,n,pos[i],i,1);};
auto rm_t=[&](int i){update(1,1,n,pos[i],0,0);};
for(int i=1;i<m;i++) add_t(i);
vector<int> res;
for(int i=m;i<=n;i++)
{
add_t(i);
if(tree[1]==r) res.push_back(i-m+1);
rm_t(i-m+1);
r=add(r,s);
}
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... |