제출 #1174100

#제출 시각아이디문제언어결과실행 시간메모리
1174100nuutsnoynton지구 온난화 (NOI13_gw)C++20
12 / 40
892 ms131072 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const ll N = 1e6 + 2; ll ataman[N], cnt; bool used[N] = {0}; vector < ll > v[N]; ll Get(ll x) { if ( x == ataman[x]) return x; return ataman[x] = Get(ataman[x]); } void Unite(ll x, ll y) { x = Get(x); y = Get(y); if ( x == y) return ; cnt --; if ( x > y) swap(x, y); ataman[y] = x; return ; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, m, r, x, s, y, i, j, ans, t; cin >> n; ll a[n + 2]; unordered_map < ll, ll > mp_2; set < ll > S; for (i = 1; i <= n; i ++) { cin >> a[i]; S.insert(a[i]); } s = 0; for ( ll R : S) { mp_2[R] = ++s; } for (i = 1; i <= n; i ++) { a[i] = mp_2[a[i]]; v[a[i]].push_back(i); } ans = 0; for (i = 1e6; i >= 0; i --) { for ( ll X : v[i]) { used[X] = 1; cnt ++; ataman[X] = X; if ( used[X - 1] == 1) Unite(X, X - 1); if ( used[X + 1] == 1) Unite(X, X + 1); } ans = max(ans, cnt); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...