Submission #902701

#TimeUsernameProblemLanguageResultExecution timeMemory
902701KN200711Fancy Fence (CEOI20_fancyfence)C++14
100 / 100
49 ms5948 KiB
# 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 (stderr)

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
fancyfence.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |   scanf("%d", &arr[i].fi.fi);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~
fancyfence.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   scanf("%d", &arr[i].fi.se);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...