# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
681278 |
2023-01-12T16:09:37 Z |
USER |
XOR Sum (info1cup17_xorsum) |
C++14 |
|
1600 ms |
28456 KB |
#include <bits/stdc++.h>
using namespace std;
class Input {
private:
char* t;
int sp;
const int sz = 10000;
char read()
{
if (sp == sz)
{
fread(t, 1, sz, stdin);
sp = 0;
return t[sp++];
}
else
return t[sp++];
}
public:
Input()
{
sp = sz;
t = new char[sz]();
}
Input& operator >> (int& n)
{
char c = read();
while (c == ' ' || c == '\n')
c = read();
n = 0;
int sng = 1;
if (c == '-')
sng = -1, c = read();
while (c != '\0' && isdigit(c))
n = n * 10 + (c - '0'), c = read();
n *= sng;
return *this;
}
Input& operator >> (char& s)
{
char c = read();
while (c != '\0' && c == '\n')
c = read();
s = c;
return *this;
}
Input& operator >> (long long& n)
{
char c = read();
while (c == ' ' || c == '\n')
c = read();
n = 0;
int sng = 1;
if (c == '-')
sng = -1, c = read();
while (c != '\0' && isdigit(c))
n = n * 10 + (c - '0'), c = read();
n *= sng;
return *this;
}
void getline(string& s)
{
char c = read();
s = "";
while (c != '\0' && c != '\n')
s += c, c = read();
}
Input& operator >> (string& s)
{
char c;
c = read();
s = "";
while (c == '\n' || c == ' ')
c = read();
while (c != '\n' && c != '\0' && c != ' ')
s += c, c = read();
return *this;
}
Input& operator >> (char* s)
{
char c;
c = read();
int i = 0;
while (c == '\n' || c == ' ')
c = read();
while (c != '\n' && c != '\0' && c != ' ')
s[i++] = c, c = read();
return *this;
}
};
class Output {
private:
char* t;
int sp;
const int sz = 10000;
void write(char c)
{
if (sp == sz)
{
fwrite(t, 1, sz, stdout);
sp = 0;
t[sp++] = c;
}
else
t[sp++] = c;
}
public:
Output()
{
sp = 0;
t = new char[sz]();
}
~Output()
{
fwrite(t, 1, sp, stdout);
}
Output& operator << (int n)
{
if (n < 0)
{
write('-');
n *= -1;
}
if (n <= 9)
write(char(n + '0'));
else
{
(*this) << (n / 10);
write(char(n % 10 + '0'));
}
return *this;
}
Output& operator << (char c)
{
write(c);
return *this;
}
Output& operator << (const char* s)
{
int i = 0;
while (s[i] != '\0')
write(s[i++]);
return *this;
}
Output& operator << (long long n)
{
if (n < 0)
{
write('-');
n *= -1;
}
if (n < 10)
write(char(n + '0'));
else
{
(*this) << (n / 10);
write(char(n % 10 + '0'));
}
return *this;
}
Output& operator << (string s)
{
for (auto i : s)
write(i);
return *this;
}
void precizion(double x, int nr)
{
int p = int(floor(x));
*this << p;
if (nr == 0)
return;
write('.');
for (int i = 1; i <= nr; i++)
{
x -= floor(x);
x *= 10;
write(int(x) + '0');
}
}
};
Input fin;
Output fout;
// (((1 << k) <= nr && nr < (1 << (k + 1))) || (nr >= (1 << k) + (1 << (k + 1))))
int v[1000001], X[1000001], n, POW[32], a[1000001];
const int p2 = 4194304;
int f[p2 + 2];
int* vp, * xp, * fp;
bool bit;
int main()
{
f[p2 + 1] = -1;
int maxi = 0;
for (int i = 0; i <= 30; i++)
POW[i] = (1 << i);
fin >> n;
for (int i = 1; i <= n; i++)
fin >> v[i], maxi = max(maxi, v[i]);
int stop = ceil(log2(maxi)) + 1, l, r, m, poz1, poz2;
int res = 0, downLim, upLim, aux, sz;
for (int k = 0; k < min(22, stop); k++)
{
bit = false;
vp = v;
vp++;
xp = X;
xp++;
fp = f;
while (*fp != -1)
*fp = 0, fp++;
for (int i = 1; i <= n; i++)
{
if (*vp & 1)
*xp += POW[k];
*vp >>= 1;
f[*xp]++;
vp++;
xp++;
}
sz = 0;
fp = f;
int ind = 0;
while (*fp != -1)
{
while (*fp)
a[++sz] = ind, (*fp)--;
ind++;
fp++;
}
aux = (1 << k) + (1 << (k + 1));
downLim = POW[k];
upLim = POW[k + 1] - 1;
for (int i = 1; i <= n; i++)
{
poz1 = -1;
l = i, r = n;
while (l <= r)
{
m = (l + r) >> 1;
if (a[i] + a[m] >= aux)
{
poz1 = m;
r = m - 1;
}
else
l = m + 1;
}
if (poz1 != -1)
bit ^= (n - poz1 + 1) & 1;
poz1 = -1;
l = i, r = n;
while (l <= r)
{
m = (l + r) >> 1;
if (a[i] + a[m] >= downLim)
{
poz1 = m;
r = m - 1;
}
else
l = m + 1;
}
if (poz1 == -1 || a[i] + a[poz1] > upLim)
continue;
l = i, r = n;
while (l <= r)
{
m = (l + r) >> 1;
if (a[i] + a[m] <= upLim)
{
poz2 = m;
l = m + 1;
}
else
r = m - 1;
}
bit ^= (poz2 - poz1 + 1) & 1;
}
if (bit)
res += POW[k];
}
for (int k = 22; k <= stop; k++)
{
bit = false;
vp = v;
vp++;
xp = X;
xp++;
for (int i = 1; i <= n; i++)
{
if (*vp & 1)
*xp += POW[k];
*vp >>= 1;
a[i] = *xp;
vp++;
xp++;
}
sort(a + 1, a + n + 1);
aux = (1 << k) + (1 << (k + 1));
downLim = POW[k];
upLim = POW[k + 1] - 1;
for (int i = 1; i <= n; i++)
{
poz1 = -1;
l = i, r = n;
while (l <= r)
{
m = (l + r) >> 1;
if (a[i] + a[m] >= aux)
{
poz1 = m;
r = m - 1;
}
else
l = m + 1;
}
if (poz1 != -1)
bit ^= (n - poz1 + 1) & 1;
poz1 = -1;
l = i, r = n;
while (l <= r)
{
m = (l + r) >> 1;
if (a[i] + a[m] >= downLim)
{
poz1 = m;
r = m - 1;
}
else
l = m + 1;
}
if (poz1 == -1 || a[i] + a[poz1] > upLim)
continue;
l = i, r = n;
while (l <= r)
{
m = (l + r) >> 1;
if (a[i] + a[m] <= upLim)
{
poz2 = m;
l = m + 1;
}
else
r = m - 1;
}
bit ^= (poz2 - poz1 + 1) & 1;
}
if (bit)
res += POW[k];
}
fout << res;
return 0;
}
Compilation message
xorsum.cpp: In member function 'char Input::read()':
xorsum.cpp:14:18: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | fread(t, 1, sz, stdin);
| ~~~~~^~~~~~~~~~~~~~~~~
xorsum.cpp: In function 'int main()':
xorsum.cpp:451:26: warning: 'poz2' may be used uninitialized in this function [-Wmaybe-uninitialized]
451 | bit ^= (poz2 - poz1 + 1) & 1;
| ~~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
16724 KB |
Output is correct |
2 |
Correct |
133 ms |
16784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1148 ms |
28456 KB |
Output is correct |
2 |
Correct |
1071 ms |
27668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1148 ms |
28456 KB |
Output is correct |
2 |
Correct |
1071 ms |
27668 KB |
Output is correct |
3 |
Execution timed out |
1668 ms |
28352 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
16724 KB |
Output is correct |
2 |
Correct |
133 ms |
16784 KB |
Output is correct |
3 |
Correct |
421 ms |
17876 KB |
Output is correct |
4 |
Correct |
427 ms |
17876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
16724 KB |
Output is correct |
2 |
Correct |
133 ms |
16784 KB |
Output is correct |
3 |
Correct |
1148 ms |
28456 KB |
Output is correct |
4 |
Correct |
1071 ms |
27668 KB |
Output is correct |
5 |
Execution timed out |
1668 ms |
28352 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |