Submission #1038828

#TimeUsernameProblemLanguageResultExecution timeMemory
1038828vjudge1Nekameleoni (COCI15_nekameleoni)C++17
0 / 140
3068 ms7280 KiB
#include<bits/stdc++.h> using namespace std; const int N = 100'000 + 10, M = 2 << 17, K = 51, inf = 1'000'000'000; int n, k, q, seg[M], a[N]; set<int> st[K]; void update(int x, int d, int s = 0, int e = n, int v = 1) { if(x < s || e <= x) return; if(e - s == 1) { seg[v] = d; return; } int mid = (s + e) / 2, lc = 2 * v, rc = lc + 1; update(x, d, s, mid, lc); update(x, d, mid, e, rc); seg[v] = min(seg[lc], seg[rc]); } void process(int x) // idx is the { int ans = x; for(int i = 1; i <= k; i ++) if(i != a[x]) ans = max(ans, *st[i].upper_bound(x)); // cerr << x << ' ' << ans << endl; update(x - 1, ans - x + 1); } int main() { 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 = seg[1]; 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...