[HDOJ4022] Bombing (discretization of +stl)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4022

There are n points on a graph, followed by M operations, one row per operation or one column. Eliminate all of the points in this row or column. The number of points each time the output of the operation is eliminated.

Ideas:

Since the data range is large, the first thing to think about is to maintain the number of columns in each row after discretization, but found that such an offline approach can only maintain the current state, updated into a problem. Later in the thinking there is no way to maintain all the line coordinates within the limits of O (LGN) without exceeding the data range. Want to go, at first want to use Map<int, vector<int>>, but vector scan is O (n). Then consider a nonlinear structure, and finally think of the red and black trees. Or the--std::multiset<int> that holds the repeating element.

So this problem becomes a water problem.

1#include <algorithm>2#include <iostream>3#include <iomanip>4#include <cstring>5#include <climits>6#include <complex>7#include <fstream>8#include <cassert>9#include <cstdio>Ten#include <bitset> One#include <vector> A#include <deque> -#include <queue> -#include <stack> the#include <ctime> -#include <Set> -#include <map> -#include <cmath> +  - using namespacestd; +  A #defineFr First at #defineSC Second - #definePB (a) push_back (a) - #defineRint (a) scanf ("%d", &a) - #defineRll (a) scanf ("%i64d", &a) - #defineRs (a) scanf ("%s", a) - #defineFRead () freopen ("in", "R", stdin) in #defineFWrite () freopen ("Out", "w", stdout) - #defineRep (i, n) for (int i = 0; I < (n); i++) to #defineFor (I, A, n) for (int i = (a); I < (n); i++) + #defineCls (a) memset ((a), 0, sizeof (a)) - #defineFull (a) memset ((a), 0x7f7f, sizeof (a)) the  * Const intMAXN =100010; $ intN, M;Panax Notoginseng intX[MAXN], Y[MAXN]; - intHX[MAXN], hxcnt; the intHY[MAXN], hycnt; + intSX[MAXN], SY[MAXN]; Amap<int, multiset<int> >xx; themap<int, multiset<int> >yy; +multiset<int>:: iterator it; -  $InlineBOOLScan_d (int&num) { $     Char inch;BOOLisn=false; -     inch=GetChar (); -     if(inch==eof)return false; the      while(inch!='-'&& (inch<'0'||inch>'9'))inch=GetChar (); -     if(inch=='-') {isn=true; num=0;}Wuyi     Elsenum=inch-'0'; the      while(inch=getchar (),inch>='0'&&inch<='9'){ -num*=Ten, num+=inch-'0'; Wu     } -     if(IsN) num=-num; About     return true; $ } -  - intGetIDint* H,intHCNT,intx) { -     returnLower_bound (H, h+hcnt, X)-h; A } +  the intMain () { -     //FRead (); $     intC, D; the      while(~SCANF ("%d%d", &n, &m) && n +m) { the Cls (SX); Cls (SY); Xx.clear (), Yy.clear (); the Rep (i, n) { the Scan_d (X[i]); Scan_d (Y[i]); -Hx[i] = X[i]; Hy[i] =Y[i]; in Xx[x[i]].insert (Y[i]); the Yy[y[i]].insert (X[i]); the         } AboutSort (HX, hx+n); Sort (hy, hy+n); thehxcnt = Unique (HX, hx+n)-HX; thehycnt = Unique (hy, hy+n)-hy; the Rep (i, n) { +Sx[getid (HX, hxcnt, X[i])]++; -Sy[getid (hy, hycnt, y[i])]++; the         }Bayi Rep (i, m) { the Scan_d (c); Scan_d (d); the             if(c = =0) { -printf"%d\n", Xx[d].size ()); -                  for(It =Xx[d].begin (); theIt! = Xx[d].end (); it++) { theyy[*It].erase (d); the                 } the xx[d].clear (); -Sx[getid (HX, hxcnt, d)] =0; the             } the             Else { theprintf"%d\n", Yy[d].size ());94                  for(It =Yy[d].begin (); theIt! = Yy[d].end (); it++) { thexx[*It].erase (d); the                 }98Sy[getid (hy, hycnt, d)] =0; About yy[d].clear (); -             }101         }102printf"\ n");103 104     } the     return 0;106}

[HDOJ4022] Bombing (discretization of +stl)

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.