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;
#define int long long
const int mod=1e9+7;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> h(n);
map<int,int> ind; int x=1;
vector<pair<int, vector<int> > >sorted;
sorted.push_back({0, {}});
for(int i=0; i<n; i++){
cin >> h[i];
if(ind[h[i]]==0){
sorted.push_back({h[i], {}});
ind[h[i]]=x;
x++;
}
sorted[ind[h[i]]].second.push_back(i);
}
sort(sorted.begin(), sorted.end());
reverse(sorted.begin(), sorted.end());
vector<int> w(n);
for(int i=0; i<n; i++){
cin >> w[i];
}
vector<int> a(n+1);
int ans=0;
for(int i=0; i<n; i++){
int h=sorted[i].first;
int next=sorted[i+1].first;
vector<int> ele=sorted[i].second;
/*cout << h << " " << next << "\n";
for(auto e: ele){
a[e]=w[e];
cout << e << " ";
}
cout << "\n";*/
int s=0; int mom=0;
for(int j=0; j<=n; j++){
if(a[j]==0){
s+=((mom*(mom+1))/2)%mod;
mom=0;
}
mom+=a[j];
}
int factor=((h*(h+1))/2 - (next*(next+1))/2)%mod;
ans+=(s*factor)%mod;
}
cout << ans << "\n";
}
# | 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... |