답안 #779236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779236 2023-07-11T09:24:21 Z vmanz XORanges (eJOI19_xoranges) C++14
0 / 100
375 ms 8648 KB
#include <iostream>
#include <vector>

using namespace std;

void actual(vector<int> &aib, int p, int nou, int vechi)
{
    int n = (int)aib.size() - 1;
    while (p <= n)
    {
        aib[p] ^= vechi;
        aib[p] ^= nou;
        p += (p & -p);
    }
}

int interogare(vector<int> &aib, int p)
{
    int n = (int)aib.size() - 1, rez = 0;
    while (p != 0)
    {
        rez ^= aib[p];
        p -= (p & -p);
    }
    return rez;
}

void scrie_aib(vector<int> &aib)
{
    int n = (int)aib.size() - 1;
    for (int i = 1; i <= n; i++)
    {
        cout << i << ":\t" << aib[i] << "\n";
    }
    cout << "\n";
}

int main()
{
    int n, q;
    cin >> n >> q;
    vector <int> v(n+1), aib_par(n+1, 0), aib_impar(n+1, 0);
    for (int i = 1; i <= n; i++)
    {
        cin >> v[i];
        if (i % 2 == 0)
        {
            actual(aib_par, i, v[i], 0);
        }
        else
        {
            actual(aib_impar, i, v[i], 0);
        }
    }
    //scrie_aib(aib_par);
    //scrie_aib(aib_impar);
    for (int i = 0; i < q; i++)
    {
        int tip;
        cin >> tip;
        if (tip == 1)
        {
            int poz, val_nou;
            cin >> poz >> val_nou;
            if (poz % 2 == 0)
            {
                actual(aib_par, poz, val_nou, v[poz]);
                v[poz] = val_nou;
                //scrie_aib(aib_par);
            }
            else
            {
                actual(aib_impar, poz, val_nou, v[poz]);
                v[poz] = val_nou;
                //scrie_aib(aib_impar);
            }
        }
        else
        {
            int st, dr;
            cin >> st >> dr;
            int rez = 0;
            if ((dr - st + 1) % 2 == 0)
            {
                cout << rez << "\n";
            }
            else
            {
                if (st % 2 == 0)
                {
                    rez = interogare(aib_par, dr) - interogare(aib_par, st - 1);
                }
                else
                {
                    rez = interogare(aib_impar, dr) - interogare(aib_impar, st - 1);
                }
                cout << rez << "\n";
            }
        }
    }
    return 0;
}

Compilation message

xoranges.cpp: In function 'int interogare(std::vector<int>&, int)':
xoranges.cpp:19:9: warning: unused variable 'n' [-Wunused-variable]
   19 |     int n = (int)aib.size() - 1, rez = 0;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 375 ms 8648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -