版本比较
P14567 题解
正文
增加 5 行删除 5 行
52 行未改动5354555657575859605960616263646565666768699 行未改动798081828383848586873 行未改动52 行未改动long long find(long long x) { return (fa[x] == x) ? x : fa[x] = find(fa[x]); }
int main() { n = read(); for(int i = 1; i <= n; i ++) for(int i = 1; i <= n; i ++) p[i].l = a[i].l = n, p[i].r = a[i].r = 1; for(long long i = 1; i <= n; i ++) c[i] = read(), a[c[i]].l = min(a[c[i]].l, i), a[c[i]].c = c[i], for(long long i = 1; i <= n; i ++) c[i] = read(), a[c[i]].l = min(a[c[i]].l, i), a[c[i]].c = c[i], a[c[i]].r = max(a[c[i]].r, i), b[c[i]].push_back(i); for(int i = 1; i <= n; i ++) v[i] = read(), fa[i] = i; for(int i = 1; i <= n; i ++) f[i] = read(); sort(a + 1, a + n + 1, cmp); for(int i = 1; i <= n; i ++) if(b[a[i].c].size()) for(int i = 1; i <= n; i ++) if(b[a[i].c].size()) for(int j = i + 1; j <= n; j ++) { if(!b[a[j].c].size()) continue; long long l = 0, r = b[a[j].c].size() - 1, res = -1; while(l <= r) {9 行未改动 p[x].r = max(p[x].r, a[i].r); } for(int i = 1; i <= n; i ++) if(p[i].l <= p[i].r) { long long res = 0; for(int j = p[i].l; j <= p[i].r; j ++) for(int j = p[i].l; j <= p[i].r; j ++) res += v[j] * f[j - p[i].l + 1]; ans = min(ans, res); } cout << ans << "\n";3 行未改动