TOPIC

10% Wrong Answer - HELP

Evandro asked 2 years ago

Alguem pode me ajudar com o erro que esta dando ? eu nao sei pra que caso esta dando errado, todos os que eu testei deram certos ate agora.

#include <bits/stdc++.h>

#define MAX 1005
#define swap(a, b) a ^= b ^= a ^= b

int BIT[MAX][MAX];

void updateBIT(int x, int y, int v){
    for(; x < MAX; x += (x & -x))
        for(int z = y; z <= MAX; z += (z & -z))
            BIT[x][z] += v;
}

int getSum(int x, int y){
    int sum = 0;

    for(; x > 0; x -= (x & -x))
        for(int z = y; z > 0; z -= (z & -z))
            sum += BIT[x][z];

    return sum;
}

int getQuery(int x1, int y1, int x2, int y2){
    int ans;

    if(x1 > x2) swap(x1, x2);
    if(y1 > y2) swap(y1, y2);

    ans = getSum(x2, y2) - getSum(x1 - 1, y2) - getSum(x2, y1 - 1) + getSum(x1 - 1, y1 - 1);

    return ans;
}

int main(){
    int x, y, p, q, sum;
    int n, x1, x2, y1, y2;
    char op;

    scanf("%d %d %d", &x, &y, &p);
    while(x || y || p){
        for(int i = 0; i <= x; i++)
            for(int j = 0; j <= y; j++)
                BIT[i][j] = 0;

        scanf("%d", &q);

        for(int i = 0; i < q; i++){
            scanf("%c", &op);

            if(op == 'A'){
                scanf("%d %d %d", &n, &x1, &y1);
                updateBIT(x1+1, y1+1, n);
            }
            else if(op == 'P'){
                scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
                sum = getQuery(x1+1, y1+1, x2+1, y2+1);
                printf("%d\n", sum*p);
            }
        }
        printf("\n");
        scanf("%d %d %d", &x, &y, &p);
    }

    return 0;
}

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.