版本比较
做题记录
正文
增加 53 行删除 0 行
299 行未改动全部展开300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356299 行未改动全部展开 return 0;}```::::
## P3909
给你一个长度为 $n$ 的序列 $a$,对于 $a_1, a_2 \dots a_{n - 1}, a_n$,求:
$$(6 \times \sum_{i = 1} ^ n \sum_{j = i + 1} ^ n \sum_{k = j + 1} ^ {n} a_i \times a_j \times a_k) \bmod (10 ^ 9 + 7)$$
### Subtask 1
考虑一个 $\mathcal{O}(n ^ 3)$ 的暴力,按理来说能过掉 Subtask 1 的数据。可是为什么我的代码全是 WA + TLE?
::::error[WA + TLE code]```cpp#include <bits/stdc++.h>#define debug(a) cerr << (#a) << " = " << (a) << endl;#define mod (int)(1e9 + 7)#define int long long#define maxn 1000010#define endl '\n'using namespace std;
int n;int a[maxn];void solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } int ans = 0; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { for (int k = j + 1; k <= n; k++) { ans += 6 * (a[i] * a[j] * a[k]); ans = (ans + mod) % mod; } } } cout << (ans + mod) % mod << endl;}signed main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int t; t = 1;// cin >> t; while (t--) { solve(); } return 0;}```::::
让我想想。