Bzoj 1452: [Jsoi2009]count (two-dimensional tree-like array)

Source: Internet
Author: User

Descriptioninputoutputsample Input



Sample Output1

2HINT


A simple application of a two-dimensional tree array, where the first-dimensional coordinates of the C array correspond to hashes. If it is a modification, the number of the current value and the ancestors are reduced by 1 before the modification, and the number is added 1.


#include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <set># Include <stack> #include <cctype> #include <algorithm> #define Lson o<<1, L, M#define Rson o<  <1|1, M+1, rusing namespace std;typedef long long ll;const int mod = 99999997;const int MAX = 1000000000;const int MAXN        = 100005;int N, m, op, Q;int in[305][305], c[105][305][305];void Add (int i, int j, int x, int v) {while (I <= N) {        int J1 = j;            while (J1 <= m) {c[x][i][j1] + = V;        J1 + = j1&-j1;    } i + = i&-i;    }}int query (int i, int j, int v) {int ans = 0;        while (i > 0) {int j1 = j;            while (J1 > 0) {ans + = c[v][i][j1];        J1-= j1&-j1;    } I-= i&-i; } return ans;    int main () {//Freopen ("In.txt", "R", stdin);    CIN >> n >> m;      for (int i = 1, i <= N; i++) for (int j = 1; j <= M; j + +) {      CIN >> In[i][j];        Add (I, J, In[i][j], 1);    } cin >> Q;        while (q--) {scanf ("%d", &op);            if (op = = 1) {int A, B, V;            scanf ("%d%d%d", &a, &b, &v);            Add (A, B, In[a][b],-1);            In[a][b] = v;        Add (A, B, In[a][b], 1);            } else {int x1, y1, x2, y2, V;            scanf ("%d%d%d%d%d", &x1, &x2, &y1, &y2, &v);            int ans = query (x2, y2, v) + query (x1-1, Y1-1, v)-Query (x2, Y1-1, v)-query (X1-1, y2, v);        printf ("%d\n", ans); }} return 0;}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.