您的位置:首页 > 其它

HDU 5200/BC 36 C Trees

2015-09-28 21:30 260 查看
其实没有官方题解说的那么麻烦(>﹏<) 直接离线处理后 开个数组模拟下即可

砍当前树时 当左右的树被砍掉时 ans就--

都没被砍掉 ans就++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#define scnaf scanf
#define cahr char
#define bug puts("bugbugbug");
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int mod=1000000007;
const int maxn=5e4+100;
const int inf=1e9;
inline void RDF(int &ret) { //输入为负数
    char c;
    int sgn;
    while(c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while(c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
}
inline void RD(int &ret) { //输入为整数
    char c;
    do {
        c = getchar();
    } while(c < '0' || c > '9');
    ret = c - '0';
    while((c = getchar()) >= '0' && c <= '9') {
        ret = ret * 10 + (c - '0');
    }
}
inline void OT(int a) { //输出为正数
    if(a >= 10) {
        OT(a / 10);
    }
    putchar(a % 10 + '0');
}
struct T
{
    int h,id;
    bool operator < (const T &b) const {
        return h<b.h;
    }
}a[maxn],q[maxn];
int tree[maxn],ans[maxn];
int main()
{
    int n,Q;
    while(~scanf("%d%d",&n,&Q))
    {
        tree[0]=tree[n+1]=-1;
        for(int i=0;i<n;i++)
        {
            RD(a[i].h);
            a[i].id=i+1;
            tree[i+1]=1;
        }
        sort(a,a+n);
        for(int i=0;i<Q;i++)
        {
            RD(q[i].h);
            q[i].id=i;
        }
        sort(q,q+Q);
        int cnt=0,anss=1;
        for(int i=0;i<Q;i++)
        {
            while(cnt<n&&a[cnt].h<=q[i].h)
            {
                int now=a[cnt].id;
                tree[now]=-1;
                if(tree[now-1]==tree[now+1])
                    if(tree[now-1]==-1) anss--;
                    else anss++;
                cnt++;
            }
            ans[q[i].id]=anss;
        }
        for(int i=0;i<Q;i++)
        {
            //cout<<ans[i]<<endl;
           OT(ans[i]);puts("");
        }
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: