当前位置: 首页 > news >正文

19728 拼十字

19728 拼十字

⭐️难度:中等
🌟考点:树状数组、省赛、2024
📖
在这里插入图片描述

📚

import java.io.*;
import java.util.*;

public class Main {
    static class FenwickTree {
        int n;
        int[] tree;

        public FenwickTree(int n) {
            this.n = n;
            tree = new int[n + 1];
        }

        int lowbit(int i) {
            return i & -i;
        }

        void add(int i, int val) {
            for (; i <= n; i += lowbit(i)) {
                tree[i] += val;
            }
        }

        int preSum(int i) {
            int ret = 0;
            for (; i > 0; i -= lowbit(i)) {
                ret += tree[i];
            }
            return ret;
        }

        int rangeSum(int l, int r) {
            return preSum(r) - preSum(l - 1);
        }
    }

    static int maxn = 100010;
    static int ans = 0;
    static int mod = (int) 1e9 + 7;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<int[]> arr = new ArrayList<>();

        // 读入所有的矩形
        for (int i = 0; i < n; i++) {
            int l = sc.nextInt(); // 长
            int w = sc.nextInt(); // 宽
            int c = sc.nextInt(); // 颜色
            arr.add(new int[]{l, w, c});
        }

        // 对矩形进行排序,l升序,然后w升序
        arr.sort((o1, o2) -> {
            if (o1[0] != o2[0]) return Integer.compare(o1[0], o2[0]);
            else return Integer.compare(o1[1], o2[1]);
        });

        // 建立三种颜色对应的树状数组
        FenwickTree[] tree = new FenwickTree[3];
        for (int i = 0; i < 3; i++) tree[i] = new FenwickTree(maxn);

        // 然后枚举排序好的arr
        for (int[] a : arr) {
            int l = a[0];
            int w = a[1];
            int c = a[2];
            for (int i = 0; i < 3; i++) {
                if (c == i) continue; // 相同颜色被排除掉
                ans = (ans + tree[i].rangeSum(w + 1, maxn)) % mod; // 累加答案
            }
            tree[c].add(w, 1); // 更新树状数组
        }
        System.out.println(ans);
    }
}
http://www.dtcms.com/a/110000.html

相关文章:

  • 算力重构营销生态:广电数字人 “造星“ 运动背后的智能革命
  • Ceph异地数据同步之-RBD异地同步复制(下)
  • NO.63十六届蓝桥杯备战|基础算法-⼆分答案|木材加工|砍树|跳石头(C++)
  • ZCC8702,LED驱动芯片的“六边形战士”可替代SY8707
  • 服务器有2张显卡,在别的虚拟环境部署运行了Xinference,然后又建个虚拟环境再部署一个可以吗?
  • ngx_time_init
  • EIR管理中IMEI和IMSI信息的作用
  • 【AI赋能:58招聘数据的深度剖析之旅】
  • NHANES指标推荐:BRI
  • 基于大模型的主动脉瓣病变预测及治疗方案研究报告
  • 《系统分析师-基础篇-1-6章总结》
  • 非对称加密:原理、算法与应用全解析
  • 工具介绍 | SafeLLMDeploy教程来了 保护本地LLM安全部署
  • 2025高频面试设计模型总结篇
  • 采用离散频率索引k和模拟频率f生成信号(MATLAB)
  • Spring Boot 集成 Redis中@Cacheable 和 @CachePut 的详细对比,涵盖功能、执行流程、适用场景、参数配置及代码示例
  • [C语言入门] 结构体
  • RNN万能逼近定理证明
  • 《2024年全球DDoS攻击态势分析》
  • 2025年内外网文件交换系统排名分析
  • 【3.软件工程】3.5 V开发模型
  • 深度学习与神经网络 | 邱锡鹏 | 第二章学习笔记
  • 微服务。1 微服务
  • Java学习总结-IO流
  • 如何免费制作办事指南二维码
  • 如何进行风电场微观选址
  • 如何在Windows上找到Python安装路径?两种方法快速定位
  • 深度学习deeplearn3
  • 基于飞桨框架3.0本地DeepSeek-R1蒸馏版部署实战
  • 质检LIMS系统在环境监测站的应用 环境监测场景下的LIMS系统应用