Vijos1512superbrother hit the mole.

Source: Internet
Author: User

Background
Superbrother in the computer room idle nothing to do (compare his noip, it is ironic ah ...), so bored to start playing "hit the Mole" ...
Describe
In this "hit the Mole" game, the mole will occasionally drill out of the hole, but will not get into the hole (mole really bold ...) )。 The openings are in a square of size n (n<=1024). This square is in a planar Cartesian coordinate system, the lower left corner is (0,0), and the upper-right corner is (n-1,n-1). The location of the hole is the whole point, that is, the horizontal ordinate is an integer. And Superbrother will occasionally want to know the total number of moles in a certain range. This is your mission.
Format
Input format

There are multiple lines for each input file.
The first line, a number n, represents the mole's range.
Each subsequent line has a number m at the beginning, indicating a different operation:
M=1, then followed by 3 numbers x,y,k (0<=x,y

#include <cstdio> using namespace std;

int n,f[1030][1030]={0},m;
    int read () {int x=0,f=1;
    Char Ch=getchar ();
        while (ch< ' 0 ' && ch> ' 9 ') {if (ch== '-') f=-1;
      Ch=getchar ();
        } while (ch>= ' 0 ' && ch<= ' 9 ') {x=x*10+ch-' 0 ';
      Ch=getchar ();
} return x*f;

} int lowbit (int x) {return x& (-X);}
    void Add (int x,int y,int t) {int i,j;
For (I=x;i<=n;i+=lowbit (i)) for (J=y;j<=n;j+=lowbit (j)) f[i][j]+=t;
    } int query (int x,int y) {int i,j,ans=0;
    For (I=x;i>=1;i-=lowbit (i)) for (J=y;j>=1;j-=lowbit (j)) Ans+=f[i][j];
return ans;
    } int main () {int x,y,x1,y1,t;
    N=read ();
            while (M=read (), m!=3) {if (m==1) {x=read () +1;
            Y=read (+1);
            T=read ();
          Add (x,y,t);
            } if (m==2) {x=read () +1; Y=read () +1;
            X1=read (+1);
            Y1=read (+1);
          printf ("%d\n", Query (x1,y1)-query (x-1,y1)-query (x1,y-1) +query (x-1,y-1));
}} 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.