Submission #974829

#TimeUsernameProblemLanguageResultExecution timeMemory
974829imarnFancy Fence (CEOI20_fancyfence)C++14
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> #define f first #define s second #define pb push_back #define pii pair<int,int> #define ll long long #define sz(x) (ll)x.size() #define pp pair<int,pii> using namespace std; const int mxn=1e5+5,inf=1e9+7; int pr[mxn]{0}; ll sz[mxn]{0}; int get(int r){ return pr[r]==r?r:pr[r]=get(pr[r]); } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);ll ans=0; int n;cin>>n;vector<pp>v(n);iota(pr,pr+n+1,0); for(int i=0;i<n;i++)cin>>v[i].f,v[i].s.s=i+1; for(int i=0;i<n;i++)cin>>v[i].s.f;sort(v.begin(),v.end(),greater<pp>()); for(auto it : v){int i=it.s.s;pr[i]=i;sz[i]=it.s.f; ans+=sz[i]*(sz[i]+1)/2*(it.f+1)*(it.f)/2; if(pr[it.s.s-1]){ int u=get(it.s.s-1); ans-=(sz[u]+1)*(sz[u])/2*(it.f+1)*(it.f)/2+(sz[i]+1)*(sz[i])/2*(it.f+1)*(it.f)/2; sz[i]+=sz[u]; pr[u]=i; ans+=(sz[i]+1)*(sz[i])/2*(it.f+1)*(it.f)/2; } if(pr[it.s.s+1]){ int u=get(it.s.s+1); ans-=(sz[u]+1)*(sz[u])/2*(it.f+1)*(it.f)/2+(sz[i]+1)*(sz[i])/2*(it.f+1)*(it.f)/2; sz[i]+=sz[u]; pr[u]=i; ans+=(sz[i]+1)*(sz[i])/2*(it.f+1)*(it.f)/2; } }cout<<ans; }

Compilation message (stderr)

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:20:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   20 |     for(int i=0;i<n;i++)cin>>v[i].s.f;sort(v.begin(),v.end(),greater<pp>());
      |     ^~~
fancyfence.cpp:20:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   20 |     for(int i=0;i<n;i++)cin>>v[i].s.f;sort(v.begin(),v.end(),greater<pp>());
      |                                       ^~~~
#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...