Submission #254003

#TimeUsernameProblemLanguageResultExecution timeMemory
254003VimmerNekameleoni (COCI15_nekameleoni)C++14
140 / 140
2581 ms106256 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-O3") #pragma GCC optimize("Ofast") //#pragma GCC optimize("fast-math") //#pragma GCC optimize("no-stack-protector") #define F first #define S second #define sz(x) int(x.size()) #define pb push_back #define pf push_front #define N 100050 #define M ll(1e9 + 7) #define inf 1e9 + 1e9 using namespace std; //using namespace __gnu_pbds; typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef short int si; typedef array <ll, 3> a3; typedef array <ll, 5> a5; //typedef tree <ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; pair <int, int> t[4 * N][51]; int f[4 * N]; int n, k, m, a[N]; multiset <int> se; void comb(int v, int tl, int tr) { if (f[v] != 0) se.erase(se.find(f[v])); int l = v + v, r = v + v + 1, ml = -1, mr = -1; bool bad = 0; vector <pair <int, int> > vr; vr.clear(); for (int i = 1; i <= k; i++) { t[v][i] = {0, 0}; if (t[l][i].F != 0) t[v][i].F = t[l][i].F; else if (t[r][i].F != 0) t[v][i].F = t[r][i].F; if (t[r][i].S != 0) t[v][i].S = t[r][i].S; else if (t[l][i].S != 0) t[v][i].S = t[l][i].S; vr.pb({t[l][i].S, i}); if (t[v][i].F == 0) {bad = 1; continue;} if (t[l][i].F != 0 && t[r][i].F != 0) continue; } if (bad) {f[v] = 0; return;} sort(vr.begin(), vr.end()); int ans = 1e9; int R = vr.back().F; for (auto it : vr) { int L = it.F; if (L != 0) ans = min(ans, R - L + 1); R = max(R, t[r][it.S].F); if (t[r][it.S].F == 0) break; } f[v] = ans; se.insert(f[v]); } void bld(int v, int tl, int tr) { if (tl == tr) { t[v][a[tl]] = {tl, tr}; return; } int md = (tl + tr) >> 1; bld(v + v, tl, md); bld(v + v + 1, md + 1, tr); comb(v, tl, tr); } void upd(int v, int tl, int tr, int pos, int val) { if (tl == tr) { t[v][a[tl]] = {0, 0}; a[tl] = val; t[v][a[tl]] = {tl, tr}; return; } int md = (tl + tr) >> 1; if (pos <= md) upd(v + v, tl, md, pos, val); else upd(v + v + 1, md + 1, tr, pos, val); comb(v, tl, tr); } int main() { //freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout); ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k >> m; for (int i = 1; i <= n; i++) cin >> a[i]; bld(1, 1, n); for (; m > 0; m--) { int t; cin >> t; if (t == 1) { int p, x; cin >> p >> x; upd(1, 1, n, p, x); continue; } if (k == 1) {cout << 1 << '\n'; continue;} if (sz(se) == 0) {cout << "-1" << '\n'; continue;} cout << *se.begin() << '\n'; } }

Compilation message (stderr)

nekameleoni.cpp: In function 'void comb(int, int, int)':
nekameleoni.cpp:45:35: warning: unused variable 'ml' [-Wunused-variable]
     int l = v + v, r = v + v + 1, ml = -1, mr = -1;
                                   ^~
nekameleoni.cpp:45:44: warning: unused variable 'mr' [-Wunused-variable]
     int l = v + v, r = v + v + 1, ml = -1, mr = -1;
                                            ^~
#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...