Bzoj 1513 POI 2006 Tet-tetris 3D Two-dimensional line segment tree

Source: Internet
Author: User

The main question: three-dimensional Tetris, asked how high the last stack.


Idea: two-dimensional line tree of the bare topic. Note, however, that the two-dimensional line segment tree does not support marking under wear. So don't pass, each time you update the answer, look at the tag, and then use all the tags to compare the size of the return.

Look at the code specifically, do not know how to say.


CODE:

#define _crt_secure_no_warnings#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 1100using namespace std; #define LEFT (POS << 1) #define RIGHT (POS << 1|1) int x, y; struct segtreey{//data int tree[max << 1],tag[max << 1];int Ask (int l,int r,int x,int y,int pos) {if (L = = x & & r = = y) return tree[pos];int mid = (L + r) >> 1,re = tag[pos];if (y <= mid) return Max (Re,ask (L,mid,x,y,left)) , if (x > Mid) return Max (Re,ask (mid + 1,r,x,y,right)), int left = Ask (L,mid,x,mid,left), int. right = Ask (mid + 1,r,mid + 1, Y,right); return Max (Re,max (Left,right));} void Modify (int l,int r,int x,int y,int c,int pos) {Tree[pos] = max (tree[pos],c); if (L = = x && y = = r) {Tag[pos] = Max (tag[pos],c); return;}  int mid = (L + R) >> 1;if (y <= mid) Modify (l,mid,x,y,c,left); else if (x > Mid) Modify (mid + 1,r,x,y,c,right); else {Modify (l,mid,x,mid,c,left); Modify (mid + 1,r,mid + 1,y,c,right);}}; int Ask_x,ask_y;strucT segtreex{//addressing Segtreey tree[max << 1],tag[max << 1];int Ask (int l,int r,int x,int y,int pos) {if (L = = x & & y = = r) return Tree[pos]. Ask (0,y,ask_x,ask_y,1); int mid = (L + r) >> 1,re = Tag[pos]. Ask (0,y,ask_x,ask_y,1), if (Y <= mid) return Max (Re,ask (l,mid,x,y,left)), if (X > Mid) return Max (Re,ask (Mid + 1,r,x,y ), int left = Ask (l,mid,x,mid,left), int right = Ask (Mid + 1,r,mid + 1,y,right); return Max (Re,max (Left,right));} void Modify (int l,int r,int x,int y,int c,int pos) {Tree[pos]. Modify (0,y,ask_x,ask_y,c,1), if (L = = x && Y = = r) {Tag[pos]. Modify (0,y,ask_x,ask_y,c,1); return;}  int mid = (L + R) >> 1;if (y <= mid) Modify (l,mid,x,y,c,left); else if (x > Mid) Modify (mid + 1,r,x,y,c,right); else {Modify (l,mid,x,mid,c,left); Modify (mid + 1,r,mid + 1,y,c,right);}} Solver;int Cnt;int Main () {cin >> X >> Y >> cnt;  X + = 10,y + = 10;for (int d,s,w,x,y,i = 1; I <= cnt; ++i) {scanf ("%d%d%d%d%d", &d,&s,&w,&x,&y); ask_x = Y,ask_y = y + s-1;int height = solver. Ask (0,x,x,x + d-1,1); Solver. Modify (0,x,x,x + d-1,height + w,1);} ask_x = 0,ask_y = Y;cout << solver. Ask (0,x,0,x,1) << Endl;return 0;}


Bzoj 1513 POI 2006 Tet-tetris 3D Two-dimensional line segment tree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.