Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1000MS AC 跑得太慢了

Posted by lz1 at 2010-11-27 13:34:07 on Problem 1195
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 1034
int p[N];
int a[N][N];
int t,n;

void add(int x,int y,int c){
     while (x<=n){
           int d=y;
           while (d<=n)
                 a[x][d]+=c,d+=p[d];
           x+=p[x];
           }
     }

int sum(int x,int y){
    int t=0;
    while (x>0){
          int d=y;
          while (d>0)
                t+=a[x][d],d-=p[d];
          x-=p[x];
          }
    return  t;
    }

int main(void){
    for (int i=1;i<=1024;i++)p[i]=i&(-i);
    scanf ("%d%d",&t,&n);
    while (scanf ("%d",&t)!=EOF&&t!=3){
          if (t==1){
             int x,y,d;
             scanf ("%d%d%d",&x,&y,&d),x++,y++;
             add(x,y,d);
             }
          else{
              int x,y,p,q,ans;
              scanf ("%d%d%d%d",&x,&y,&p,&q),x++,y++,p++,q++;
              ans=sum(p,q)+sum(x-1,y-1)-sum(x-1,q)-sum(p,y-1);
              printf ("%d\n",ans);
              }
          }
    return 0;
    }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator