This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// MLE TEST
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int N,K,M,patern[1000005],niz[1000005],oduz[1000005];
int MOD=1000000009,b=1000037,stepen[1000005];
vector<int> on[1000005],off[1000005];
struct slog{
int sv,poz;
} sniz[1000005];
bool posv(slog a,slog b){
return a.sv<b.sv;
}
struct cvor{
int cnt,mlt,rez;
bool on;
}st[4200000];
cvor opr(cvor a,cvor b){
if(a.on==false)
return b;
if(b.on==false)
return a;
a.rez=(a.rez+b.rez+(ll)a.cnt*b.mlt)%MOD;
a.mlt+=b.mlt;
if(a.mlt>=MOD)
a.mlt-=MOD;
a.cnt+=b.cnt;
return a;
}
void update(int gde,bool akt){
st[gde].on=akt;
gde/=2;
while(gde){
st[gde]=opr(st[gde*2],st[gde*2+1]);
gde/=2;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>N>>M;
stepen[0]=1;
for(int i=1;i<=M;i++)
stepen[i]=(stepen[i-1]*(ll)b)%MOD;
K=1;
while(K<2*M)
K<<=1;
for(int i=1;i<=N;i++)
cin>>patern[i];
for(int i=1;i<=M;i++)
cin>>niz[i];
for(int i=1;i<=M;i++){
sniz[i].poz=i;
sniz[i].sv=niz[i];
}
sort(sniz+1,sniz+1+M,posv);
int upok=K;
for(int i=M;i>=1;i--){
st[upok].cnt=1;
st[upok].mlt=0;
st[upok].rez=0;
st[upok].on=false;
on[sniz[i].poz+1].push_back(upok);
upok++;
st[upok].cnt=0;
st[upok].mlt=stepen[sniz[i].poz];
st[upok].rez=0;
st[upok].on=false;
int l=max(1,sniz[i].poz-N);
on[l].push_back(upok);
off[sniz[i].poz].push_back(upok);
}
for(int i=1;i<=M;i++){
for(int j=0;j<on[i].size();j++)
update(on[i][j],true);
for(int j=0;j<off[i].size();j++)
update(off[i][j],false);
oduz[i]=st[1].rez;
}
cout<<0<<endl;
return 0;
}
Compilation message (stderr)
mat.cpp: In function 'int main()':
mat.cpp:75:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for(int j=0;j<on[i].size();j++)
| ~^~~~~~~~~~~~~
mat.cpp:77:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int j=0;j<off[i].size();j++)
| ~^~~~~~~~~~~~~~
# | 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... |