about summary refs log tree commit diff
path: root/codechef/prtagn.c
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-07-15 19:58:48 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-07-15 19:58:48 +0700
commitbe6678fbca007e73d69c9a9c5cddb8241a987149 (patch)
treee00165734b3b3ab2ca8d47e32ef5d7868b4804c3 /codechef/prtagn.c
parent6c0ea3cc3364733e8d8fe7625b128f817d55b2cd (diff)
downloadcp-be6678fbca007e73d69c9a9c5cddb8241a987149.tar.gz
So I gave up on a number theory one
Diffstat (limited to 'codechef/prtagn.c')
-rw-r--r--codechef/prtagn.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/codechef/prtagn.c b/codechef/prtagn.c
new file mode 100644
index 0000000..deadb6f
--- /dev/null
+++ b/codechef/prtagn.c
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int prt(long n)
+{
+	int tmp;
+	for (tmp = n & 1; n >>= 1; tmp ^= n & 1);
+	return tmp;
+}
+
+int main()
+{
+	char t;
+	long q, x, z, *s = malloc(sizeof(long) << 17);
+
+	scanf("%hhd", &t);
+	while (t--) {
+		char *in = calloc(1 << 17, sizeof(char));
+		long e = 0, o = 0, *p = s;
+
+		scanf("%ld", &q);
+		while (q--) {
+			scanf("%ld", &x);
+			if (in[x]) {
+				printf("%ld %ld\n", e, o);
+				continue;
+			}
+
+			long *y = p;
+			while (y-- > s)
+				if ((z = x ^ *y) && !in[z]) {
+					*p++ = z;
+					in[z] = 1;
+					prt(z) ? o++ : e++;
+				}
+
+			*p++ = x;
+			in[x] = 1;
+			prt(x) ? o++ : e++;
+			printf("%ld %ld\n", e, o);
+		}
+
+		free(in);
+	}
+
+	return 0;
+}