zoukankan      html  css  js  c++  java
  • ZOJ

    https://cn.vjudge.net/problem/ZOJ-1610

    题意

    给一个n,代表n次操作,接下来每次操作表示把[l,r]区间的线段涂成k的颜色其中,l,r,k的范围都是0到8000。

    分析

    把区间看作点,即[3,4]看作点4。查询时进行前序遍历,记录上一段的颜色,不连续的就+1。注意区间的范围可达8000

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <string>
    #include <algorithm>
    #include <cmath>
    #include <ctime>
    #include <vector>
    #include <queue>
    #include <map>
    #include <stack>
    #include <set>
    #include <bitset>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    #define ms(a, b) memset(a, b, sizeof(a))
    #define pb push_back
    #define mp make_pair
    #define pii pair<int, int>
    #define eps 0.0000000001
    #define IOS ios::sync_with_stdio(0);cin.tie(0);
    #define random(a, b) rand()*rand()%(b-a+1)+a
    #define pi acos(-1)
    const ll INF = 0x3f3f3f3f3f3f3f3fll;
    const int inf = 0x3f3f3f3f;
    const int maxn = 10000 + 10;
    const int maxm = 200000 + 10;
    const int mod = 998244353;
    int n;
    struct ND{
        int l,r;
    //    ll sum,lazy;
        int col;
    }tree[maxn<<2];
    int pre;
    int ans[maxn];
    //void pushup(int rt){
    //
    //    tree[rt].sum=tree[rt<<1].sum+tree[rt<<1|1].sum;
    //}
    void pushdown(int rt){
        if(tree[rt].col!=-1){
            tree[rt<<1].col=tree[rt<<1|1].col=tree[rt].col;
            tree[rt].col=-1;
        }
    }
    void build(int rt,int l,int r){
        tree[rt].l=l,tree[rt].r=r;
        tree[rt].col=-1;
    //    tree[rt].lazy=0;
        if(l==r){
            return;
        }
        int mid=(l+r)>>1;
        build(rt<<1,l,mid);
        build(rt<<1|1,mid+1,r);
    //    pushup(rt);
    }
    void update(int rt,int L,int R,int val){
        if(L<=tree[rt].l&&tree[rt].r<=R){
            tree[rt].col=val;
            return;
        }
        pushdown(rt);
        int mid=(tree[rt].l+tree[rt].r)>>1;
        if(mid>=L) update(rt<<1,L,R,val);
        if(mid<R) update(rt<<1|1,L,R,val);
    //    pushup(rt);
    }
    
    void query(int rt){
        if(tree[rt].l==tree[rt].r){
            if(tree[rt].col!=-1&&tree[rt].col!=pre){
                ans[tree[rt].col]++;
            }
            pre=tree[rt].col;
            return;
        }
        pushdown(rt);
        query(rt<<1);
        query(rt<<1|1);
    }
    int main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    #endif
        int t,cas=1;
    //    scanf("%d",&t);
        while(~scanf("%d",&n)){
            pre=-1;
            memset(ans,0,sizeof(ans));
            build(1,1,8000);
            while(n--){
                int x,y,z;
                scanf("%d%d%d",&x,&y,&z);
                if(x<y) update(1,x+1,y,z);
            }
            query(1);
            for(int i=0;i<=8000;i++){
                if(ans[i]) printf("%d %d
    ",i,ans[i]);
            }
            puts("");
        }
        return 0;
    }
  • 相关阅读:
    tomcat9.x 集群升级至 tomcat 10.x 发现的问题....
    java8 快速实现List转map 、分组、过滤等操作
    java高亮显示关键字不区分大小写(但不改变原文字母的大小写)---关键字分词功能(自写算法:关键字之间有子集的情况和关键字首尾拼接)
    Java Array、List、Set互相转化
    java 查找list中重复数据
    Java Set对象去重
    Java--如何高效向List中存放不重复的数据(附带时间测试)
    java list的交集,差集,并集
    Java中枚举实现单例模式
    使用jsoup选择器来查找元素
  • 原文地址:https://www.cnblogs.com/fht-litost/p/9572822.html
Copyright © 2011-2022 走看看