Submission #680742

# Submission time Handle Problem Language Result Execution time Memory
680742 2023-01-11T16:55:55 Z iosif_andrei_ XOR Sum (info1cup17_xorsum) C++14
0 / 100
151 ms 12088 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]();
    }

    inline 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, Sorted[1000001], M[1000002];
int* vp, * xp, * p;
long long bit[30];

int main()
{
    fin >> n;

    for (int i = 1; i <= n; i++)
        fin >> v[i], Sorted[i] = v[i];

    sort(Sorted + 1, Sorted + n + 1);
    M[n + 1] = -1;

    int i, k, l, r, m, poz;

    for (k = 0; k <= 29; k++)
    {
        vp = v;
        vp++;

        xp = x;
        xp++;

        p = M;
        p++;

        //while (*p != -1)
            //*p = 0, p++;

        for (i = 1; i <= n; i++)
        {
            if (*vp & 1)
                *xp += (1 << k);
            *vp >>= 1;

            l = 1, r = n;

            while (l <= r)
            {
                m = (l + r) >> 1;

                if (Sorted[m] == *xp)
                {
                    poz = m;
                    break;
                }

                if (Sorted[m] < *xp)
                    l = m + 1;
                else
                    r = m - 1;
            }

            vp++;
            xp++;
        }
    }

    int res = 0;

    for (int k = 0; k <= 29; k++)
        if (bit[k] & 1)
            res += (1 << k);

    fout << res;

    return 0;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:254:24: warning: variable 'poz' set but not used [-Wunused-but-set-variable]
  254 |     int i, k, l, r, m, poz;
      |                        ^~~
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);
      |             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 151 ms 12088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 151 ms 12088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -