# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
498637 | RambaXGorilla | Fancy Fence (CEOI20_fancyfence) | C++17 | 38 ms | 5208 KiB |
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<cstdio>
#include<algorithm>
#include<utility>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair <int,int> ii;
#define pq priority_queue
const int modNum = 1000000007;
int N;
int heights[100010];
int widths[100010];
ll prefs[100010];
int smaller[100010];
pq <ii> big;
int form(ll a, ll b){
ll nums[] = {a, b, a + 1, b + 1};
for(int i = 0;i < 4;i++){
if(!(nums[i] % 2)){
nums[i] /= 2;
}
nums[i] %= modNum;
}
ll prod = 1;
for(int i = 0;i < 4;i++){
prod *= nums[i];
prod %= modNum;
}
return prod;
}
int main(){
scanf("%d",&N);
for(int i = 0;i < N;i++){
scanf("%d",&heights[i]);
}
heights[N] = 0;
prefs[0] = 0;
for(int i = 0;i < N;i++){
scanf("%d",&widths[i]);
prefs[i + 1] = prefs[i] + widths[i];
}
for(int i = 0;i < N + 1;i++){
while(!big.empty() && big.top().first > heights[i]){
smaller[big.top().second] = i;
big.pop();
}
big.push(ii(heights[i], i));
}
int total = 0;
for(int i = 0;i < N;i++){
int bott = 0;
if(i > 0){
bott = heights[i - 1];
}
int curr = i;
int last;
while(curr < N){
last = curr;
curr = smaller[curr];
if(heights[last] <= bott){
break;
}
total += (form(heights[last], prefs[curr] - prefs[i]) - form(max(heights[curr], bott), prefs[curr] - prefs[i]) + modNum) % modNum;
total %= modNum;
}
}
printf("%d",total);
}
Compilation message (stderr)
# | 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... |