답안 #1106830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106830 2024-10-31T07:29:46 Z sinataghizadeh Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
72 ms 11120 KB
#include <bits/stdc++.h>
using namespace std;


typedef long long       ll;
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pll;
#define all(x)			(x).begin(),(x).end()
#define pb    			push_back
#define fi              first
#define se              second
#define mp make_pair
#define beg             begin
#define siz              size()
#define fastio          cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false);
#define endl       		'\n'
#define ins             insert
#define log             LOG
const ll inf = 1e18;
const ll mod = 1e9+7;
const int maxn=1e6+44;
const int log=24;
const int delta=229939;
ll n;

int main(){
	fastio
    cin>>n;
    vector<ll>prefix(n+1);
    vector<ll>H(n+1),W(n+1);
    ll res=0;
    for(ll i=1;i<=n;i++) {
        cin>>H[i];
    }
    for(ll i=1;i<=n;i++) {
        cin>>W[i];
        prefix[i]=prefix[i-1]+W[i];
    }
   vector<pair<ll,ll>>v(n);
   set<ll>s;
   for(ll i=1;i<=n;i++) {
    s.insert(i);
    v[i-1]=mp(H[i],i);
   }
   sort(v.rbegin(),v.rend());
   s.insert(0);
   s.insert(n+1);
   for(ll t=0;t<n;t++) {
        ll index=v[t].second;
        s.erase(index);
        auto it= s.upper_bound(index);
        ll wd = prefix[*it-1]-prefix[index];
        it=prev(it,1);
        ll ws = prefix[index-1]-prefix[*it];
        wd%=mod;
        ws%=mod;
        ll w = W[index];
        ll h = H[index];
        ll sum=h*(h+(ll)1)/(ll)2;
        ll sumw=w*(w+(ll)1)/(ll)2;
        sum%=mod;
        sumw%=mod;
        ll toadd=0;
        toadd+=(ws*w)%mod;
        toadd%=mod;
        toadd+=(wd*w)%mod;
        toadd%=mod;
        toadd+=(wd*ws)%mod;toadd%=mod;
        toadd+=sumw;toadd%=mod;
        toadd*=sum;toadd%=mod;
        res+=toadd;
        res%=mod;
   }    
	cout<<res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 22 ms 5352 KB Output is correct
4 Correct 45 ms 10056 KB Output is correct
5 Correct 46 ms 10124 KB Output is correct
6 Correct 41 ms 10064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 5 ms 1360 KB Output is correct
3 Correct 33 ms 5684 KB Output is correct
4 Correct 42 ms 10948 KB Output is correct
5 Correct 42 ms 11120 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 4 ms 1528 KB Output is correct
4 Correct 20 ms 5712 KB Output is correct
5 Correct 45 ms 10868 KB Output is correct
6 Correct 48 ms 11096 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 4 ms 1360 KB Output is correct
9 Correct 22 ms 5596 KB Output is correct
10 Correct 42 ms 10824 KB Output is correct
11 Correct 46 ms 10932 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 21 ms 5356 KB Output is correct
12 Correct 46 ms 10056 KB Output is correct
13 Correct 43 ms 10064 KB Output is correct
14 Correct 41 ms 10068 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 1492 KB Output is correct
17 Correct 20 ms 5716 KB Output is correct
18 Correct 53 ms 10956 KB Output is correct
19 Correct 48 ms 11080 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 4 ms 1360 KB Output is correct
22 Correct 20 ms 5744 KB Output is correct
23 Correct 41 ms 10828 KB Output is correct
24 Correct 41 ms 10824 KB Output is correct
25 Correct 1 ms 504 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 6 ms 1360 KB Output is correct
31 Correct 6 ms 1360 KB Output is correct
32 Correct 31 ms 5624 KB Output is correct
33 Correct 33 ms 5704 KB Output is correct
34 Correct 71 ms 10576 KB Output is correct
35 Correct 69 ms 10568 KB Output is correct
36 Correct 72 ms 10832 KB Output is correct
37 Correct 71 ms 10824 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 68 ms 10992 KB Output is correct
40 Correct 55 ms 11000 KB Output is correct
41 Correct 47 ms 10848 KB Output is correct
42 Correct 39 ms 10832 KB Output is correct