# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
974830 | 2024-05-03T21:02:01 Z | imarn | Fancy Fence (CEOI20_fancyfence) | C++14 | 1 ms | 600 KB |
#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]); } ll c(ll x){ return ((x*(x+1))/2)%inf; } 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+=(c(sz[i])*c(it.f))%inf; if(pr[it.s.s-1]){ int u=get(it.s.s-1); ans-=(c(sz[u])*c(it.f))%inf+(c(sz[i])*c(it.f))%inf;ans%=inf; sz[i]+=sz[u];sz[i]%=inf; pr[u]=i; ans+=(c(sz[i])*c(it.f))%inf;ans%=inf; } if(pr[it.s.s+1]){ int u=get(it.s.s+1); ans-=(c(sz[u])*c(it.f))%inf+(c(sz[i])*c(it.f))%inf;ans%=inf; sz[i]+=sz[u];sz[i]%=inf; pr[u]=i; ans+=(c(sz[i])*c(it.f))%inf;ans%=inf; } }cout<<(ans%inf+inf)%inf; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Incorrect | 1 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Incorrect | 1 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 600 KB | Output is correct |
2 | Incorrect | 1 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Incorrect | 1 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Incorrect | 1 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |