제출 #665887

#제출 시각아이디문제언어결과실행 시간메모리
665887AstraytMoney (IZhO17_money)C++17
100 / 100
221 ms43468 KiB
//君の手を握ってしまったら //孤独を知らないこの街には //もう二度と帰ってくることはできないのでしょう //君が手を差し伸べた 光で影が生まれる //歌って聞かせて この話の続き //連れて行って見たことない星まで //さユリ - 花の塔 #include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll #define starburst ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define pii pair<int,int> #define pb push_back #define ff first #define ss second #define mp make_pair #define maxn 1000005 #define mod 1000000007 struct DisjointSetUnion{ int par[maxn]; void init(){ for(int i = 1; i <= maxn - 1; ++i) par[i] = i; } int qry(int u){ return (u == par[u] ? u : par[u] = qry(par[u])); } void uni(int u, int v){ u = qry(u), v = qry(v); par[u] = v; } }dsu; void solve(){ int n, ans = 0; cin >> n; vector<int> v(n), cnt(maxn, 0); for(auto &x:v) cin >> x, cnt[x]++; dsu.init(); for(int i = maxn - 1; i >= 1; --i) if(cnt[i] == 0) dsu.uni(i, i - 1); for(int i = n - 1, j = n - 1; i >= 0; i = j){ ans++; while(j >= 0 && v[i] == v[j]) cnt[v[j]]--, j--; if(cnt[v[i]] == 0) dsu.uni(v[i], v[i] - 1); int x = dsu.qry(v[i] - 1); while(j >= 0){ if(x != v[j]) break; cnt[v[j]]--, j--; if(cnt[x] == 0){ dsu.uni(x, x - 1); x = dsu.qry(x); } } } cout << ans << '\n'; } signed main(){ starburst int t = 1; //cin >> t; while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...