QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#498064 | #8712. Flooding Wall | SirPh | 8 | 1ms | 7800kb | C++20 | 4.2kb | 2024-07-29 22:28:11 | 2024-07-29 22:28:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mod=(int)1e9+7;
int dpl[2][20003];
int pref[2][20003];
int dpr[10003][20003];
vector<int>hi;
int arr[10000+1];
int brr[10000+1];
int getsuml(int i,int l,int r)
{
i%=2;
if((pref[i][r]-pref[i][l-1]+mod)>=mod)return(pref[i][r]-pref[i][l-1]);
else return (pref[i][r]-pref[i][l-1]+mod);
}
int getsumr(int i,int l,int r)
{
if((dpr[i][r]-dpr[i][l-1]+mod)>=mod)return (dpr[i][r]-dpr[i][l-1]);
else return (dpr[i][r]-dpr[i][l-1]+mod);
}
signed main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>arr[i];
for(int i=1;i<=n;i++){
cin>>brr[i];
if(arr[i]>brr[i])swap(arr[i],brr[i]);
}
for(int i=1;i<=n;i++)hi.push_back(arr[i]);
for(int i=1;i<=n;i++)hi.push_back(brr[i]);
hi.push_back(0);
sort(hi.begin(),hi.end());
hi.erase(unique(hi.begin(),hi.end()));
int a7a=*max_element(arr,arr+n+1);
a7a=max(a7a,*max_element(brr,brr+n+1));
a7a=lower_bound(hi.begin(),hi.end(),a7a)-hi.begin();
int ans=0;
// cout<<dpl.size();
// return 0;
dpr[n+1][0]=1;
for(int i=1;i<=n;i++)
arr[i]=lower_bound(hi.begin(),hi.end(),arr[i])-hi.begin(),brr[i]=lower_bound(hi.begin(),hi.end(),brr[i])-hi.begin();
for(int i=n;i>=1;i--)
{
for(int j=arr[i];j>=0;j--)
{
if(dpr[i+1][j]==0)continue;
dpr[i][arr[i]]+=dpr[i+1][j];
dpr[i][arr[i]]%=mod;
}
for(int j=arr[i]+1;j<=a7a;j++)
{
if(dpr[i+1][j]==0)continue;
dpr[i][j]+=dpr[i+1][j];
dpr[i][j]%=mod;
}
for(int j=brr[i];j>=0;j--)
{
if(dpr[i+1][j]==0)continue;
dpr[i][brr[i]]+=dpr[i+1][j];
dpr[i][brr[i]]%=mod;
}
for(int j=brr[i]+1;j<=a7a;j++)
{
if(dpr[i+1][j]==0)continue;
dpr[i][j]+=dpr[i+1][j];
dpr[i][j]%=mod;
}
}
dpl[0][0]=1;
pref[0][0]=1;
for(int i=0;i<=n+1;i++)
for(int j=1;j<=a7a;j++){
pref[0][j]=dpl[0][j]+pref[0][j-1];
if(pref[0][j]>=mod)
pref[0][j]-=mod;
dpr[i][j]+=dpr[i][j-1];
if(dpr[i][j]>=mod)
dpr[i][j]-=mod;
}
for(int i=1;i<=n;i++)
{
for(int j=0;j<=a7a;j++)dpl[i%2][j]=0;
for(int j=arr[i];j>=0;j--)
{
if(dpl[(i%2)^1][j]==0)continue;
dpl[i%2][arr[i]]+=dpl[(i%2)^1][j];
dpl[i%2][arr[i]]%=mod;
}
for(int j=arr[i]+1;j<=a7a;j++)
{
if(dpl[(i%2)^1][j]==0)continue;
dpl[i%2][j]+=dpl[(i%2)^1][j];
dpl[i%2][j]%=mod;
}
for(int j=brr[i];j>=0;j--)
{
if(dpl[(i%2)^1][j]==0)continue;
dpl[i%2][brr[i]]+=dpl[(i%2)^1][j];
dpl[i%2][brr[i]]%=mod;
}
for(int j=brr[i]+1;j<=a7a;j++)
{
if(dpl[(i%2)^1][j]==0)continue;
dpl[i%2][j]+=dpl[(i%2)^1][j];
dpl[i%2][j]%=mod;
}
pref[i%2][0]=dpl[i%2][0];
for(int j=1;j<=a7a;j++){
pref[i%2][j]=dpl[i%2][j]+pref[i%2][j-1];
if(pref[0][j]>=mod)
pref[0][j]-=mod;
}
for(int j=arr[i];j<=a7a;j++)
{
long long x=getsuml(i-1,j,j);
x*=getsumr(i+1,j,a7a);
x%=mod;
ans+=((hi[j]-hi[arr[i]])*x)%mod;
if(ans>=mod)ans-=mod;
x=getsumr(i+1,j,j);
x*=getsuml(i-1,j+1,a7a);
x%=mod;
ans+=((hi[j]-hi[arr[i]])*x)%mod;
if(ans>=mod)ans-=mod;
if(j>=brr[i])
{
x=getsuml(i-1,j,j);
x*=getsumr(i+1,j,a7a);
x%=mod;
ans+=((hi[j]-hi[brr[i]])*x)%mod;
if(ans>=mod)ans-=mod;
x=getsumr(i+1,j,j);
x*=getsuml(i-1,j+1,a7a);
x%=mod;
ans+=((hi[j]-hi[brr[i]])*x)%mod;
if(ans>=mod)ans-=mod;
}
}
}
// cout<<ans<<endl;
for(int i=1;i<=n;i++)
{
}
cout<<ans<<endl;
}
详细
Subtask #1:
score: 8
Accepted
Test #1:
score: 8
Accepted
time: 0ms
memory: 5636kb
input:
4 1 1 1 1 2 2 2 2
output:
6
result:
ok single line: '6'
Test #2:
score: 8
Accepted
time: 1ms
memory: 5636kb
input:
10 1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1
output:
21116
result:
ok single line: '21116'
Test #3:
score: 8
Accepted
time: 0ms
memory: 3592kb
input:
1 1 2
output:
0
result:
ok single line: '0'
Test #4:
score: 8
Accepted
time: 0ms
memory: 3636kb
input:
2 1 1 2 2
output:
0
result:
ok single line: '0'
Test #5:
score: 8
Accepted
time: 0ms
memory: 3572kb
input:
3 1 1 1 2 2 2
output:
1
result:
ok single line: '1'
Test #6:
score: 8
Accepted
time: 1ms
memory: 5616kb
input:
3 1 1 1 3 2 3
output:
3
result:
ok single line: '3'
Test #7:
score: 8
Accepted
time: 0ms
memory: 5688kb
input:
3 2 1 1 3 2 3
output:
4
result:
ok single line: '4'
Test #8:
score: 8
Accepted
time: 1ms
memory: 5604kb
input:
3 1 1 2 3 2 3
output:
4
result:
ok single line: '4'
Test #9:
score: 8
Accepted
time: 0ms
memory: 5764kb
input:
4 1 1 2 2 2 2 1 1
output:
6
result:
ok single line: '6'
Test #10:
score: 8
Accepted
time: 0ms
memory: 3648kb
input:
3 1 4 4 3 1 1
output:
2
result:
ok single line: '2'
Test #11:
score: 8
Accepted
time: 0ms
memory: 3712kb
input:
20 801072306 297281669 94099424 745640358 822582129 579751930 776707816 425952653 529794053 256263083 615445445 401366545 990263003 967996508 788867983 916880116 837997768 346996508 623409388 122077161 141734988 448434751 822901346 825591177 388082644 468025968 260356829 1164654 537396602 730502935 ...
output:
840988190
result:
ok single line: '840988190'
Test #12:
score: 8
Accepted
time: 1ms
memory: 5764kb
input:
15 792312195 195812430 401437979 703756992 502275277 612055402 556065888 470806179 556125857 640437896 240743729 861383776 500299988 911972088 161499505 167335533 694282920 379241393 144223073 973249939 83979787 962250505 359871412 130233016 655843497 928153117 542969567 974346871 369758881 962874102
output:
617169726
result:
ok single line: '617169726'
Test #13:
score: 8
Accepted
time: 1ms
memory: 7800kb
input:
20 1 1 2 1 1 1 2 2 2 2 2 1 1 1 1 2 2 1 2 1 2 2 1 2 2 2 1 1 1 1 1 2 2 2 2 1 1 2 1 2
output:
8388630
result:
ok single line: '8388630'
Test #14:
score: 8
Accepted
time: 1ms
memory: 5608kb
input:
15 2 1 1 2 1 2 2 1 2 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2 1 2 1 1 2
output:
180241
result:
ok single line: '180241'
Test #15:
score: 8
Accepted
time: 1ms
memory: 5820kb
input:
20 10 3 8 2 5 7 8 3 3 10 5 6 1 2 1 9 10 2 7 10 6 6 2 3 6 10 4 6 7 2 3 3 5 7 2 8 2 1 5 1
output:
78020608
result:
ok single line: '78020608'
Test #16:
score: 8
Accepted
time: 1ms
memory: 5740kb
input:
20 999999992 999999995 999999995 999999998 999999994 999999996 999999992 1000000000 1000000000 999999997 999999999 999999994 999999998 999999992 999999999 1000000000 999999993 999999999 999999996 999999998 999999998 999999998 999999996 999999993 999999996 999999997 1000000000 999999995 999999994 999...
output:
44474368
result:
ok single line: '44474368'
Test #17:
score: 8
Accepted
time: 0ms
memory: 3780kb
input:
20 999999996 10 6 5 4 1 7 9 5 10 1 4 6 3 10 5 3 10 4 999999997 999999997 4 10 7 5 6 2 2 2 7 2 7 3 5 7 1 8 9 2 1000000000
output:
701155847
result:
ok single line: '701155847'
Test #18:
score: 8
Accepted
time: 1ms
memory: 5608kb
input:
11 1 4 2 1 10 6 3 10 1 10 10 6 8 8 7 1 1 1 9 7 9 3
output:
56064
result:
ok single line: '56064'
Test #19:
score: 8
Accepted
time: 1ms
memory: 5820kb
input:
13 999999992 999999993 999999999 999999998 999999994 999999998 999999991 999999991 999999999 999999996 999999994 999999991 999999994 999999994 999999991 999999994 999999997 999999997 1000000000 999999996 999999993 999999992 999999992 999999992 999999998 999999991
output:
184256
result:
ok single line: '184256'
Test #20:
score: 8
Accepted
time: 1ms
memory: 5728kb
input:
17 1000000000 6 4 10 10 4 2 4 10 2 7 1 3 8 4 1 999999996 999999997 3 6 4 3 6 5 10 5 7 6 10 10 7 10 3 999999997
output:
968149511
result:
ok single line: '968149511'
Test #21:
score: 8
Accepted
time: 1ms
memory: 7792kb
input:
20 5 900000001 800000002 700000003 600000004 500000005 10 5 1 100000009 10 3 2 300000007 8 500000005 3 3 800000002 2 1000000000 3 6 6 10 4 400000006 300000007 200000008 1 1 100000009 200000008 5 400000006 4 600000004 700000003 2 900000001
output:
681216662
result:
ok single line: '681216662'
Test #22:
score: 8
Accepted
time: 1ms
memory: 5740kb
input:
19 1000000000 2 777777778 7 555555556 444444445 333333334 222222223 6 4 111111112 222222223 8 444444445 555555556 6 10 888888889 1000000000 3 888888889 3 666666667 6 8 7 10 111111112 1 5 4 333333334 3 4 666666667 777777778 7 4
output:
608096464
result:
ok single line: '608096464'
Subtask #2:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 0ms
memory: 6016kb
input:
100 948 425 211 688 416 81 356 602 712 954 117 522 797 75 281 491 662 669 78 156 939 526 929 937 916 619 166 777 48 898 449 278 298 714 668 755 679 38 389 602 195 135 672 833 655 541 473 27 596 274 351 353 598 993 837 246 950 99 179 751 481 843 550 195 964 279 806 82 330 599 124 756 649 838 513 625 ...
output:
982679529
result:
wrong answer 1st lines differ - expected: '164439470', found: '982679529'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #5:
score: 0
Runtime Error
Test #57:
score: 0
Runtime Error
input:
500000 1 1 1 1 2 2 2 1 1 1 1 1 2 2 1 1 2 2 2 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 2 1 1 2 2 2 2 1 2 2 2 2 1 2 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 2 2 1 1 1 2 2 2 1 1 2 1 2 2 1 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 1 1 1 2 1 2 1 1 2 1 2 1 2 2 1 1 2 1 1 1 1 1 2 2 2 2 2 2 1 2 2 1 1 2 1 2 1...
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%