hdu6681 Rikka with Cake

题目链接、

 

压缩y轴,维护x的树状数组

/*author:revolIA*/
#include
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
using namespace std;
typedef long long ll;
template  T max(T &a,const T &b){return a>b?a:b;}
template  T min(T &a,const T &b){return a vex,vey;
vector > Add[maxn],Query[maxn];
struct node{
    int x,y;
    char opt[2];
}rel[maxn];
int main(){
    scanf("%d",&T);
    while(T--){
        vex.clear(),vey.clear();
        scanf("%d%d%d",&n,&m,&k);
        for(int i=1;i<=k;i++){
            scanf("%d%d%s",&rel[i].x,&rel[i].y,rel[i].opt);
            vex.push_back(rel[i].x);
            vey.push_back(rel[i].y);
        }
        sort(vex.begin(),vex.end()),sort(vey.begin(),vey.end());
        vex.erase(unique(vex.begin(),vex.end()),vex.end());
        vey.erase(unique(vey.begin(),vey.end()),vey.end());
        n = vex.size(),m = vey.size();
        for(int i=1;i<=k;i++){
            rel[i].x = lower_bound(vex.begin(),vex.end(),rel[i].x)-vex.begin()+1;
            rel[i].y = lower_bound(vey.begin(),vey.end(),rel[i].y)-vey.begin()+1;
        }
        for(int i=1;i<=m;i++)Add[i].clear(),Query[i].clear();
        for(int i=1;i<=n;i++)Tree[i] = 0;
        for(int i=1;i<=k;i++){
            int x = rel[i].x,y = rel[i].y;
            if(rel[i].opt[0] == 'U'){
                Add[y].push_back({x,1});
            }else if(rel[i].opt[0] == 'D'){
                Add[1].push_back({x,1});
                Add[y+1].push_back({x,-1});
            }else if(rel[i].opt[0] == 'L'){
                Query[y].push_back({1,x});
            }else{
                Query[y].push_back({x,n});
            }
        }
        int ans = 0;
        for(int i=1;i<=m;i++){
            for(auto j:Add[i])add(j.first,j.second);
            for(auto j:Query[i])ans += query(j.second)-query(j.first-1);
        }
        printf("%d\n",ans+1);
    }
    return 0;
}

 

你可能感兴趣的:(模板类(什么,这也是模板),思维(抖啊,抖啊,抖个机灵儿))