This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
long long h[100005];
long long w[100005];
long long md=1e9+7;
struct block{
long long h,w;
block(long long hh=0,long long ww=0){
h=hh;
w=ww;
}
};
long long calc(block x){
long long ans=x.h*(x.h+1)/2;
ans%=md;
long long ans1=x.w*(x.w+1)/2;
ans1%=md;
long long ans2=(ans*ans1)%md;
return ans2;
}
vector<long long>v;
vector<block>info;
vector<block>tmp;
map<int,int>mp;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>h[i];
if(mp[h[i]]==0){
mp[h[i]]=1;
v.push_back(h[i]);
//cout<<h[i]<<endl;
}
}
//cout<<endl;
//cout<<v.size()<<endl;
sort(v.begin(),v.end(),greater<int>());
for(int i=1;i<=n;i++){
cin>>w[i];
}
long long ans=0;
/*for(int i=0;i<v.size();i++){
cout<<v[i]<<endl;
}
cout<<endl;*/
for(int i=1;i<=n;i++){
info.push_back(block(h[i],w[i]));
}
for(int i=0;i<v.size();i++){
long long h=v[i];
tmp.clear();
//cout<<h<<":"<<endl;
for(int j=0;j<info.size();j++){
if(info[j].h>=h){
if(i!=0&&info[j-1].h>=h){
block z=tmp.back();
tmp.pop_back();
tmp.push_back(block(h,z.w+info[j].w));
}else{
tmp.push_back(block(h,info[j].w));
}
}else{
tmp.push_back(info[j]);
}
}
//cout<<"blocks"<<endl;
for(int j=0;j<tmp.size();j++){
//cout<<tmp[j].h<<" "<<tmp[j].w<<endl;
if(tmp[j].h>=h){
ans+=calc(tmp[j]);
ans%=md;
}
}
for(int j=0;j<info.size();j++){
if(info[j].h>h){
ans+=md;
ans-=calc(block(h,info[j].w));
ans%=md;
}
}
//cout<<"ans:"<<ans<<endl;
info.clear();
for(int i=0;i<tmp.size();i++){
info.push_back(tmp[i]);
}
}
cout<<ans;
}
Compilation message (stderr)
fancyfence.cpp: In function 'int main()':
fancyfence.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
fancyfence.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<block>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int j=0;j<info.size();j++){
| ~^~~~~~~~~~~~
fancyfence.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<block>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int j=0;j<tmp.size();j++){
| ~^~~~~~~~~~~
fancyfence.cpp:77:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<block>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int j=0;j<info.size();j++){
| ~^~~~~~~~~~~~
fancyfence.cpp:86:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<block>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(int i=0;i<tmp.size();i++){
| ~^~~~~~~~~~~
# | 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... |