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

求大佬帮我看一下我的四叉线段树哪里写错了,样例都对,是WA

Posted by swust5102177231 at 2018-11-20 21:24:44 on Problem 1195
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int maxN = 1024;
int Mem, N, op;
int tree[maxN*maxN<<2];
bool yezi[maxN*maxN<<2];
void buildTree(int rt, int xl, int yl, int xr, int yr)
{
    if(xl == xr && yl == yr)
    {
        tree[rt] = Mem;
        return;
    }
    int mid_x = (xl + xr)>>1, mid_y = (yl + yr)>>1;
    buildTree((rt<<2)-2, xl, yl, mid_x, mid_y);
    if(yl != yr) buildTree((rt<<2)-1, xl, mid_y+1, mid_x, yr);
    else { tree[(rt<<2)-1]=0; yezi[(rt<<2)-1]=true; }
    if(xl != xr) buildTree((rt<<2), mid_x+1, yl, xr, mid_y);
    else { tree[(rt<<2)]=0; yezi[(rt<<2)]=true; }
    if(xl!=xr && yl!=yr) buildTree((rt<<2)+1, mid_x+1, mid_y+1, xr, yr);
    else { tree[(rt<<2)+1]=0; yezi[(rt<<2)+1]=true; }
    tree[rt] = tree[(rt<<2)-2] + tree[(rt<<2)-1] + tree[(rt<<2)] + tree[(rt<<2)+1];
}
void update(int rt, int xl, int yl, int xr, int yr, int qx, int qy, int val)
{
    if(yezi[rt]) return;
    if(xl == xr && yl == yr) { tree[rt]+=val; return; }
    int mid_x = (xl + xr)>>1, mid_y = (yl + yr)>>1;
    if(qx<=mid_x && qy<=mid_y) update((rt<<2)-2, xl, yl, mid_x, mid_y, qx, qy, val);
    else if(qx<=mid_x && qy>mid_y) update((rt<<2)-1, xl, mid_y+1, mid_x, yr, qx, qy, val);
    else if(qx>mid_x && qy<=mid_y) update((rt<<2), mid_x+1, yl, xr, mid_y, qx, qy, val);
    else if(qx>mid_x && qy>mid_y) update((rt<<2)+1, mid_x+1, mid_y+1, xr, yr, qx, qy, val);
    tree[rt] = tree[(rt<<2)-2] + tree[(rt<<2)-1] + tree[(rt<<2)] + tree[(rt<<2)+1];
}
int query(int rt, int xl, int yl, int xr, int yr, int qlx, int qly, int qrx, int qry)
{
    if(yezi[rt]) return 0;
    if(qlx<=xl && qly<=yl && qrx>=xr && qry>=yr) return tree[rt];
    int mid_x = (xl + xr)>>1, mid_y = (yl + yr)>>1;
    int ans = 0;
    if(qlx<=mid_x && qly<=mid_y) ans+=query((rt<<2)-2, xl, yl, mid_x, mid_y, qlx, qly, qrx, qry);
    if(qlx<=mid_x && qry>mid_y) ans+=query((rt<<2)-1, xl, mid_y+1, mid_x, yr, qlx, qly, qrx, qry);
    if(qrx>mid_x && qly<=mid_y) ans+=query((rt<<2), mid_x+1, yl, xr, mid_y, qlx, qly, qrx, qry);
    if(qrx>mid_x && qly>mid_y) ans+=query((rt<<2)+1, mid_x+1, mid_y+1, xr, yr, qlx, qly, qrx, qry);
    return ans;
}
int main()
{
    while(scanf("%d%d", &Mem, &N)!=EOF)
    {
        memset(yezi, false, sizeof(yezi));
        buildTree(1, 0, 0, N-1, N-1);
        while(scanf("%d", &op) && op!=3)
        {
            if(op == 1)
            {
                int e1, e2, e3;
                scanf("%d%d%d", &e1, &e2, &e3);
                update(1, 0, 0, N-1, N-1, e1, e2, e3);
            }
            else
            {
                int e1, e2, e3, e4;
                scanf("%d%d%d%d", &e1, &e2, &e3, &e4);
                printf("%d\n", query(1, 0, 0, N-1, N-1, e1, e2, e3, e4));
            }
        }
    }
    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