#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int ,int > PII; int const N = 200010, null = 0x3f3f3f3f, mol = 1e9 + 7; LL n, m, h; LL a[N], s[N], w[N]; int main() { cin >> n; int d = 0; for(int i = 1; i <= n; i++) { cin >> a[i]; if(a[i] > 0 && !d) d = i; s[i] = s[i - 1] + a[i]; } if(s[n] % 3) cout << 0 << endl; else { int x = s[n] / 3; int num = 0; int sum = 0; for(int i = d; i <= n; i++) { if(a[i] > 0) w[i] = num; else w[i] = w[i - 1]; if(s[i] == x) num++; else if(s[i] == x * 2) sum += w[i]; } cout << sum << endl; } } 6 -9 6 2 -2 -3 -3 应该输出0, 但是输出1也过了
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务