BZOJ1452 [JSOI2009]Count Solution

來源:互聯網
上載者:User

標籤:io   os   ar   for   sp   on   amp   ad   line   

題意:自行腦補

做法:直接開權值那麼多的二維樹狀數組暴力。

Code:

#include <cstdio>#include <cctype>#include <iostream>#include <algorithm>using namespace std; inline int getc() {    static const int L = 1 << 15;    static char buf[L], *S = buf, *T = buf;    if (S == T) {        T = (S = buf) + fread(buf, 1, L, stdin);        if (S == T)            return EOF;    }    return *S++;}inline int getint() {    int c;    while(!isdigit(c = getc()));    int tmp = c - '0';    while(isdigit(c = getc()))        tmp = (tmp << 1) + (tmp << 3) + c - '0';    return tmp;} int A[101][301][301], w[301][301];int n, m;void modify(int c, int x, int y, int add) {    int t;    for(; x <= n; x += x & -x) {        for(t = y; t <= m; t += t & -t)            A[c][x][t] += add;    }}int get(int c, int x, int y) {    int res = 0, t;    for(; x; x -= x & -x) {        for(t = y; t; t -= t & -t)            res += A[c][x][t];    }    return res;} int main() {    n = getint();    m = getint();         register int i, j;    int x;    for(i = 1; i <= n; ++i)        for(j = 1; j <= m; ++j) {            x = getint();            w[i][j] = x;            modify(x, i, j, 1);        }         int Q = getint();    int ope, x1, y1, x2, y2, c;    while(Q--) {        ope = getint();        if (ope == 1) {            x1 = getint(), y1 = getint(), c = getint();            modify(w[x1][y1], x1, y1, -1);            modify(w[x1][y1] = c, x1, y1, 1);        }        else {            x1 = getint(), x2 = getint(), y1 = getint(), y2 = getint();            c = getint();            printf("%d\n", get(c, x2, y2) - get(c, x1 - 1, y2) - get(c, x2, y1 - 1) + get(c, x1 - 1, y1 - 1));        }    }         return 0;}


BZOJ1452 [JSOI2009]Count Solution

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.