답안 #681167

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
681167 2023-01-12T13:19:36 Z USER XOR Sum (info1cup17_xorsum) C++14
0 / 100
327 ms 8280 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');
        }
    }
};
class Set {
private:

#define sub(p) (p == NULL ? 0 : p->nr)
#define hight(p) (p == NULL ? 0 : p->hight)
#define getBalanced(p) (p == NULL ? 0 : hight(p->left) - hight(p->right))

    struct nod {
        int val, hight, nr, fr;
        nod* left, * right;
    };

    nod* root;

    inline nod* New(int val)
    {
        nod* p = new nod;

        p->val = val;
        p->left = p->right = NULL;
        p->nr = p->hight = 1;
        p->fr = 1;

        return p;
    }

    inline nod* to_right(nod* x)
    {
        nod* y = x->left;
        nod* z = y->right;

        y->right = x;
        x->left = z;

        x->hight = max(hight(x->left), hight(x->right)) + 1;
        y->hight = max(hight(y->left), hight(y->right)) + 1;

        x->nr = sub(x->left) + sub(x->right) + x->fr;
        y->nr = sub(y->left) + sub(y->right) + y->fr;

        return y;
    }

    inline nod* to_left(nod* x)
    {
        nod* y = x->right;
        nod* z = y->left;

        y->left = x;
        x->right = z;

        x->hight = max(hight(x->left), hight(x->right)) + 1;
        y->hight = max(hight(y->left), hight(y->right)) + 1;

        x->nr = sub(x->left) + sub(x->right) + x->fr;
        y->nr = sub(y->left) + sub(y->right) + y->fr;

        return y;
    }

    nod* add(nod* root, int val)
    {
        if (root == NULL)
            return New(val);

        if (root->val < val)
            root->right = add(root->right, val);
        else if (root->val > val)
            root->left = add(root->left, val);
        else
        {
            root->fr++;
            root->nr++;
            return root;
        }

        root->hight = max(hight(root->left), hight(root->right)) + 1;
        root->nr = sub(root->left) + sub(root->right) + root->fr;

        int b = getBalanced(root);

        if (b > 1)
        {
            if (val < root->left->val)
                return to_right(root);
            else
            {
                root->left = to_left(root->left);
                return to_right(root);
            }
        }
        else if (b < -1)
        {
            if (val > root->right->val)
                return to_left(root);
            else
            {
                root->right = to_right(root->right);
                return to_left(root);
            }
        }

        return root;
    }

    int greaterThan(nod* p, int& val)
    {
        if (p == NULL)
            return 0;

        if (p->val < val)
            return greaterThan(p->right, val);
        return p->fr + greaterThan(p->left, val) + sub(p->right);
    }

    int lessThanPrv(nod* p, int& val)
    {
        if (p == NULL)
            return 0;

        if (p->val > val)
            return lessThanPrv(p->left, val);
        return p->fr + lessThanPrv(p->right, val) + sub(p->left);
    }

    int intervalPrv(nod* p, int& l, int& r)
    {
        if (p == NULL)
            return 0;

        if (p->val < l)
            return intervalPrv(p->right, l, r);
        else if (r < p->val)
            return intervalPrv(p->left, l, r);

        return p->fr + greaterThan(p->left, l) + lessThanPrv(p->right, r);
    }

public:

    Set()
    {
        root = NULL;
    }

    void clear()
    {
        root = NULL;
    }

    void insert(int val)
    {
        if (root == NULL)
        {
            root = new nod;

            root->nr = root->hight = 1;
            root->left = root->right = NULL;
            root->val = val;
            root->fr = 1;
            return;
        }

        root = add(root, val);
    }

    int interval(int l, int r)
    {
        if (l > r)
            return 0;
        return intervalPrv(root, l, r);
    }

    int lessThan(int val)
    {
        return lessThanPrv(root, val);
    }

    int greaterThan(int val)
    {
        return greaterThan(root, val);
    }
};

input fin;
output fout;
//ofstream out("number.out");

// (((1 << k) <= nr && nr < (1 << (k + 1))) || (nr >= (1 << k) + (1 << (k + 1))))

int v[1000001], x[1000001], n, POW[32];
int* vp, * xp, * p;
long long bit[30];
const int p2 = 25165825;
int t[p2 + 1];
Set S;

inline void add(int& poz)
{
    for (int o = poz + 1; o <= p2; o += (o & -o))
        t[o]++;
}

inline int get(int poz)
{
    int s = 0;

    for (int o = poz + 1; o; o -= (o & -o))
        s += t[o];

    return s;
}

int main()
{
    for (int i = 0; i <= 30; i++)
        POW[i] = (1 << i);

    cin >> n;

    for (int i = 1; i <= n; i++)
        cin >> v[i];

    int aux, downLim, upLim, o;

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

        xp = x;
        xp++;

        aux = POW[k] + POW[k + 1];
        downLim = POW[k];
        upLim = POW[k + 1] - 1;

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

            // add element in AIB
            for (o = *xp + 1; o <= p2; o += (o & -o))
                t[o]++;

            //if (aux - *xp > 0)
            //    bit[k] += i - get(aux - *xp - 1);
            //else
            //    bit[k] += i;

            //if (upLim - *xp >= 0)
            //    bit[k] += get(upLim - *xp) - get(max(0, downLim - *xp) - 1);

            vp++;
            xp++;
        }
    }

    /*for (int k = 24; k <= 29; k++)
    {
        vp = v;
        vp++;

        xp = x;
        xp++;

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

            S.insert(*xp);

            bit[k] += S.interval(POW[k] - *xp, POW[k + 1] - *xp - 1) + S.greaterThan(POW[k] + POW[k + 1] - *xp);

            vp++;
            xp++;
        }

        S.clear();
    }*/

    int res = 0;

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

    fout << res;

    return 0;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:457:9: warning: variable 'aux' set but not used [-Wunused-but-set-variable]
  457 |     int aux, downLim, upLim, o;
      |         ^~~
xorsum.cpp:457:14: warning: variable 'downLim' set but not used [-Wunused-but-set-variable]
  457 |     int aux, downLim, upLim, o;
      |              ^~~~~~~
xorsum.cpp:457:23: warning: variable 'upLim' set but not used [-Wunused-but-set-variable]
  457 |     int aux, downLim, upLim, o;
      |                       ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 327 ms 8280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 327 ms 8280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -