Submission #1038864

#TimeUsernameProblemLanguageResultExecution timeMemory
1038864vjudge1Nekameleoni (COCI15_nekameleoni)C++17
0 / 140
1805 ms11640 KiB
#include<bits/stdc++.h> using namespace std; const int N = 100'000 +10, K = 51, inf = 1'000'000'000; int n, k, q, a[N], val[N]; set<int> st[K]; multiset<int> mi; void update(int x, int ans) { auto it = mi.find(val[x]); if(it != mi.end()) mi.erase(it); val[x] = ans; mi.insert(val[x]); } void process(int x) { int ans = x; for(int i = 1; i <= k; i ++) if(i != a[x]) ans = max(ans, *st[i].upper_bound(x)); if(ans < *st[a[x]].upper_bound(x)) ans = ans - x + 1; else ans = inf; update(x, ans); } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> k >> q; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i ++) st[a[i]].insert(i); for(int i = 1; i <= k; i++) st[i].insert(inf), st[i].insert(-inf); for(int i = 1; i <= n; i ++) process(i); while(q--) { int t; cin >> t; if(t == 2) { int ans = *mi.begin(); cout << (ans > n ? -1 : ans) << "\n"; } else { int p, x; cin >> p >> x; st[a[p]].erase(p); a[p] = x; st[a[p]].insert(p); vector<pair<int, int> > vec(k + 1); for(int i = 1; i <= k; i ++) { auto it = st[i].upper_bound(p); it--; vec[i].first = *it; it++; vec[i].second = *it; } for(int i = 1; i <= k; i ++) { if(vec[i].first == -inf) continue; int ans = vec[i].first; for(int j = 1; j <= k; j++) { if(vec[j].first >= vec[i].first) ans = max(vec[j].first, ans); else ans = max(vec[j].second, ans); } if(ans < vec[i].second) ans = 1 + ans - vec[i].first; else ans = inf; update(vec[i].first, ans); } auto it = st[x].find(p); it--; if(*it > 0) process(*it); } } return 0; }
#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...