답안 #779258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779258 2023-07-11T09:37:53 Z vmanz XORanges (eJOI19_xoranges) C++14
100 / 100
412 ms 8644 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 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 7 ms 440 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 9 ms 480 KB Output is correct
14 Correct 11 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 412 ms 3836 KB Output is correct
2 Correct 387 ms 8644 KB Output is correct
3 Correct 388 ms 8640 KB Output is correct
4 Correct 377 ms 8260 KB Output is correct
5 Correct 376 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 7 ms 440 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 9 ms 480 KB Output is correct
14 Correct 11 ms 468 KB Output is correct
15 Correct 412 ms 3836 KB Output is correct
16 Correct 387 ms 8644 KB Output is correct
17 Correct 388 ms 8640 KB Output is correct
18 Correct 377 ms 8260 KB Output is correct
19 Correct 376 ms 8284 KB Output is correct
20 Correct 282 ms 8308 KB Output is correct
21 Correct 294 ms 8396 KB Output is correct
22 Correct 285 ms 8388 KB Output is correct
23 Correct 369 ms 8344 KB Output is correct
24 Correct 368 ms 8264 KB Output is correct