Language: C

#include <stdio.h>

typedef struct {
    long long rotate;
    int flip;
} Query;

long long k, n, q;

tree[(1 << 20) * 2 + 5];
void init(void)
{
    long long _n = n;
    long long i;
    
    while (_n < n) {
        _n *= 2;
    }
    n = 2;
    
    for (long long i = 0; i <= n * 2; i++) {
        tree[i] = (Query){0, 0};
    }
    
    return;
}
Query merge(Query a, Query b)
{
    Query x;
    
    x.flip = (a.flip + b.flip) % 2;
    
    if (a.flip) x.rotate = a.rotate + b.rotate;
    else x.rotate = a.rotate - b.rotate;
    
    return Query;
}

void update(Query a, long long k)
{
    k += (n - 1);
    
    tree[k] = a;
    
    while (k > 0) {
        k = (k + 1) / 2;
        tree[k] = merge(tree[k * 2 + 1], tree[k * 2 + 2]);
    }
    
    return;
}

Query sum(void)
{
    return tree[0];
}

int main()
{
    long long a;
    scanf("%lld %lld %lld", &k, &n, &q);
    
    for (long long i = 0; i < n; i++) {
        Query x = (Query){0, 0};
        scanf("%lld", &a);
        
        if (a == 0) x.flip = 1;
        x.rotate = a;
        
        update(x, i);
    }
    
    for (long long i = 0; i < q; i++) {
        long long l, r;
        
        scanf("%lld %lld", &l, &r);
        
        Query left = tree[l + (n - 1)];
        Qeury right = tree[r + (n - 1)];
        
        update(left, r);
        update(right, l);
        
        
        Query total = sum();
        
        total.rotate = (k - total.rotate) % k;
        
        long long num = 1 + total.rotate;
        
        if (total.flip) {
            if (num == 1) {
                num = -1;
            } else {
                num = num - (k + 2);
            }
        }
        
        printf("%lld\n", num);
    }
    
    return 0;
}


Compiler output:
main.c:10:1: warning: data definition has no type or storage class
   10 | tree[(1 << 20) * 2 + 5];
      | ^~~~
main.c:10:1: error: type defaults to 'int' in declaration of 'tree' [-Wimplicit-int]
main.c: In function 'init':
main.c:22:19: error: incompatible types when assigning to type 'int' from type 'Query'
   22 |         tree[i] = (Query){0, 0};
      |                   ^
main.c: In function 'merge':
main.c:36:12: error: expected expression before 'Query'
   36 |     return Query;
      |            ^~~~~
main.c: In function 'update':
main.c:43:15: error: incompatible types when assigning to type 'int' from type 'Query'
   43 |     tree[k] = a;
      |               ^
main.c:47:29: error: incompatible type for argument 1 of 'merge'
   47 |         tree[k] = merge(tree[k * 2 + 1], tree[k * 2 + 2]);
      |                         ~~~~^~~~~~~~~~~
      |                             |
      |                             int
main.c:27:19: note: expected 'Query' but argument is of type 'int'
   27 | Query merge(Query a, Query b)
      |             ~~~~~~^
main.c:47:46: error: incompatible type for argument 2 of 'merge'
   47 |         tree[k] = merge(tree[k * 2 + 1], tree[k * 2 + 2]);
      |                                          ~~~~^~~~~~~~~~~
      |                                              |
      |                                              int
main.c:27:28: note: expected 'Query' but argument is of type 'int'
   27 | Query merge(Query a, Query b)
      |                      ~~~~~~^
main.c: In function 'sum':
main.c:55:16: error: incompatible types when returning type 'int' but 'Query' was expected
   55 |     return tree[0];
      |            ~~~~^~~
main.c: In function 'main':
main.c:78:22: error: invalid initializer
   78 |         Query left = tree[l + (n - 1)];
      |                      ^~~~
main.c:79:9: error: unknown type name 'Qeury'; did you mean 'Query'?
   79 |         Qeury right = tree[r + (n - 1)];
      |         ^~~~~
      |         Query
main.c:82:16: error: incompatible type for argument 1 of 'update'
   82 |         update(right, l);
      |                ^~~~~
      |                |
      |                int
main.c:39:19: note: expected 'Query' but argument is of type 'int'
   39 | void update(Query a, long long k)
      |             ~~~~~~^