zoukankan      html  css  js  c++  java
  • Tunnel Warfare HDU 1540

    学习set,其他容器每次都要去sort(),除了堆(但其无法lower_bound)

    题面

    During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a line. Except the two at the ends, every village was directly connected with two neighboring ones.

    Frequently the invaders launched attack on some of the villages and destroyed the parts of tunnels in them. The Eighth Route Army commanders requested the latest connection state of the tunnels and villages. If some villages are severely isolated, restoration of connection must be done immediately!

    Input

    The first line of the input contains two positive integers n and m (n, m ≤ 50,000) indicating the number of villages and events. Each of the next m lines describes an event.

    There are three different events described in different format shown below:

    D x: The x-th village was destroyed.

    Q x: The Army commands requested the number of villages that x-th village was directly or indirectly connected with including itself.

    R: The village destroyed last was rebuilt.
    OutputOutput the answer to each of the Army commanders’ request in order on a separate line.

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n, m, x, c;
        while (scanf("%d%d", &n, &m) != EOF)
        {
            stack<int> sk;
            set<int> st;
            st.insert(0), st.insert(n + 1);
            while (m--)
            {
                getchar();
                scanf("%c", &c);
                if (c == 'R') st.erase(sk.top()), sk.pop();
                else
                {
                    scanf("%d", &x);
                    if (c == 'D') st.insert(x), sk.push(x);
                    else if (st.find(x) != st.end()) printf("0\n");
                    else
                    {
                        auto l = st.lower_bound(x), r = st.lower_bound(x);
                        printf("%d\n", *r - *--l - 1);
                    }
                }
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    JS和PYTHON中数据类型比较
    http状态码
    ffmpeg architecture(上)
    降低数值精度以提高深度学习性能
    IaaS、PaaS 和 SaaS:云服务模型概述
    英特尔Intel® Arria® 10 FPGA加速器设计
    基于至强® 平台的内存数据库解决方案
    MLPerf结果证实至强® 可有效助力深度学习训练
    如何从数据角度为人工智能部署做好数据准备
    英特尔内存革新助平安云 Redis 云服务降本增效
  • 原文地址:https://www.cnblogs.com/2aptx4869/p/12123684.html
Copyright © 2011-2022 走看看