zoukankan      html  css  js  c++  java
  • POJ 2155 Matrix

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<sstream>
    #include<algorithm>
    #include<queue>
    #include<deque>
    #include<iomanip>
    #include<vector>
    #include<cmath>
    #include<map>
    #include<stack>
    #include<set>
    #include<fstream>
    #include<memory>
    #include<list>
    #include<string>
    using namespace std;
    typedef long long LL;
    typedef unsigned long long ULL;
    #define MAXN 1000 + 23
    #define L 31
    #define INF 1000000009
    #define eps 0.00000001
    #define sf(a) scanf("%d",&a)
    int T, n, k;
    int a[MAXN][MAXN];
    char op[2];
    inline int lowbit(int x)
    {
        return x&(-x);
    }
    void update(int x, int y)
    {
        for (int i = x; i < MAXN; i += lowbit(i) )
        {
            for (int j = y; j < MAXN; j += lowbit(j) )
            {
                a[i][j]++;
            }
        }
    }
    
    int query(int x, int y)
    {
        int sum = 0;
        for (int i = x; i > 0; i -= lowbit(i))
        {
            for (int j = y; j > 0; j -= lowbit(j))
            {
                sum += a[i][j];
            }
        }
        return sum;
    }
    int main()
    {
        int x1, y1, x2, y2;
        sf(T);
        while (T--)
        {
            memset(a, 0, sizeof(a));
            sf(n), sf(k);
            for (int i = 0; i < k; i++)
            {
                scanf("%s", op);
                if (op[0] == 'C')
                {
                    sf(x1), sf(y1), sf(x2), sf(y2);
                    x1++, y1++, x2++, y2++;//避免出现0
    
                    update(x1, y1);
                    update(x1, y2 + 1);
                    update(x2 + 1, y1);
                    update(x2 + 1, y2 + 1);//重叠的部分加上 
                }
                else
                {
                    sf(x1), sf(y1);
                    x1++, y1++;
                    printf("%d
    ", query(x1, y1) % 2);
                }
            }
            cout << endl;
        }
    }
  • 相关阅读:
    java 集合框架(十五)Deque
    java 集合框架(十四)Queue
    java 集合框架(十)List
    java 集合框架(四)Set
    java 集合框架(三)Collection
    java 集合框架(一)概述
    java 集合框架(二)Iterable接口
    java I/O框架 (四)文件流
    全零网络IP地址0.0.0.0表示意义详谈
    windows在cmd执行svn 命令
  • 原文地址:https://www.cnblogs.com/joeylee97/p/7468813.html
Copyright © 2011-2022 走看看