# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
876234 | 2023-11-21T13:05:58 Z | Huy | Fancy Fence (CEOI20_fancyfence) | C++17 | 56 ms | 11996 KB |
#include<bits/stdc++.h> #define int long long #define pii pair<ll,ll> #define fi first #define se second #pragma GCC tarGet ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC tarGet("avx,avx2,fma") using namespace std; using ll = long long; using ull = unsigned long long; using ldb = long double; const int N = 1e5; const int maxN = 2e5 + 1; const ll mod = 1e9 + 7; const int block_size = 708; const ll infty = 1e18; const double ep = 1e-7; const int base = 200003; void InputFile() { //freopen(".in","r",stdin); //freopen(".out","w",stdout); freopen("test.out","r",stdin); } int n; int h[maxN]; int w[maxN]; int prew[maxN]; int id[maxN]; int L[maxN]; int R[maxN]; bool FA(int i,int j) { return (h[i] < h[j]) || (h[i] == h[j] && L[i] < L[j]); } ll power(int a,int b) { if(b == 0) return 1; ll t = power(a,b/2); if(b % 2) { return t * t % mod * a % mod; } return t * t % mod; } ll C2(ll w) { return (w % mod * ((w + 1) % mod) % mod * power(2,mod-2) % mod ); } void Read() { cin >> n; for(int i = 1; i <= n; i++) { cin >> h[i]; id[i] = i; } for(int i = 1; i <= n; i++) { cin >> w[i]; prew[i] = prew[i-1] + w[i]; } vector<int> vc; for(int i = 1; i <= n; i++) { while(!vc.empty() && h[vc.back()] >= h[i]) { vc.pop_back(); } if(vc.empty()) L[i] = 0; else L[i] = vc.back(); vc.push_back(i); } vc.clear(); for(int i = n; i >= 1; i--) { while(!vc.empty() && h[vc.back()] >= h[i]) { vc.pop_back(); } if(vc.empty()) R[i] = n + 1; else R[i] = vc.back(); vc.push_back(i); } sort(id + 1,id + n + 1,FA); ll res = 0; for(int i = 1; i <= n; i++) { if(h[id[i]] == h[id[i-1]] && L[id[i]] == L[id[i-1]]) continue; //cout << id[i] <<' '; ll need_w = prew[R[id[i]]-1] - prew[L[id[i]]]; ll pp = max(h[L[id[i]]],h[R[id[i]]]); ll thua = h[id[i]] - pp; ll add = (C2(thua) + thua * pp % mod) % mod * C2(need_w) % mod ; res = (res + add) % mod; } cout << res; //cout << C2(3); } void Solve() { } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //InputFile(); //int sub_type; //cin >> sub_type; //Sieve(); int test; //cin >> test; test = 1; while(test--) //for(int prc = 1; prc <= test; prc++) { Read(); Solve(); //Debug(); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 8540 KB | Output is correct |
2 | Correct | 2 ms | 8540 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 8540 KB | Output is correct |
2 | Correct | 1 ms | 8540 KB | Output is correct |
3 | Correct | 1 ms | 8916 KB | Output is correct |
4 | Correct | 1 ms | 8540 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 8536 KB | Output is correct |
2 | Correct | 2 ms | 8536 KB | Output is correct |
3 | Correct | 13 ms | 9560 KB | Output is correct |
4 | Correct | 22 ms | 10076 KB | Output is correct |
5 | Correct | 28 ms | 10068 KB | Output is correct |
6 | Correct | 21 ms | 10076 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 8536 KB | Output is correct |
2 | Correct | 3 ms | 8796 KB | Output is correct |
3 | Correct | 10 ms | 9796 KB | Output is correct |
4 | Correct | 21 ms | 10844 KB | Output is correct |
5 | Correct | 20 ms | 11092 KB | Output is correct |
6 | Correct | 1 ms | 8536 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 8536 KB | Output is correct |
2 | Correct | 1 ms | 8536 KB | Output is correct |
3 | Correct | 3 ms | 8796 KB | Output is correct |
4 | Correct | 12 ms | 9804 KB | Output is correct |
5 | Correct | 20 ms | 10924 KB | Output is correct |
6 | Correct | 20 ms | 11092 KB | Output is correct |
7 | Correct | 2 ms | 8540 KB | Output is correct |
8 | Correct | 6 ms | 9064 KB | Output is correct |
9 | Correct | 16 ms | 10052 KB | Output is correct |
10 | Correct | 42 ms | 11732 KB | Output is correct |
11 | Correct | 41 ms | 11900 KB | Output is correct |
12 | Correct | 1 ms | 8536 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 8536 KB | Output is correct |
2 | Correct | 1 ms | 8660 KB | Output is correct |
3 | Correct | 1 ms | 8540 KB | Output is correct |
4 | Correct | 1 ms | 8656 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
6 | Correct | 1 ms | 8540 KB | Output is correct |
7 | Correct | 1 ms | 8540 KB | Output is correct |
8 | Correct | 2 ms | 8540 KB | Output is correct |
9 | Correct | 1 ms | 8540 KB | Output is correct |
10 | Correct | 1 ms | 8540 KB | Output is correct |
11 | Correct | 1 ms | 8540 KB | Output is correct |
12 | Correct | 1 ms | 8540 KB | Output is correct |
13 | Correct | 1 ms | 8540 KB | Output is correct |
14 | Correct | 2 ms | 8672 KB | Output is correct |
15 | Correct | 2 ms | 8540 KB | Output is correct |
16 | Correct | 1 ms | 8664 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 8540 KB | Output is correct |
2 | Correct | 2 ms | 8540 KB | Output is correct |
3 | Correct | 1 ms | 8540 KB | Output is correct |
4 | Correct | 2 ms | 8540 KB | Output is correct |
5 | Correct | 1 ms | 8664 KB | Output is correct |
6 | Correct | 1 ms | 8664 KB | Output is correct |
7 | Correct | 1 ms | 8536 KB | Output is correct |
8 | Correct | 1 ms | 8540 KB | Output is correct |
9 | Correct | 1 ms | 8668 KB | Output is correct |
10 | Correct | 1 ms | 8540 KB | Output is correct |
11 | Correct | 13 ms | 9308 KB | Output is correct |
12 | Correct | 25 ms | 10076 KB | Output is correct |
13 | Correct | 25 ms | 10076 KB | Output is correct |
14 | Correct | 21 ms | 10160 KB | Output is correct |
15 | Correct | 1 ms | 8540 KB | Output is correct |
16 | Correct | 3 ms | 8792 KB | Output is correct |
17 | Correct | 11 ms | 9564 KB | Output is correct |
18 | Correct | 22 ms | 10804 KB | Output is correct |
19 | Correct | 20 ms | 11096 KB | Output is correct |
20 | Correct | 1 ms | 8540 KB | Output is correct |
21 | Correct | 5 ms | 9052 KB | Output is correct |
22 | Correct | 15 ms | 10060 KB | Output is correct |
23 | Correct | 42 ms | 11696 KB | Output is correct |
24 | Correct | 42 ms | 11996 KB | Output is correct |
25 | Correct | 1 ms | 8540 KB | Output is correct |
26 | Correct | 1 ms | 8540 KB | Output is correct |
27 | Correct | 1 ms | 8540 KB | Output is correct |
28 | Correct | 2 ms | 8536 KB | Output is correct |
29 | Correct | 2 ms | 8540 KB | Output is correct |
30 | Correct | 6 ms | 8796 KB | Output is correct |
31 | Correct | 6 ms | 8864 KB | Output is correct |
32 | Correct | 25 ms | 9564 KB | Output is correct |
33 | Correct | 24 ms | 9640 KB | Output is correct |
34 | Correct | 56 ms | 10944 KB | Output is correct |
35 | Correct | 49 ms | 10576 KB | Output is correct |
36 | Correct | 50 ms | 10832 KB | Output is correct |
37 | Correct | 54 ms | 11000 KB | Output is correct |
38 | Correct | 1 ms | 8536 KB | Output is correct |
39 | Correct | 51 ms | 11000 KB | Output is correct |
40 | Correct | 49 ms | 10844 KB | Output is correct |
41 | Correct | 44 ms | 10956 KB | Output is correct |
42 | Correct | 41 ms | 11476 KB | Output is correct |