Submission #851756

#TimeUsernameProblemLanguageResultExecution timeMemory
851756c2zi6Zamjene (COCI16_zamjene)C++14
0 / 140
7837 ms524288 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; vector<int> a, q; vector<int> p; vector<int> cnt; vector<map<int, int>> seq; int LAVCNT; int get(int u) { return p[u] = (u == p[u] ? u : get(p[u])); } void onion(int u, int v) { u = get(u); v = get(v); if (u == v) return; if (cnt[v] > cnt[u]) swap(u, v); //v-n miacnel u-in cnt[u] += cnt[v]; p[v] = u; if (seq[u].size() == 0) LAVCNT--; if (seq[v].size() == 0) LAVCNT--; for (pair<int, int> p : seq[v]) { seq[u][p.first] += p.second; if (seq[u][p.first] == 0) seq[u].erase(p.first); } if (seq[u].size() == 0) LAVCNT++; } void solve() { int n, Q; cin >> n >> Q; a = vector<int>(n); for (int& x : a) cin >> x; q = a; sort(q.begin(), q.end()); LAVCNT = 0; p = cnt = vector<int>(n); seq = vector<map<int, int>>(n); for (int i = 0; i < n; i++) { p[i] = i; cnt[i] = 1; if (a[i] == q[i]) { LAVCNT++; continue; } seq[i][a[i]]++; seq[i][q[i]]--; } while (true) { cout << "type: "; int t; cin >> t; if (t == 1) { set<int> st; for (int i = 0; i < n; i++) { cout << get(i) << " "; st.insert(get(i)); } cout << endl; cout << "GOOD CLOUDS' COUNT: " << LAVCNT << endl; for (int x : st) { cout << x << "'s properties:" << endl; cout << " count: " << cnt[x] << endl; for (pair<int, int> p : seq[x]) { cout << " " << p.first << ": " << p.second << endl; } } } else { int u, v; cin >> u >> v; onion(u, v); } } } int main() { 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...
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...