Submission #628742

#TimeUsernameProblemLanguageResultExecution timeMemory
628742a_aguiloFancy Fence (CEOI20_fancyfence)C++14
12 / 100
73 ms316 KiB
#include<bits/stdc++.h> using namespace std; typedef vector<int> vi; const int MOD = 1e9 + 7; void buildTree(int node, int leftBound, int rightBound, vi& arr, vi& tree){ if(leftBound > rightBound) return; if(leftBound == rightBound) { tree[node] = arr[leftBound]; return; } int mid = leftBound + (rightBound - leftBound)/2; buildTree(2*node, leftBound, mid, arr, tree); buildTree(2*node+1, mid+1, rightBound, arr, tree); tree[node] = min(tree[2*node], tree[2*node+1]); } int getValue(int node, int leftBound, int rightBound, int left, int right, vi& tree){ if(left > rightBound or right < leftBound) return 1e9+7; if(left <= leftBound and right >= rightBound)return tree[node]; int mid = leftBound + (rightBound - leftBound)/2; return min(getValue(2*node, leftBound, mid, left, right, tree), getValue(2*node+1, mid+1, rightBound, left, right, tree)); } int main(){ int n; long long W; cin >> n; vi heights(n); vi widths(n); for(int i = 0; i < n; ++i) cin >> heights[i]; for(int i = 0; i < n; ++i)cin >> widths[i]; vi tree(4*n); buildTree(1, 0, n-1, heights, tree); long long ans = 0; for(int i = 0; i < n; ++i){ for(int j = i; j < n; ++j){ int H = getValue(1, 0, n-1, i, j, tree); //cout << i << " " << j << " " << H << " " << W << endl; long long chooseh = (H*(H+1)/2)%MOD; long long choosew; if(i == j) choosew = (widths[i]*(widths[i]+1)/2)%MOD; else choosew = (widths[i]*widths[j])%MOD; ans += (chooseh*choosew)%MOD; ans%=MOD; } } cout << ans << endl; return 0; }

Compilation message (stderr)

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:29:15: warning: unused variable 'W' [-Wunused-variable]
   29 |     long long W;
      |               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...