Submission #943120

#TimeUsernameProblemLanguageResultExecution timeMemory
943120shoryu386Fancy Fence (CEOI20_fancyfence)C++17
12 / 100
1 ms2396 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define MAX 100007 #define MOD 1000000007 tuple<int, int, int> hw[MAX]; int p[MAX]; int sumsz[MAX]; int storeSqrSum = 0; int compute(int x){ return ( (x * (x+1))/2 ) %MOD; } void activate(int a){ sumsz[a] = get<1>(hw[a]); storeSqrSum += compute(get<1>(hw[a])); storeSqrSum %= MOD; } int root(int a){ if (a == p[a]) return a; return p[a] = root(p[a]); } void merge(int a, int b){ a = root(a); b = root(b); if (a == b) return; p[a] = b; storeSqrSum -= compute(sumsz[a]); storeSqrSum += MOD; storeSqrSum %= MOD; storeSqrSum -= compute(sumsz[b]); storeSqrSum += MOD; storeSqrSum %= MOD; sumsz[b] += sumsz[a]; //sumsz[b] %= MOD; //???????????????????? storeSqrSum += compute(sumsz[b]); storeSqrSum %= MOD; } main(){ int n; cin >> n; set<int> heights; for (int x = 0; x < n; x++) cin >> get<0>(hw[x]), heights.insert(get<0>(hw[x])); for (int x = 0; x < n; x++) cin >> get<1>(hw[x]), get<2>(hw[x]) = x; sort(hw, hw+n); reverse(hw, hw+n); for (int x = 0; x < n; x++) p[x] = x, sumsz[x] = 0; int ptr = 0; int ans = 0; for (int curh = 100; curh >= 1; curh--){ while (ptr != n && get<0>(hw[ptr]) == curh){ int idx = get<2>(hw[ptr]); activate( idx ); if (idx != 0 && sumsz[idx-1] != 0) merge(idx, idx-1); if (idx != n-1 && sumsz[idx+1] != 0) merge(idx, idx+1); ptr++; } int heightSqr = curh; ans += (storeSqrSum * heightSqr)%MOD; ans %= MOD; //cerr << curh << ' ' << storeSqrSum << ' ' << (storeSqrSum * heightSqr)%MOD << '\n'; } cout << ans; }

Compilation message (stderr)

fancyfence.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main(){
      | ^~~~
#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...