# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
974832 | 2024-05-03T21:05:46 Z | imarn | Fancy Fence (CEOI20_fancyfence) | C++14 | 29 ms | 5204 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); 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;sz[i]%=inf; ans+=(c(sz[i])*c(it.f))%inf; if(pr[it.s.s-1]&&get(it.s.s-1)!=get(i)){ int u=get(it.s.s-1); ans-=((c(sz[u])*c(it.f))%inf+(c(sz[i])*c(it.f))%inf)%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]&&get(it.s.s+1)!=get(i)){ int u=get(it.s.s+1); ans-=((c(sz[u])*c(it.f))%inf+(c(sz[i])*c(it.f))%inf)%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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 12 ms | 2200 KB | Output is correct |
4 | Correct | 24 ms | 3932 KB | Output is correct |
5 | Correct | 24 ms | 3932 KB | Output is correct |
6 | Correct | 24 ms | 3928 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 600 KB | Output is correct |
2 | Correct | 3 ms | 604 KB | Output is correct |
3 | Correct | 14 ms | 1576 KB | Output is correct |
4 | Correct | 29 ms | 2668 KB | Output is correct |
5 | Correct | 27 ms | 2664 KB | Output is correct |
6 | Correct | 0 ms | 344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 3 ms | 604 KB | Output is correct |
4 | Correct | 13 ms | 1576 KB | Output is correct |
5 | Correct | 27 ms | 2676 KB | Output is correct |
6 | Correct | 27 ms | 2676 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 3 ms | 604 KB | Output is correct |
9 | Correct | 13 ms | 1628 KB | Output is correct |
10 | Correct | 18 ms | 2680 KB | Output is correct |
11 | Correct | 19 ms | 2640 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 600 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 1 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 472 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 600 KB | Output is correct |
11 | Correct | 12 ms | 2204 KB | Output is correct |
12 | Correct | 25 ms | 3932 KB | Output is correct |
13 | Correct | 27 ms | 3924 KB | Output is correct |
14 | Correct | 24 ms | 3832 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 3 ms | 884 KB | Output is correct |
17 | Correct | 14 ms | 2456 KB | Output is correct |
18 | Correct | 28 ms | 4700 KB | Output is correct |
19 | Correct | 28 ms | 4692 KB | Output is correct |
20 | Correct | 1 ms | 348 KB | Output is correct |
21 | Correct | 2 ms | 860 KB | Output is correct |
22 | Correct | 13 ms | 2396 KB | Output is correct |
23 | Correct | 20 ms | 4452 KB | Output is correct |
24 | Correct | 23 ms | 4568 KB | Output is correct |
25 | Correct | 0 ms | 344 KB | Output is correct |
26 | Correct | 0 ms | 348 KB | Output is correct |
27 | Correct | 1 ms | 348 KB | Output is correct |
28 | Correct | 1 ms | 348 KB | Output is correct |
29 | Correct | 1 ms | 348 KB | Output is correct |
30 | Correct | 3 ms | 860 KB | Output is correct |
31 | Correct | 3 ms | 860 KB | Output is correct |
32 | Correct | 14 ms | 2392 KB | Output is correct |
33 | Correct | 13 ms | 2396 KB | Output is correct |
34 | Correct | 26 ms | 4316 KB | Output is correct |
35 | Correct | 28 ms | 4436 KB | Output is correct |
36 | Correct | 27 ms | 4696 KB | Output is correct |
37 | Correct | 27 ms | 4692 KB | Output is correct |
38 | Correct | 0 ms | 348 KB | Output is correct |
39 | Correct | 27 ms | 4692 KB | Output is correct |
40 | Correct | 24 ms | 4700 KB | Output is correct |
41 | Correct | 22 ms | 4692 KB | Output is correct |
42 | Correct | 23 ms | 5204 KB | Output is correct |