zoukankan      html  css  js  c++  java
  • 51nod 1562 玻璃切割 (set)

     1 #include<stdio.h>
     2 #include<iostream>
     3 #include<set>
     4 using namespace std;
     5 typedef long long LL;
     6 
     7 const int maxn = 200010;
     8 LL ans[maxn];
     9 int x[maxn];
    10 char c[maxn];
    11 set<int> row,col;
    12 set<int>:: iterator it;
    13 
    14 int main()
    15 {       
    16     int w, h, n, maxr, maxc;
    17     while(~scanf("%d%d%d", &w, &h, &n))
    18     {
    19         maxr = maxc = 0;
    20         row.clear();col.clear();
    21         row.insert(0);row.insert(h);
    22         col.insert(0);col.insert(w);
    23         for(int i =0 ;i < n;i++){
    24             scanf("%*c%c%d", &c[i], &x[i]);
    25             if(c[i] == 'H') row.insert(x[i]);
    26             else col.insert(x[i]);
    27         }
    28         int l, r;
    29         for(it = row.begin();it != row.end();){ 
    30             l = *it;
    31             it++;
    32             r = *it;
    33             maxr = max(maxr, r-l);
    34         }
    35         for(it = col.begin();it != col.end();){ 
    36             l = *it;
    37             it++;
    38             r = *it;                  
    39             maxc = max(maxc, r-l);
    40         }
    41         for(int i = n-1;i >= 0;i--){
    42             ans[i] = 1LL*maxr*maxc;
    43             if(c[i] == 'H'){
    44                 it = row.lower_bound(x[i]);
    45                 it--;
    46                 l = *it;
    47                 it++;it++;
    48                 r = *it;
    49                 maxr = max(maxr, r-l);
    50                 row.erase(x[i]);
    51             }
    52             else{
    53                 it = col.lower_bound(x[i]);
    54                 it--;
    55                 l = *it;
    56                 it++;it++;
    57                 r = *it;
    58                 maxc = max(maxc, r-l);
    59                 col.erase(x[i]);
    60             }
    61         }
    62         for(int i = 0;i < n;i++) 
    63             printf("%lld
    ", ans[i]);           
    64     }
    65     return 0;
    66 }
  • 相关阅读:
    Bzoj 2820: YY的GCD(莫比乌斯反演+除法分块)
    Cogs 2221. [SDOI2016 Round1] 数字配对(二分图)
    Cogs 750. 栅格网络(对偶图)
    最小环问题
    浅谈卡特兰数
    洛谷 P1744 采购特价商品
    HDU 1212 Big Number
    HDU 2108 Shape of HDU
    HDU 1029 Ignatius and the Princess IV
    HDU 1021 Fibonacci Again
  • 原文地址:https://www.cnblogs.com/ouyang_wsgwz/p/9434344.html
Copyright © 2011-2022 走看看