zoukankan      html  css  js  c++  java
  • F

     1 // 升维
     2 #include <bits/stdc++.h>
     3 using namespace std;
     4 const int MAX = 1e3+10;
     5 int sum[MAX][MAX];
     6 void init() {
     7     memset(sum,0,sizeof(sum));
     8 }
     9 int lowbit(int x) {
    10     return x&-x;
    11 }
    12 void modify(int x,int y,int val) {
    13     for(int i=x;i<MAX;i+=lowbit(i)) {
    14         for(int j=y;j<MAX;j+=lowbit(j)) {
    15             sum[i][j]+=val;
    16         }
    17     }
    18 }
    19 int query(int x,int y) {
    20     int res=0;
    21     for(int i=x;i;i-=lowbit(i)) {
    22         for(int j=y;j;j-=lowbit(j)) {
    23             res+=sum[i][j];
    24         }
    25     }
    26     return res;
    27 }
    28 int main() {
    29     int n,m;
    30     int x,y;
    31     while(scanf("%d %d",&n,&m)==2) {
    32         init();
    33         for(int i=1;i<=n;i++) {
    34             scanf("%d %d",&x,&y);
    35             modify(x,y,1);
    36         }
    37         for(int i=1;i<=m;i++) {
    38             scanf("%d %d",&x,&y);
    39             printf("%d ",query(MAX-2,y)-query(x-1,y));
    40         }
    41     }
    42     return 0;
    43 }
    View Code
  • 相关阅读:
    第04组 Alpha冲刺(4/6)
    第04组 Alpha冲刺(3/6)
    第04组 Alpha冲刺(2/6)
    第04组 Alpha冲刺(1/6)
    第04组 团队Git现场编程实战
    第04组 团队项目-需求分析报告
    团队项目-选题报告
    第二次结对编程作业
    第04组 Alpha冲刺(6/6)
    第04组 Alpha冲刺(5/6)
  • 原文地址:https://www.cnblogs.com/acvc/p/4419857.html
Copyright © 2011-2022 走看看