poj2155(树状数组,区间修改,点查询)

来源:互联网 发布:optisystem mac air 编辑:程序博客网 时间:2024/06/05 18:40

题目链接:点击打开链接

// poj2155// 题目大意:一个01矩阵,每次变换一个区间(0->1,1->0),问某个点是多少#include <iostream>#include <algorithm>#include <fstream>#include <sstream>#include <iomanip>#include <cstdio>#include <vector>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <set>#include <map>#define L 1500using namespace std;int c[1500][1500], n;void add(int x, int y, int d){for(int i= x; i<= L; i+= i&-i)for(int j= y; j<= L; j+= j&-j)c[i][j]+= d;}int sum(int x, int y){int s= 0;for(int i= x; i> 0; i-= i&-i)for(int j= y; j> 0; j-= j&-j)s+= c[i][j];return s;}int main(){    int T, t; cin >> T;    while(T--)    {        scanf("%d%d", &n, &t);        memset(c, 0, sizeof(c));        while(t--)        {            char ch[10]; scanf("%s", ch);            if(ch[0]== 'C')            {                int a, b, x, y; scanf("%d%d%d%d", &a, &b, &x, &y); x++; y++;                add(x, y, 1); add(a, b, 1); add(x, b, 1); add(a, y, 1);            }            if(ch[0]== 'Q')            {                int x, y; scanf("%d%d", &x, &y);                printf("%d\n", sum(x, y)& 1);            }        }        if(T) printf("\n");    }    return 0;}


阅读全文
0 0