Submission #628803

#TimeUsernameProblemLanguageResultExecution timeMemory
628803a_aguiloFancy Fence (CEOI20_fancyfence)C++14
30 / 100
1087 ms1956 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 or leftBound > rightBound) 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, 1e9+7); 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 = ((long long)H*(H+1)/2)%MOD; long long choosew; if(i == j) choosew = (((long long)widths[i]*(widths[i]+1))/2)%MOD; else choosew = ((long long)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...