답안 #252549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
252549 2020-07-25T20:33:35 Z islingr Nekameleoni (COCI15_nekameleoni) C++14
0 / 140
2035 ms 421288 KB
#include <bits/stdc++.h>

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define f first
#define s second

using namespace std;
using ll = long long;

const int N = 1 << 17, K = 51, inf = 1e9;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }

int U;
struct S {
	int len, ans;
	pair<ll, int> pref[K], suff[K];
	S() : ans{inf}, len{0} { }
	S(int p, int v) : len{1}, ans{U != 1 ? inf : 1} {
		pref[0] = suff[0] = {1ll << v, p};
	}
	S(const S &l, const S &r) {
		len = 0;
		rep(i, 0, l.len) pref[len++] = l.pref[i];
		rep(i, 0, r.len)
			if (len) {
				pref[len] = r.pref[i];
				pref[len].f |= pref[len - 1].f;
				if (pref[len].f != pref[len - 1].f) ++len;
			} else pref[len++] = r.pref[i];
		int tmp = len;
		len = 0;
		rep(i, 0, r.len) suff[len++] = r.suff[i];
		rep(i, 0, l.len) {
			if (len) {
				suff[len] = l.suff[i];
				suff[len].f |= suff[len - 1].f;
				if (suff[len].f != suff[len - 1].f) ++len;
			} else suff[len++] = l.suff[i];
		}

		assert(tmp == len);

		ans = inf;
		for (int s = l.len, p = 0; s--; ) {
			while (p < r.len && (l.suff[s].f | r.pref[p].f) != U) ++p;
			if (p < r.len && (l.suff[s].f | r.pref[p].f) == U)
				ckmin(ans, r.pref[p].s - l.suff[s].s + 1);
		}
	}
};

int sz = 1;
S t[N << 1];

int query() { return t[1].ans; }
void update(int p, int v) {
	p += sz;
	for (t[p] = {p, v}; p >>= 1; )
		t[p] = {t[p << 1], t[p << 1|1]};
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, k, q; cin >> n >> k >> q; U = (1ll << k) - 1;
	while (sz < n) sz <<= 1;
	rep(i, 0, n) { int v; cin >> v; --v; update(i, v); }
	while (q--) {
		short t; cin >> t; --t;
		if (t) cout << (query() != inf ? query() : -1) << '\n';
		else {
			int p, v; cin >> p >> v; --p; --v;
			update(p, v);
		}
	}
}

Compilation message

nekameleoni.cpp: In constructor 'S::S()':
nekameleoni.cpp:16:11: warning: 'S::ans' will be initialized after [-Wreorder]
  int len, ans;
           ^~~
nekameleoni.cpp:16:6: warning:   'int S::len' [-Wreorder]
  int len, ans;
      ^~~
nekameleoni.cpp:18:2: warning:   when initialized here [-Wreorder]
  S() : ans{inf}, len{0} { }
  ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 249 ms 420984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 268 ms 421016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 288 ms 421112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 707 ms 421180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1136 ms 421196 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1261 ms 421240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1578 ms 421288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1507 ms 421172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2017 ms 421112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2035 ms 421060 KB Output isn't correct
2 Halted 0 ms 0 KB -