답안 #78500

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
78500 2018-10-05T13:54:28 Z youngyojun XOR (IZhO12_xor) C++11
100 / 100
287 ms 73580 KB
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
//#define rf(x) (x)=0;while(*p<48)im=*p=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x);
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define cb(x) (x)=(!(x))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define INFST (0x7f7f7f7f)
#define INFLLST (0x7f7f7f7f7f7f7f7fll)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
typedef complex<ld> base;
const ld EPS = (ld)1e-7;
const ld PI = acos(0) * 2;
bool isZero(const ld& x) { return abs(x) <= EPS; }
int sign(const ld& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); }
ll gcd(ll a, ll b) { for(;b;a%=b,swap(a,b)){} return abs(a); }
pll operator + (const pll& a, const pll& b) { return pll(a.first+b.first, a.second+b.second); }
pll operator - (const pll& a, const pll& b) { return pll(a.first-b.first, a.second-b.second); }
pll operator * (const pll& a, const ll& b) { return pll(a.first*b, a.second*b); }
ll operator * (const pll& a, const pll& b) { return a.first*b.second - b.first*a.second; }
ll ccw(const pll& a, const pll& b, const pll& c) { return a*b + b*c + c*a; }
void fg(vector<int> G[], int a, int b) { G[a].pb(b); G[b].pb(a); }
void fg(vector<pii> G[], int a, int b, int c) { G[a].pb({b, c}); G[b].pb({a, c}); }
int operator * (pii a, pii b) { return a.first*b.second - a.second*b.first; }
int ccw(pii a, pii b, pii c) { return a*b + b*c + c*a; }

const int MAXN = 300055;

struct SEG {
	SEG() : l(0), r(0), dt(INF) {}
	SEG *l, *r;
	int dt;

	void upd(int s, int e, int x, int i) {
		upmin(dt, i);
		if(s == e) return;
		const int m = (ll(s)+e) >> 1;
		if(x <= m) {
			if(!l) l = new SEG();
			l -> upd(s, m, x, i);
		} else {
			if(!r) r = new SEG();
			r -> upd(m+1, e, x, i);
		}
	}

	int get(int s, int e, int x, int y, int key) {
		if(s == e) return y <= (s^x) ? dt : INF;
		const int m = (ll(s)+e) >> 1;
		if(y & key) {
			if(x & key) return l ? (l -> get(s, m, x, y, key >> 1)) : INF;
			return r ? (r -> get(m+1, e, x, y, key >> 1)) : INF;
		} else {
			int ret = INF;
			if(x & key) {
				if(l) ret = l -> dt;
				if(r) upmin(ret, r -> get(m+1, e, x, y, key >> 1));
			} else {
				if(r) ret = r -> dt;
				if(l) upmin(ret, l -> get(s, m, x, y, key >> 1));
			}
			return ret;
		}
	}
} *rt = new SEG();

int A[MAXN], B[MAXN];

int N, X, AnsI = -INF, AnsL;

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> X;
	for(int i = 1; i <= N; i++) {
		cin >> A[i];
		B[i] = B[i-1] ^ A[i];
	}

	for(int i = 1, l; i <= N; i++) {
		rt -> upd(0, 2147483647, B[i-1], i-1);
		int j = rt -> get(0, 2147483647, B[i], X, 1 << 30);
		if(i <= j) continue;
		l = i - j;
		if(AnsL < l) {
			AnsL = l;
			AnsI = j+1;
		}
	}

	if(AnsI <= 0) puts("-1");
	else printf("%d %d\n", AnsI, AnsL);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 620 KB Output is correct
4 Correct 3 ms 956 KB Output is correct
5 Correct 18 ms 2376 KB Output is correct
6 Correct 14 ms 2692 KB Output is correct
7 Correct 14 ms 2872 KB Output is correct
8 Correct 15 ms 3228 KB Output is correct
9 Correct 99 ms 29356 KB Output is correct
10 Correct 99 ms 30276 KB Output is correct
11 Correct 100 ms 30996 KB Output is correct
12 Correct 100 ms 31872 KB Output is correct
13 Correct 102 ms 32636 KB Output is correct
14 Correct 99 ms 33476 KB Output is correct
15 Correct 105 ms 34340 KB Output is correct
16 Correct 98 ms 34908 KB Output is correct
17 Correct 253 ms 67684 KB Output is correct
18 Correct 252 ms 69612 KB Output is correct
19 Correct 287 ms 71596 KB Output is correct
20 Correct 261 ms 73580 KB Output is correct