# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
902701 | 2024-01-11T00:37:24 Z | KN200711 | Fancy Fence (CEOI20_fancyfence) | C++14 | 49 ms | 5948 KB |
# include <bits/stdc++.h> # define ll long long # define ld long double # define fi first # define se second # define pll pair<ll, ll> # define pdd pair<ld, ld> # define pii pair<int, int> using namespace std; const ll MOD = 1e9 + 7; int par[100001]; ll sz[100001], ans[100001]; ll C2(int a) { ll v = a * (a + 1ll) / 2ll; v %= MOD; return v; } int find(int a) { if(a == par[a]) return a; par[a] = find(par[a]); return par[a]; } void merge(int a, int b, ll c) { a = find(a); b = find(b); if(a == b) return; ans[a] += ans[b]; ans[a] %= MOD; ll G = C2(c) * (C2(sz[a]) + C2(sz[b])); G %= MOD; par[b] = a; sz[a] += sz[b]; sz[a] %= MOD; ans[a] -= G; ans[a] %= MOD; G = C2(c) * (C2(sz[a])); G %= MOD; ans[a] += G; ans[a] %= MOD; } bool vis[100001]; int main() { int N; scanf("%d", &N); vector<pair<pii, int> > arr(N); for(int i=0;i<N;i++) { par[i] = i; scanf("%d", &arr[i].fi.fi); } for(int i=0;i<N;i++) { scanf("%d", &arr[i].fi.se); ans[i] = C2(arr[i].fi.fi) * C2(arr[i].fi.se); sz[i] = arr[i].fi.se; ans[i] %= MOD; arr[i].se = i; } sort(arr.begin(), arr.end()); for(int i=N-1;i>=0;i--) { int idx = arr[i].se; vis[idx] = 1; if(idx > 0 && vis[idx - 1]) merge(idx - 1, idx, arr[i].fi.fi); if(idx + 1 < N && vis[idx + 1]) merge(idx + 1, idx, arr[i].fi.fi); } if(ans[find(0)] < 0) ans[find(0)] += MOD; printf("%lld\n", ans[find(0)]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 360 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 360 KB | Output is correct |
2 | Correct | 1 ms | 360 KB | Output is correct |
3 | Correct | 0 ms | 452 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 360 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 360 KB | Output is correct |
2 | Correct | 1 ms | 360 KB | Output is correct |
3 | Correct | 22 ms | 2648 KB | Output is correct |
4 | Correct | 30 ms | 4808 KB | Output is correct |
5 | Correct | 43 ms | 4708 KB | Output is correct |
6 | Correct | 31 ms | 4756 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 516 KB | Output is correct |
2 | Correct | 4 ms | 872 KB | Output is correct |
3 | Correct | 20 ms | 2904 KB | Output is correct |
4 | Correct | 33 ms | 5456 KB | Output is correct |
5 | Correct | 35 ms | 5624 KB | Output is correct |
6 | Correct | 1 ms | 356 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 356 KB | Output is correct |
2 | Correct | 1 ms | 460 KB | Output is correct |
3 | Correct | 3 ms | 860 KB | Output is correct |
4 | Correct | 22 ms | 3000 KB | Output is correct |
5 | Correct | 33 ms | 5364 KB | Output is correct |
6 | Correct | 33 ms | 5948 KB | Output is correct |
7 | Correct | 1 ms | 356 KB | Output is correct |
8 | Correct | 3 ms | 868 KB | Output is correct |
9 | Correct | 22 ms | 2908 KB | Output is correct |
10 | Correct | 23 ms | 5468 KB | Output is correct |
11 | Correct | 23 ms | 5480 KB | Output is correct |
12 | Correct | 1 ms | 360 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 360 KB | Output is correct |
2 | Correct | 1 ms | 360 KB | Output is correct |
3 | Correct | 1 ms | 616 KB | Output is correct |
4 | Correct | 0 ms | 360 KB | Output is correct |
5 | Correct | 1 ms | 360 KB | Output is correct |
6 | Correct | 0 ms | 360 KB | Output is correct |
7 | Correct | 1 ms | 360 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 504 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 516 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 1 ms | 360 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 | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 360 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 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 | 1 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 19 ms | 2816 KB | Output is correct |
12 | Correct | 46 ms | 4644 KB | Output is correct |
13 | Correct | 30 ms | 4728 KB | Output is correct |
14 | Correct | 45 ms | 4728 KB | Output is correct |
15 | Correct | 1 ms | 344 KB | Output is correct |
16 | Correct | 4 ms | 860 KB | Output is correct |
17 | Correct | 16 ms | 2992 KB | Output is correct |
18 | Correct | 38 ms | 5464 KB | Output is correct |
19 | Correct | 41 ms | 5464 KB | Output is correct |
20 | Correct | 1 ms | 348 KB | Output is correct |
21 | Correct | 3 ms | 968 KB | Output is correct |
22 | Correct | 20 ms | 2868 KB | Output is correct |
23 | Correct | 22 ms | 5408 KB | Output is correct |
24 | Correct | 24 ms | 5504 KB | Output is correct |
25 | Correct | 1 ms | 344 KB | Output is correct |
26 | Correct | 1 ms | 348 KB | Output is correct |
27 | Correct | 1 ms | 348 KB | Output is correct |
28 | Correct | 1 ms | 496 KB | Output is correct |
29 | Correct | 1 ms | 464 KB | Output is correct |
30 | Correct | 4 ms | 856 KB | Output is correct |
31 | Correct | 3 ms | 860 KB | Output is correct |
32 | Correct | 15 ms | 2904 KB | Output is correct |
33 | Correct | 19 ms | 3000 KB | Output is correct |
34 | Correct | 34 ms | 5236 KB | Output is correct |
35 | Correct | 48 ms | 5200 KB | Output is correct |
36 | Correct | 46 ms | 5460 KB | Output is correct |
37 | Correct | 49 ms | 5460 KB | Output is correct |
38 | Correct | 0 ms | 348 KB | Output is correct |
39 | Correct | 32 ms | 5388 KB | Output is correct |
40 | Correct | 45 ms | 5460 KB | Output is correct |
41 | Correct | 28 ms | 5604 KB | Output is correct |
42 | Correct | 23 ms | 5468 KB | Output is correct |