码队的新桌游
时间:2019-08-22
本文章向大家介绍码队的新桌游,主要包括码队的新桌游使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
树状数组、离散化、二维偏序
#include <cstdio> #include <cstdlib> #include <cstring> #include <climits> #include <utility> #include <algorithm> #include <queue> #include <unordered_map> using namespace std; struct Item { int a, b, c; int id; int ans; explicit Item(int _a = 0, int _b = 0, int _c = 0) : a(_a), b(_b), c(_c) {} }; struct cmpa { bool operator()(const Item &lhs, const Item &rhs) const { return lhs.a > rhs.a || (lhs.a == rhs.a && lhs.b < rhs.b) || (lhs.a == rhs.a && lhs.b == rhs.b && lhs.c < rhs.c); } }; struct cmpc { bool operator()(const Item &lhs, const Item &rhs) const { return lhs.c > rhs.c || (lhs.c == rhs.c && lhs.b < rhs.b) || (lhs.c == rhs.c && lhs.b == rhs.b && lhs.a < rhs.a); } }; priority_queue<Item, vector<Item>, cmpa> Qin; priority_queue<Item, vector<Item>, cmpc> Qout; const int MAXN = 300100; int ca[MAXN]; int lsh[MAXN], lsc; Item za[MAXN]; unordered_map<int, int> lss; void addZ(int x, int v) { while (x <= lsc) { ca[x] += v; x += (x & -x); } } int getZ(int x) { int ans = 0; while (x) { ans += ca[x]; x -= (x & -x); } return ans; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d%d%d", &za[i].a, &za[i].b, &za[i].c); Qin.push(za[i]); lsh[lsc++] = za[i].a; lsh[lsc++] = za[i].b; lsh[lsc++] = za[i].c; za[i].id = i; } sort(lsh, lsh + lsc); lsc = unique(lsh, lsh + lsc) - lsh; for (int i = 0; i < lsc; ++i) { lss[lsh[i]] = i + 1;///离散化 } sort(za, za + n, [](const Item &a, const Item &b) { return a.b < b.b; }); for (int i = 0; i < n; ++i) { while (!Qin.empty()) { Item xx = Qin.top(); if (za[i].b > xx.a) { Qin.pop(); addZ(lss[xx.b], 1); Qout.push(xx); } else break; } while (!Qout.empty()) { Item xx = Qout.top(); if (za[i].b >= xx.c) { Qout.pop(); addZ(lss[xx.b], -1); } else break; } za[i].ans = getZ(lss[za[i].c]) - getZ(lss[za[i].a]); } sort(za, za + n, [](const Item &a, const Item &b) { return a.id < b.id; }); for (int i = 0; i < n; ++i)printf("%d\n", za[i].ans-1); return 0; }
原文地址:https://www.cnblogs.com/liulex/p/11393412.html
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- keras 指定程序在某块卡上训练实例
- Python3 requests模块如何模仿浏览器及代理
- PHP中的empty、isset、isnull的区别与使用实例
- Laravel学习笔记之Artisan命令生成自定义模板的方法
- php微信扫码支付 php公众号支付
- PHP析构函数destruct与垃圾回收机制的讲解
- 关于php unset对json_encode的影响详解
- python实现二分类和多分类的ROC曲线教程
- PHP随机数函数rand()与mt_rand()的讲解
- PHP实现小程序批量通知推送
- Keras loss函数剖析
- Laravel使用scout集成elasticsearch做全文搜索的实现方法
- python3.4中清屏的处理方法
- TensorFlow Autodiff自动微分详解
- python interpolate插值实例