Submission #439168

# Submission time Handle Problem Language Result Execution time Memory
439168 2021-06-29T10:59:17 Z LucaIlie XORanges (eJOI19_xoranges) C
0 / 100
170 ms 4244 KB
#include <stdio.h>

#define MAX_N 200000

int xor[2][4 * MAX_N / 2], orange[2][(MAX_N + 1)/ 2];

void construct( int l, int r, int nod, int v[], int aint[] ) {
    int mid = (l + r) / 2;

    if ( l == r )
        aint[nod] = v[l];
    else {
        construct( l, mid, nod * 2 + 1, v, aint );
        construct( mid + 1, r, nod * 2 + 2, v, aint );
        aint[nod] = aint[nod * 2 + 1] ^ aint[nod * 2 + 2];
    }
}

void update( int i, int l, int r, int nod, int v[], int aint[] ) {
    int mid = (l + r) / 2;

    if ( l == r )
        aint[nod] = v[l];
    else {
        if ( i <= mid )
            update( i, l, mid, nod * 2 + 1, v, aint );
        else
            update( i, mid + 1, r, nod * 2 + 2, v, aint );
        aint[nod] = aint[nod * 2 + 1] ^ aint[nod * 2 + 2];
    }
}

int query( int lq, int rq, int l, int r, int nod, int v[], int aint[] ) {
    int mid = (l + r) / 2;

    if ( lq <= l && r <= rq )
        return aint[nod];
    if ( l > rq || r < lq )
        return 0;
    return query( lq, rq, l, mid, nod * 2 + 1, v, aint ) ^ query( lq, rq, mid + 1, r, nod * 2 + 2, v, aint );
}

int main() {
    int n, q, tip, p, u, x, i;
    int len[2];

    scanf( "%d%d", &n, &q );
    for ( i = 0; i < n; i++ )
        scanf( "%d", &orange[i % 2][i / 2] );
    len[0] = (n + 1) / 2;
    len[1] = n / 2;

    for ( p = 0; p < 2; p++ )
        construct( 0, len[p] - 1, 0, orange[p], xor[p] );
    printf( "%d ", xor[1][0] );

    for ( i = 0; i < q; i++ ) {
        scanf( "%d", &tip );
        if ( tip == 1 ) {
            scanf( "%d%d", &p, &x );
            p--;
            orange[p % 2][p / 2] = x;
            update( p, 0, len[p % 2] - 1, 0, orange[p % 2], xor[p % 2] );
        }
        else {
            scanf( "%d%d", &p, &u );
            p--;
            u--;
            if ( (u - p + 1) % 2 == 0 )
                printf( "0\n" );
            else
                printf( "%d\n", query( p / 2, u / 2, 0, len[p % 2] - 1, 0, orange[p % 2], xor[p % 2] ) );
        }
    }

    return 0;
}

Compilation message

xoranges.c: In function 'main':
xoranges.c:47:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     scanf( "%d%d", &n, &q );
      |     ^~~~~~~~~~~~~~~~~~~~~~~
xoranges.c:49:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         scanf( "%d", &orange[i % 2][i / 2] );
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xoranges.c:58:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         scanf( "%d", &tip );
      |         ^~~~~~~~~~~~~~~~~~~
xoranges.c:60:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |             scanf( "%d%d", &p, &x );
      |             ^~~~~~~~~~~~~~~~~~~~~~~
xoranges.c:66:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |             scanf( "%d%d", &p, &u );
      |             ^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 170 ms 4244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -