Submission #667539

#TimeUsernameProblemLanguageResultExecution timeMemory
667539berrFancy Fence (CEOI20_fancyfence)C++17
100 / 100
278 ms7508 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N=1e5+37; int p[N], vis[N], length[N]; int sum, ans=0, mod=1e9+7; int s(int x, int y){ return ((x+y)%mod+mod)%mod; } int mul(int x, int y){ return (x*y)%mod; } int poww(int x, int y){ if(y==0) return 1; int tmp=poww(x, y/2); if(y&1) return mul(tmp, mul(tmp, x)); return mul(tmp, tmp); } int val(int x){ return mul(mul(x, (x+1)), poww(2, mod-2)); } int find(int x){ return (p[x]!=x)?p[x]=find(p[x]):x; } void dsu(int x, int y){ x=find(x); y=find(y); if(x==y) return; sum=s(sum, -val(length[x])); sum=s(sum, -val(length[y])); p[y]=x; length[x]=s(length[x], length[y]); sum=s(sum, val(length[x])); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin>>n; vector<array<int, 3>> a(n+1); for(int i=1; i<=n; i++) p[i]=i; for(int i=0; i<n; i++){ cin>>a[i][0]; a[i][2]=i+1; } for(int i=0; i<n; i++){ cin>>a[i][1]; length[i+1]=a[i][1]; } sort(a.begin(), a.end()); reverse(a.begin(), a.end()); for(int i=0; i<a.size()-1; i++) { int p=a[i][2], len=a[i][1], h=a[i][0]; sum=s(sum, val(length[p])); vis[p]=1; if(vis[p-1]&&vis[p+1]){ dsu(p, p-1); dsu(p, p+1); } else if(vis[p-1]){ dsu(p, p-1); } else if(vis[p+1]){ dsu(p, p+1); } ans=s(ans, mul(sum, s(val(h), -val(a[i+1][0])))); } cout<<ans; }

Compilation message (stderr)

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:71:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for(int i=0; i<a.size()-1; i++)
      |                  ~^~~~~~~~~~~
fancyfence.cpp:73:24: warning: unused variable 'len' [-Wunused-variable]
   73 |         int p=a[i][2], len=a[i][1], h=a[i][0];
      |                        ^~~
#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...