记录编号 |
391045 |
评测结果 |
AAAAAAAAAA |
题目名称 |
简单题 |
最终得分 |
100 |
用户昵称 |
sxysxy |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
10.850 s |
提交时间 |
2017-04-04 23:46:02 |
内存使用 |
7.94 MiB |
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdarg>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
struct node{
int d[2], l[2], r[2], size, wei, sum;
node *ch[2];
node(int x, int y, int v){
d[0] = x, d[1] = y, wei = v;
ch[0] = ch[1] = NULL;
pushup();
}
void pushup(){
l[0] = r[0] = d[0], l[1] = r[1] = d[1];
sum = wei;
size = 1;
for(int i = 0; i < 2; i++)if(ch[i]){
sum += ch[i]->sum;
size += ch[i]->size;
for(int j = 0; j < 2; j++)
l[j] = min(l[j], ch[i]->l[j]), r[j] = max(r[j], ch[i]->r[j]);
}
}
}*root;
int n, _size, D;
bool cmp(node *x, node *y){
return x->d[D] < y->d[D];
}
node *pool[int(5e5+1)<<2];
node *build(int l, int r, int d){
if(l > r)return NULL;
D = d;
int m = (l+r)>>1;
nth_element(pool+l, pool+m, pool+r+1, cmp);
node *p = pool[m];
p->ch[0] = build(l, m-1, d^1);
p->ch[1] = build(m+1, r, d^1);
p->pushup();
return p;
}
const double rate = 0.66;
void dfs(node *u){
if(!u)return;
dfs(u->ch[0]);
pool[++_size] = u;
dfs(u->ch[1]);
}
void rebuild(node *&u, int d){
_size = 0; dfs(u);
u = build(1, _size, d);
}
void insert(node *&o, node *p, int d){
if(!o)o = p;
else insert(o->ch[p->d[d] >= o->d[d]], p, d^1);
o->pushup();
int maxs = 0;
for(int i = 0; i < 2; i++)if(o->ch[i])maxs = max(maxs, o->ch[i]->size);
if(maxs > o->size * rate)rebuild(o, d);
}
int x0, x1, y0, y1;
int query(node *o){
if(!o || o->l[0] > x1 || o->r[0] < x0 || o->l[1] > y1 || o->r[1] < y0)return 0;
if(x0 <= o->l[0] && o->r[0] <= x1 &&
y0 <= o->l[1] && o->r[1] <= y1)return o->sum;
int s = 0;
if(x0 <= o->d[0] && o->d[0] <= x1 &&
y0 <= o->d[1] && o->d[1] <= y1)s += o->wei;
return s + query(o->ch[0]) + query(o->ch[1]);
}
int main(){
// freopen("test_data.txt", "r", stdin);
freopen("bzoj_4066.in", "r", stdin);
freopen("bzoj_4066.out", "w", stdout);
int n; scanf("%d", &n);
int lastans = 0;
while(true){
int op; scanf("%d", &op);
if(op == 1){
int x, y, w; scanf("%d %d %d", &x, &y, &w);
x ^= lastans, y ^= lastans, w ^= lastans;
node *p = new node(x, y, w);
insert(root, p, 0);
}else if(op == 2){
scanf("%d %d %d %d", &x0, &y0, &x1, &y1);
x0 ^= lastans, y0 ^= lastans, x1 ^= lastans, y1 ^= lastans;
printf("%d\n", lastans = query(root));
}else break;
}
return 0;
}