結果
問題 | No.1505 Zero-Product Ranges |
ユーザー |
|
提出日時 | 2021-05-14 22:19:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 1,028 bytes |
コンパイル時間 | 1,827 ms |
コンパイル使用メモリ | 177,140 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-02 01:47:58 |
合計ジャッジ時間 | 3,707 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
#include "bits/stdc++.h"using namespace std;using ll = long long;ll numSubseq(ll n) {return n * (n + 1) / 2;}void Main() {ll N;cin >> N;vector<ll> A(N, 0);for (ll i = 0; i < N; ++i) {cin >> A[i];}map<ll, ll> ones;bool reset = true;ll temp = 0;for (ll i = 0; i < N; ++i) {if (A[i] == 1) {++temp;}else {if (temp == 0) {continue;}if (ones.count(temp) == 0) {ones.emplace(temp, 0);}ones[temp] += 1;temp = 0LL;}}if (ones.count(temp) == 0) {ones.emplace(temp, 0);}ones[temp] += 1;ll ans = numSubseq(N);for (auto e : ones) {ans -= numSubseq(e.first) * e.second;}cout << ans << endl;}int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);std::cout << std::fixed << std::setprecision(15);Main();return 0;}