Submission #555635

#TimeUsernameProblemLanguageResultExecution timeMemory
555635MamedovNekameleoni (COCI15_nekameleoni)C++17
140 / 140
1270 ms55660 KiB
#pragma GCC optimize ("O3") #include <bits/stdc++.h> #define pii pair<int, int> #define piii pair<pii, int> #define vi vector<int> #define vvi vector<vi> #define vpii vector<pii> #define vvpii vector<vpii> #define f first #define s second #define oo 1000000001 #define eb emplace_back #define pb push_back #define mpr make_pair #define size(v) (int)v.size() #define ln '\n' #define ull unsigned long long #define ll long long #define all(v) v.begin(), v.end() using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define pli pair<ll, int> struct node { vector<pli> pref, suff; int ans; node() { ans = oo; } node(int x, int pos) { pref.eb(mpr((1ll << x), pos)); suff.eb(mpr((1ll << x), pos)); ans = oo; } }; const int up = 1e5 + 5; node tree[up << 2]; int arr[up]; int k; node Merge(node &L, node &R) { node res; res.ans = min(L.ans, R.ans); int posr = 0; for (int i = size(L.suff) - 1; i >= 0 && posr < size(R.pref); --i) { while (posr < size(R.pref) && ((L.suff[i]).f | (R.pref[posr]).f) != (1ll << k) - 1) { ++posr; } if (posr < size(R.pref)) { res.ans = min(res.ans, (R.pref[posr]).s - (L.suff[i]).s + 1); } } res.pref = L.pref; for (pli p : R.pref) { if ((((res.pref).back()).f | p.f) > ((res.pref).back()).f) { (res.pref).eb(mpr(((res.pref).back()).f | p.f, p.s)); } } res.suff = R.suff; for (pli p : L.suff) { if ((((res.suff).back()).f | p.f) > ((res.suff).back()).f) { (res.suff).eb(mpr(((res.suff).back()).f | p.f, p.s)); } } return res; } void build(int v, int l, int r) { if (l == r) { tree[v] = node(arr[l], l); if (k == 1) tree[v].ans = 1; } else { int mid = (l + r) >> 1; build(v * 2, l, mid); build(v * 2 + 1, mid + 1, r); tree[v] = Merge(tree[v * 2], tree[v * 2 + 1]); } } void update(int v, int l, int r, int pos) { if (l == r) { tree[v] = node(arr[l], l); if (k == 1) tree[v].ans = 1; } else { int mid = (l + r) >> 1; if (pos <= mid) update(v * 2, l, mid, pos); else update(v * 2 + 1, mid + 1, r, pos); tree[v] = Merge(tree[v * 2], tree[v * 2 + 1]); } } void solve() { int n, m; cin >> n >> k >> m; for (int i = 1; i <= n; ++i) { cin >> arr[i]; --arr[i]; } build(1, 1, n); int type, p, v; while (m--) { cin >> type; if (type == 1) { cin >> p >> v; --v; arr[p] = v; update(1, 1, n, p); } else { int ans = tree[1].ans; if (ans == oo) ans = -1; cout << ans << ln; } } } int main() { ios_base::sync_with_stdio(false); int t = 1; //cin >> t; while (t--) { solve(); } 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...