답안 #465837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465837 2021-08-16T21:21:06 Z ivan_tudor Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
78 ms 5316 KB
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
const unsigned long long N = 1e5+5;
unsigned long long lgcput(unsigned long long b,unsigned long long p){
  unsigned long long a = 1;
  while(p){
    if(p & 1){
      a *= b;
      a%=MOD;
    }
    b*=b;
    b%=MOD;
    p/=2;
  }
  return a;
}
unsigned long long cost(unsigned long long n){
  return ((unsigned long long)(((unsigned long long)(n *(n+1)))%MOD) *(lgcput(2,MOD-2) % MOD)) %MOD ;
}
struct drept{
  unsigned long long h,w;
};
drept v[N];
unsigned long long stk[N];
 
unsigned long long nwc[N];
int main()
{
  //freopen(".in","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0),cout.tie(0);
  unsigned long long n;
  cin>>n;
  for(unsigned long long i =1;i<=n;i++){
    cin>>v[i].h;
  }
  for(unsigned long long i=1;i<=n;i++){
    cin>>v[i].w;
  }
  unsigned long long ans = 0;
  unsigned long long nw = 0;
  unsigned long long vf = 0;
  nwc[0] = 0;
  for(unsigned long long i=1;i<=n;i++){
    unsigned long long dlted = 0;
    while(vf>0 && v[stk[vf]].h >= v[i].h){
      dlted += v[stk[vf]].w;
      dlted %= MOD;
      v[i].w %=MOD;
      vf--;
    }
    nw = ((unsigned long long)nwc[stk[vf]] + ((unsigned long long)cost(v[i].h) * dlted)%MOD ) %MOD;
    ans += ((unsigned long long) nw * v[i].w)%MOD;
    ans %= MOD;
    ans += ((unsigned long long)cost(v[i].h) * cost(v[i].w)) % MOD;
    ans %= MOD;
    nw  += ((unsigned long long) cost(v[i].h) * v[i].w) % MOD;
    nw %= MOD;
    nwc[i] = nw;
    stk[++vf] = i;
    v[i].w += dlted;
    v[i].w%=MOD;
  }
  cout<<ans;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 33 ms 2076 KB Output is correct
4 Correct 67 ms 3784 KB Output is correct
5 Correct 66 ms 3776 KB Output is correct
6 Correct 67 ms 3772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 8 ms 716 KB Output is correct
3 Correct 36 ms 2372 KB Output is correct
4 Correct 73 ms 4552 KB Output is correct
5 Correct 74 ms 4672 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 8 ms 716 KB Output is correct
4 Correct 36 ms 2372 KB Output is correct
5 Correct 71 ms 4536 KB Output is correct
6 Correct 74 ms 4680 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 8 ms 716 KB Output is correct
9 Correct 37 ms 2528 KB Output is correct
10 Correct 71 ms 5152 KB Output is correct
11 Correct 73 ms 5316 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 35 ms 2068 KB Output is correct
12 Correct 68 ms 3792 KB Output is correct
13 Correct 67 ms 3780 KB Output is correct
14 Correct 67 ms 3784 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 8 ms 740 KB Output is correct
17 Correct 36 ms 2428 KB Output is correct
18 Correct 72 ms 4548 KB Output is correct
19 Correct 78 ms 4824 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 8 ms 848 KB Output is correct
22 Correct 37 ms 2532 KB Output is correct
23 Correct 71 ms 5268 KB Output is correct
24 Correct 72 ms 5248 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 8 ms 708 KB Output is correct
31 Correct 8 ms 692 KB Output is correct
32 Correct 37 ms 2384 KB Output is correct
33 Correct 36 ms 2372 KB Output is correct
34 Correct 72 ms 4392 KB Output is correct
35 Correct 72 ms 4316 KB Output is correct
36 Correct 72 ms 4556 KB Output is correct
37 Correct 72 ms 4548 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 71 ms 4516 KB Output is correct
40 Correct 72 ms 4588 KB Output is correct
41 Correct 72 ms 4560 KB Output is correct
42 Correct 72 ms 4864 KB Output is correct