제출 #248060

#제출 시각아이디문제언어결과실행 시간메모리
248060Vladikus004Kralj (COCI16_kralj)C++14
140 / 140
737 ms113784 KiB
#include <bits/stdc++.h> #define inf 2e9 #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; const int N = 500000 + 5; int n, a[N], p[N], v[N], us[N], cnt, sz[N], was_ed[N], cmp[N], pr[N], ed[N]; vector <int> gr[N], add[N]; void add_ed(int x){ if (was_ed[x]) return; gr[(x - 1 + n) % n].push_back(x); was_ed[x] = 1; } int get_anc(int x){ if (x == pr[x]) return x; return pr[x] = get_anc(pr[x]); } void unite(int x, int y){ x = get_anc(x); y = get_anc(y); if (x == y) return; pr[y] = x; ed[x] = ed[y]; } int ans = 0; multiset <int> ms; void dfs(int x){ us[x] = 1; if (gr[x].size()) dfs(gr[x][0]); ms.insert(p[x]); for (auto u: add[x]){ auto it = ms.lower_bound(u); if (it == ms.begin()){ ms.erase(ms.lower_bound(*ms.rbegin())); }else{ --it; ms.erase(it); ans++; } } } void init(){ for (int i = 0; i < n; i++) ed[i] = -1, pr[i] = i; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif // LOCAL cin >> n; init(); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> p[i]; for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i < n; i++){ a[i]--; add[a[i]].push_back(v[i]); int go = 0, ind = a[i], e = 0; if (!cmp[ind]){ cmp[ind] = ++cnt; ed[cmp[ind]] = ind + 1; continue; } cmp[ind] = get_anc(cmp[ind]); int was = ind, was_cmp = cmp[ind]; ind = ed[cmp[ind]]; ind %= n; while (cmp[ind]){ add_ed(ind); cmp[ind] = get_anc(cmp[ind]); unite(cmp[was], cmp[ind]); was = ind; ind = ed[cmp[ind]]; ind %= n; } cmp[ind] = was_cmp; add_ed(ind); ed[was_cmp]++; ed[was_cmp] %= n; } for (int i = 0; i < n; i++){ if (was_ed[i] || us[i]) continue; dfs(i); } cout << ans; }

컴파일 시 표준 에러 (stderr) 메시지

kralj.cpp: In function 'int main()':
kralj.cpp:70:13: warning: unused variable 'go' [-Wunused-variable]
         int go = 0, ind = a[i], e = 0;
             ^~
kralj.cpp:70:33: warning: unused variable 'e' [-Wunused-variable]
         int go = 0, ind = a[i], e = 0;
                                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...