Submission #1038847

#TimeUsernameProblemLanguageResultExecution timeMemory
1038847vjudge1Nekameleoni (COCI15_nekameleoni)C++17
42 / 140
3097 ms11256 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 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; auto it = mi.find(val[x]); if(it != mi.end()) mi.erase(it); val[x] = ans; mi.insert(val[x]); } 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); 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); for(int i = 1; i <= k; i ++) { auto it = st[i].upper_bound(p); if(it != st[i].begin()) { it--; process(*it); } if(i == x && it != st[i].begin()) { it--; 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...