結果
問題 | No.2779 Don't make Pair |
ユーザー |
![]() |
提出日時 | 2024-06-07 21:43:15 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 53 ms / 2,000 ms |
コード長 | 2,376 bytes |
コンパイル時間 | 2,961 ms |
コンパイル使用メモリ | 255,620 KB |
実行使用メモリ | 8,820 KB |
最終ジャッジ日時 | 2024-06-07 21:43:31 |
合計ジャッジ時間 | 4,448 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 4 ms
5,376 KB |
testcase_10 | AC | 19 ms
6,472 KB |
testcase_11 | AC | 6 ms
5,376 KB |
testcase_12 | AC | 20 ms
5,376 KB |
testcase_13 | AC | 22 ms
5,376 KB |
testcase_14 | AC | 15 ms
5,376 KB |
testcase_15 | AC | 35 ms
6,192 KB |
testcase_16 | AC | 37 ms
6,360 KB |
testcase_17 | AC | 29 ms
6,020 KB |
testcase_18 | AC | 21 ms
5,540 KB |
testcase_19 | AC | 29 ms
5,976 KB |
testcase_20 | AC | 13 ms
5,376 KB |
testcase_21 | AC | 53 ms
7,148 KB |
testcase_22 | AC | 45 ms
7,152 KB |
testcase_23 | AC | 52 ms
8,820 KB |
testcase_24 | AC | 45 ms
7,152 KB |
testcase_25 | AC | 45 ms
7,148 KB |
testcase_26 | AC | 47 ms
7,148 KB |
testcase_27 | AC | 47 ms
7,284 KB |
testcase_28 | AC | 46 ms
7,152 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((ll)v.size()) template<class T> inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template<class T> inline bool chmax(T &a,T b){ if(a<b){ a=b; return true; } return false; } template <class T,auto op,T e> struct segment_tree{ int n; vector<T> v; segment_tree(int n_):n(n_),v(n*2,e){} segment_tree(vector<T> a):n((int)a.size()),v(n*2,e){ for(int i=0;i<n;i++) v[i+n]=a[i]; for(int i=n-1;1<=i;i--) v[i]=op(v[i<<1],v[i<<1|1]); } void update(int i,T x){ assert(0<=i&&i<=n); i+=n; v[i]=x; while(1<i){ i>>=1; v[i]=op(v[i<<1],v[i<<1|1]); } } T get(int i){ i+=n; return v[i]; } T fold(int l,int r){ //[l,r) assert(0<=l&&l<=n); assert(0<=r&&r<=n); assert(l<=r); T ret_l=e,ret_r=e; l+=n; r+=n; for(;l<r;l>>=1,r>>=1){ if(l&1) ret_l=op(ret_l,v[l++]); if(r&1) ret_r=op(v[--r],ret_r); } return op(ret_l,ret_r); } }; template<class T> vector<T> compress(vector<T> &x){ vector<T> unique_v=x; int n=x.size(); sort(all(unique_v)); unique_v.erase(unique(all(unique_v)),unique_v.end()); for(int i=0;i<n;i++){ x[i]=lower_bound(all(unique_v),x[i])-unique_v.begin(); } return unique_v; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n; cin >> n; vector<ll> a(n); rep(i,n) cin >> a[i]; compress(a); segment_tree<ll,[&](ll i,ll j){return max(i,j);},0> seg(n),seg2(n); rep(i,n){ ll x=seg.get(a[i]); seg.update(a[i],x+1); } vector<ll> ans; rep(i,n-1){ ll x=seg.get(a[i]); seg.update(a[i],x-1); ll y=seg2.get(a[i]); seg2.update(a[i],y+1); if(seg.fold(0,n)<=1&&seg2.fold(0,n)<=1) ans.push_back(i); } cout << len(ans) << '\n'; for(auto i:ans) cout << i+1 << ' '; cout << '\n'; }