心路历程

预计得分:100 + 40 + 30 = 170

实际得分:100 + 30 + 0 = 130

T2有一个部分分的数组没开够RE了。

T3好像是思路有点小问题。。 思路没问题,实现的时候一个细节没想过来。。

Sol

T1

直接把式子化开,发现都可以$O(1)$维护,做完了。。。

#include<cstdio>
#include<algorithm>
#include<vector>
#define LL long long
using namespace std;
const LL MAXN = 1e5 + 10;
inline LL read() {
    char c = getchar(); LL x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
LL N, a[MAXN], sum, sump;
int main() {
    N = read();
    for(LL i = 1; i <= N; i++) a[i] = read(), sum += a[i], sump += a[i] * a[i];
    for(LL i = 1; i <= N; i++) {
        LL ans = (N - 1) * (sump - a[i] * a[i]) - 2 * (sum - a[i]) * (sum - a[i]) + (sum - a[i]) * (sum - a[i]);
        if(i != N) printf("%lld ", ans);
        else printf("%lld", ans);
    }
    return 0;
}
T1

相关文章:

  • 2021-10-22
  • 2022-02-09
  • 2021-04-26
  • 2021-12-06
  • 2021-07-06
  • 2022-12-23
  • 2022-01-15
猜你喜欢
  • 2021-07-18
  • 2021-08-08
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
  • 2021-10-24
相关资源
相似解决方案