版本比较
题解:P15546 「Stoi2037」七里香
正文
增加 8 行删除 8 行
112 行未改动全部展开11311411511611711711811912012112212212312412512615 行未改动14214314414514614614714814915015115215215315415515615715815815916016116216216316416516616716816816917017117117217317417531 行未改动112 行未改动全部展开
// 输出 __int128void print(__int128 x){ if(x == 0) if(x == 0) { putchar('0'); return; } if(x < 0) if(x < 0) { putchar('-'); x = -x; }15 行未改动 for(int i = 1; i <= n; i++) { a[i] = read(); }
// 计算权重 c[i] for(int i = 1; i <= n; i++) { c[i] = (__int128)i * (n - i + 1) * (2 * i - n - 1) / 2; }
// 第一部分:固定贡献 for(int i = 1; i <= n; i++) { ans += c[i] * i * k; }
// 排序后对应相乘 sort(a + 1, a + n + 1); sort(c + 1, c + n + 1);
// 第二部分:可变贡献 for(int i = 1; i <= n; i++) { ans += c[i] * a[i]; }
print(ans); cout << endl;
return 0;}//Q^Q!!!```31 行未改动