zoukankan      html  css  js  c++  java
  • Mobile phones POJ

    Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares form an S * S matrix with the rows and columns numbered from 0 to S-1. Each square contains a base station. The number of active mobile phones inside a square can change because a phone is moved from a square to another or a phone is switched on or off. At times, each base station reports the change in the number of active phones to the main base station along with the row and the column of the matrix. 

    Write a program, which receives these reports and answers queries about the current total number of active mobile phones in any rectangle-shaped area. 

    Input

    The input is read from standard input as integers and the answers to the queries are written to standard output as integers. The input is encoded as follows. Each input comes on a separate line, and consists of one instruction integer and a number of parameter integers according to the following table. 

    The values will always be in range, so there is no need to check them. In particular, if A is negative, it can be assumed that it will not reduce the square value below zero. The indexing starts at 0, e.g. for a table of size 4 * 4, we have 0 <= X <= 3 and 0 <= Y <= 3. 

    Table size: 1 * 1 <= S * S <= 1024 * 1024 
    Cell value V at any time: 0 <= V <= 32767 
    Update amount: -32768 <= A <= 32767 
    No of instructions in input: 3 <= U <= 60002 
    Maximum number of phones in the whole table: M= 2^30 

    Output

    Your program should not answer anything to lines with an instruction other than 2. If the instruction is 2, then your program is expected to answer the query by writing the answer as a single line containing a single integer to standard output.

    Sample Input

    0 4
    1 1 2 3
    2 0 0 2 2 
    1 1 1 2
    1 1 2 -1
    2 1 1 2 3 
    3
    

    Sample Output

    3
    4

    板子题
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <queue>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <set>
     7 #include <iostream>
     8 #include <map>
     9 #include <stack>
    10 #include <string>
    11 #include <vector>
    12 #define pi acos(-1.0)
    13 #define eps 1e-6
    14 #define fi first
    15 #define se second
    16 #define lson l,m,rt<<1
    17 #define rson m+1,r,rt<<1|1
    18 #define bug         printf("******
    ")
    19 #define mem(a,b)    memset(a,b,sizeof(a))
    20 #define fuck(x)     cout<<"["<<x<<"]"<<endl
    21 #define f(a)        a*a
    22 #define sf(n)       scanf("%d", &n)
    23 #define sff(a,b)    scanf("%d %d", &a, &b)
    24 #define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
    25 #define pf          printf
    26 #define FRE(i,a,b)  for(i = a; i <= b; i++)
    27 #define FREE(i,a,b) for(i = a; i >= b; i--)
    28 #define FRL(i,a,b)  for(i = a; i < b; i++)
    29 #define FRLL(i,a,b) for(i = a; i > b; i--)
    30 #define FIN freopen("DATA.txt","r",stdin)
    31 #define lowbit(x)   x&-x
    32 #pragma comment (linker,"/STACK:102400000,102400000")
    33 
    34 using namespace std;
    35 typedef long long LL ;
    36 const int maxn = 2e3 + 10;
    37 int n, k, c[maxn][maxn];
    38 void updata(int x, int y, int z) {
    39     for (int i = x ; i <= n ; i += lowbit(i))
    40         for (int j = y ; j <= n ; j += lowbit(j))
    41             c[i][j] += z;
    42 }
    43 int sum(int x, int y) {
    44     int ret = 0;
    45     for (int i = x ; i > 0 ; i -= lowbit(i))
    46         for (int j = y ; j > 0 ; j -= lowbit(j))
    47             ret += c[i][j];
    48     return ret;
    49 }
    50 int main() {
    51     scanf("%d%d", &k, &n);
    52     while(1) {
    53         scanf("%d", &k);
    54         if (k == 1) {
    55             int x, y, z;
    56             sfff(x, y, z);
    57             x++, y++;
    58             updata(x, y, z);
    59         }
    60         if (k == 2) {
    61             int x1,y1,x2,y2;
    62             scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    63             x1++, y1++, x2++, y2++;
    64             int ans = sum(x2, y2) - sum(x1 - 1, y2) - sum(x2, y1 - 1) + sum(x1 - 1, y1 - 1);
    65             printf("%d
    ", ans);
    66         }
    67         if (k == 3) break;
    68     }
    69     return 0;
    70 }


  • 相关阅读:
    一个具体的例子学习Java volatile关键字
    JavaScript实现的水果忍者游戏,支持鼠标操作
    记录我开发工作中遇到HTTP跨域和OPTION请求的一个坑
    微信程序开发系列教程(四)使用微信API创建公众号自定义菜单
    微信程序开发系列教程(三)使用微信API给微信用户发文本消息
    Java实现 LeetCode 547 朋友圈(并查集?)
    Java实现 LeetCode 547 朋友圈(并查集?)
    Java实现 LeetCode 547 朋友圈(并查集?)
    Java实现 LeetCode 546 移除盒子(递归,vivo秋招)
    Java实现 LeetCode 546 移除盒子(递归,vivo秋招)
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/9415313.html
Copyright © 2011-2022 走看看