WHU 1581 Union of cubes

Source: Internet
Author: User

Title Link: http://acm.whu.edu.cn/land/problem/detail?problem_id=1581

---------------------------------------------------------------------------------------

observed that the first dimension is the largest only $10$ so the first dimension can be directly enumerated $ ($) $

observed that the second dimension is the largest only $100$ so the second dimension can also continue to enumerate $ ($ cut the rectangle into segments $) $

If the last dimension is covered with a segment tree, the complexity is

$O (N^{2}kmlog (n * k ^ 2)) $ $ (n <=, K <=, M <= 1000) $

Since the time limit is only $500ms$, there are multiple sets of data that are likely to $t$ out.

Think about it, we'll find only the interval override operation without interval modification operation $ ($ equivalent to No fallback feature $) $

Then just maintain the right end of the overlay segment for each point.

And the maintenance operation is obviously to use and check the set is more convenient

Complexity reduced by one $log$ after a single group of $10^6$ multiple groups will not $t$

1#include <cstdio>2#include <cstring>3#include <cmath>4#include <algorithm>5 using namespacestd;6 inta[ One][ the][1010], fa[ One][ the][1010];7 intN, K0, M, N2, N3, sum, ans;8 intP1, Q1, R1, p2, Q2, R2;9 intFINDF (intXintYintz)Ten { One     if(Fa[x][y][z]! =z) AFA[X][Y][Z] =findf (x, Y, fa[x][y][z]); -     returnFa[x][y][z]; - } the intMain () - { -      while(SCANF ("%d%d%d", &n, &k0, &m)! =EOF) -     { +N2 = n *K0; -n3= N2 *K0; +          for(inti =1; I <= N; ++i) A              for(intj =1; J <= N2; ++j) at             { -                  for(intK =1; K <= N3; ++k) -                 { -scanf"%d", &a[i][j][k]); -FA[I][J][K] =K; -                 } inFa[i][j][n3 +1] = n3 +1; -             } tosum =0; +Ans =-1e9; -          while(m--) the         { *scanf"%d%d%d%d%d%d", &p1, &q1, &r1, &AMP;P2, &AMP;Q2, &r2); $              for(inti = p1; I <= p2; ++i)Panax Notoginseng                  for(intj = Q1; J <= Q2; ++j) -                      for(intK = R1; K <= R2; K =Fa[i][j][k]) the                         if(Findf (I, j, k) = =k) +                         { ASum + =A[i][j][k]; theFa[i][j][k] = FINDF (i, J, K +1); +                         } -Ans =max (ans, sum); $         } $printf"%d\n", ans); -     } -     return 0; the}

WHU 1581 Union of cubes

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.