# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
902517 | 2024-01-10T14:25:48 Z | KN200711 | Fancy Fence (CEOI20_fancyfence) | C++14 | 1 ms | 500 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; 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.fi; 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); } printf("%lld\n", ans[find(0)]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Incorrect | 1 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Incorrect | 1 ms | 448 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Incorrect | 1 ms | 500 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Incorrect | 1 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Incorrect | 1 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |