結果
問題 |
No.2956 Substitute with Average
|
ユーザー |
![]() |
提出日時 | 2024-11-21 14:15:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,106 ms / 3,000 ms |
コード長 | 724 bytes |
コンパイル時間 | 2,139 ms |
コンパイル使用メモリ | 200,692 KB |
最終ジャッジ日時 | 2025-02-25 05:46:42 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10, MAXX = 32; int n, a[MAXN], _a[MAXN], sum[MAXN]; long long ans, cnt[2][MAXX * MAXN]; int main(){ ios::sync_with_stdio(0), cin.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; } ans = 1ll * n * (n + 1) / 2 + 1; for(int i = 1; i <= 30; i++){ map<int,int> cnt[2]; for(int j = 1; j <= n; j++){ _a[j] = i - a[j]; } for(int j = 1; j <= n; j++){ sum[j] = sum[j - 1] + _a[j]; if(_a[j] == 0){ cnt[0][sum[j - 1]]++; ans -= cnt[0][sum[j]] + cnt[1][sum[j]]; } else { cnt[1][sum[j - 1]]++; ans -= cnt[0][sum[j]]; } } } cout << ans; return 0; }