結果
問題 | No.2930 Larger Mex |
ユーザー |
![]() |
提出日時 | 2024-10-12 16:45:45 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 70 ms / 2,000 ms |
コード長 | 1,369 bytes |
コンパイル時間 | 2,817 ms |
コンパイル使用メモリ | 249,808 KB |
実行使用メモリ | 7,552 KB |
最終ジャッジ日時 | 2024-10-12 16:45:54 |
合計ジャッジ時間 | 8,499 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, x, y) for (auto i = (x); i < (y); i++) #define RREP(i, x, y) for (auto i = (y) - 1; (x) <= i; i--) #define ALL(x) (x).begin(), (x).end() #pragma GCC optimize("O3") #include <atcoder/segtree> using namespace atcoder; int op(int a, int b){ return min(a, b); } int e(){ return 1000000; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; vector<int> A(N); REP(i, 0, N){ cin >> A[i]; } if(M == 0){ REP(i, 0, N){ cout << N - i << "\n"; } return 0; } vector<int> ans(N); segtree<int, op, e> st(M); REP(i, 0, M){ st.set(i, 0); } int j = 0; REP(i, 0, N){ while(st.prod(0, M) == 0 && j < N){ if(A[j] < M){ st.set(A[j], st.get(A[j])+1); } j++; } if(st.prod(0, M) != 0){ ans[j-i-1]++; if(i){ ans[N-i]--; } } if(A[i] < M){ st.set(A[i], st.get(A[i])-1); } // REP(j, 0, M){ // cout << st.get(j) << " "; // } // cout << " " << st.prod(0, M) << "\n"; } // REP(i, 0, N){ // cout << ans[i] << " "; // } // cout << "\n"; ll sum = 0; REP(i, 0, N){ sum += ans[i]; cout << sum << "\n"; } return 0; } /* File : ~/yukicoder/midoriika_3rd/L.cpp Date : 2024/10/12 Time : 16:21:06 */