Submission #439211

# Submission time Handle Problem Language Result Execution time Memory
439211 2021-06-29T11:46:52 Z LucaIlie XORanges (eJOI19_xoranges) C
100 / 100
183 ms 4332 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 ( rq < l || 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] );

    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 / 2, 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:57:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         scanf( "%d", &tip );
      |         ^~~~~~~~~~~~~~~~~~~
xoranges.c:59:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |             scanf( "%d%d", &p, &x );
      |             ^~~~~~~~~~~~~~~~~~~~~~~
xoranges.c:65:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |             scanf( "%d%d", &p, &u );
      |             ^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 4 ms 460 KB Output is correct
12 Correct 4 ms 484 KB Output is correct
13 Correct 5 ms 424 KB Output is correct
14 Correct 4 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 4300 KB Output is correct
2 Correct 166 ms 4296 KB Output is correct
3 Correct 175 ms 4196 KB Output is correct
4 Correct 183 ms 4228 KB Output is correct
5 Correct 158 ms 4224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 4 ms 460 KB Output is correct
12 Correct 4 ms 484 KB Output is correct
13 Correct 5 ms 424 KB Output is correct
14 Correct 4 ms 460 KB Output is correct
15 Correct 177 ms 4300 KB Output is correct
16 Correct 166 ms 4296 KB Output is correct
17 Correct 175 ms 4196 KB Output is correct
18 Correct 183 ms 4228 KB Output is correct
19 Correct 158 ms 4224 KB Output is correct
20 Correct 161 ms 3900 KB Output is correct
21 Correct 174 ms 3784 KB Output is correct
22 Correct 163 ms 3780 KB Output is correct
23 Correct 181 ms 4332 KB Output is correct
24 Correct 149 ms 4288 KB Output is correct