結果
| 問題 |
No.2956 Substitute with Average
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-11-13 12:12:32 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 3,000 ms |
| コード長 | 896 bytes |
| コンパイル時間 | 3,603 ms |
| コンパイル使用メモリ | 272,940 KB |
| 実行使用メモリ | 17,068 KB |
| 最終ジャッジ日時 | 2024-11-13 12:12:41 |
| 合計ジャッジ時間 | 6,143 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 1e5 + 10, L = 3e6 + 10;
int n, a[N], p[N], cnt[L * 2];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i ++)
cin >> a[i];
i64 ans = n * (n + 1ll) / 2 + 1;
for(int t = 1; t <= 30; t ++) {
i64 x = 0, y = 0;
for(int i = 1; i <= n; i ++) {
p[i] = p[i - 1] + a[i] - t;
if(a[i] != t) {
cnt[L + p[i - 1]] ++;
y += cnt[L + p[i]];
}
}
for(int i = 0; i < n; i ++)
cnt[L + p[i]] = 0;
for(int i = 1; i <= n; i ++) {
cnt[L + p[i - 1]] ++;
x += cnt[L + p[i]];
}
for(int i = 0; i < n; i ++)
cnt[L + p[i]] = 0;
ans -= x - y;
}
cout << ans << "\n";
}
vjudge1