Submission #128624

# Submission time Handle Problem Language Result Execution time Memory
128624 2019-07-11T07:45:42 Z E869120 XOR Sum (info1cup17_xorsum) C++14
0 / 100
1600 ms 16864 KB
#include <iostream>
#include <vector>
using namespace std;
#pragma warning (disable: 4996)

class BIT {
public:
	vector<int> bit; int size_ = 0;

	void init(int sz) {
		size_ = sz + 2;
		bit.resize(size_ + 2, 0);
	}
	void add(int pos, int x) {
		pos++;
		while (pos <= size_) {
			bit[pos] += x;
			pos += (pos&-pos);
		}
	}
	int sum(int pos) {
		pos++; int s = 0;
		while (pos >= 1) {
			s += bit[pos];
			pos -= (pos&-pos);
		}
		return s;
	}
};

int N, A[1 << 20];

int solve(int bit) {
	BIT Z; Z.init((4 << bit)); int rem = 0;
	for (int i = 1; i <= N; i++) {
		int F = A[i] % (2 << bit);
		Z.add(F, 1);
		Z.add(F + (2 << bit), 1);
		rem += Z.sum((4 << bit) - F - 1) - Z.sum((3 << bit) - F - 1);
		rem %= 2;
	}
	return rem;
}

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
	int ans = 0;
	for (int i = 0; i <= 20; i++) {
		int t = solve(i);
		if (t == 1) ans += (1 << i);
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

xorsum.cpp:4:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
xorsum.cpp: In function 'int main()':
xorsum.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
xorsum.cpp:47:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
                               ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 16864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1661 ms 12660 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1661 ms 12660 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 16864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 16864 KB Output isn't correct
2 Halted 0 ms 0 KB -