http://acm.neu.edu.cn/hustoj/problem.php?id=1702

思路:三维偏序模板题,用CDQ分治+树状数组或者树套树。对于三元组(x,y,z),先对x进行排序,然后对x进行CDQ分治降维,在分治的区间对y进行排序,用树状数组维护z。

还不太理解CDQ分治。等待UPDATE。

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <iostream>
#include <stack>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
#define N 100010
#define INF 0x3f3f3f3f
struct node {
int id, x, y, z;
node () {}
node (int x, int y, int z, int id) : x(x), y(y), z(z), id(id) {}
bool operator == (const node &A) const {
return (x == A.x && y == A.y && z == A.z);
}
} p[N]; int gap, same[N], bit[N], ans[N]; bool cmpx(const node &a, const node &b) {
if(a.x != b.x) return a.x < b.x;
if(a.y != b.y) return a.y < b.y;
return a.z < b.z;
} bool cmpy(const node &a, const node &b) {
if(a.y != b.y) return a.y < b.y;
if(a.x != b.x) return a.x < b.x;
return a.z < b.z;
} bool cmpid(const node &a, const node &b) { return a.id < b.id; } int lowbit(int x) { return x & (-x); } void update(int x, int val) {
while(x <= gap) {
bit[x] += val;
x += lowbit(x);
}
} int query(int x) {
int ans = ;
while(x) {
ans += bit[x];
x -= lowbit(x);
}
return ans;
} void CDQ(int l, int r) {
if(l == r) return ;
int mid = (l + r) >> ;
CDQ(l, mid); CDQ(mid + , r);
sort(p + l, p + r + , cmpy);
for(int i = l; i <= r; i++)
if(p[i].x <= mid) update(p[i].z, );
else ans[p[i].id] += query(p[i].z);
for(int i = l; i <= r; i++)
if(p[i].x <= mid) update(p[i].z, -);
} int main()
{
int t;
scanf("%d", &t);
while(t--) {
int n, a, b, c;
scanf("%d", &n);
gap = ;
for(int i = ; i <= n; i++) {
scanf("%d%d%d", &a, &b, &c);
p[i] = node(a, b, c, i);
if(c > gap) gap = c;
}
sort(p + , p + + n, cmpx);
memset(same, , sizeof(same));
for(int i = ; i <= n; ) {
int j = i + ;
while(p[i] == p[j] && j <= n) j++;
while(i < j) same[p[i++].id] = p[j-].id;
}
memset(bit, , sizeof(bit));
memset(ans, , sizeof(ans));
for(int i = ; i <= n; i++) p[i].x = i;
CDQ(, n);
sort(p + , p + + n, cmpid);
for(int i = ; i <= n; i++)
printf("%d\n", ans[same[p[i].id]]);
}
return ;
}

NEUOJ 1702:撩妹全靠魅力值(CDQ分治三维偏序)的更多相关文章

  1. NEUOJ 1702 撩妹全靠魅力值 (三维偏序)

    题目链接:http://acm.neu.edu.cn/hustoj/problem.php?id=1702 题目大意:就是问每个人三个属性同时不低于另外几个人....人不分先后 经典的三维偏序问题 解 ...

  2. 人家为撩妹就鼓捣个网页,我做了个约炮APP(已开源)

    每年初夏第一场雷雨刚过,漫步河边的草坪,总是能闻到伴随着泥土的清新,这不是coco的前香,让人神魂颠倒:也不是gucci的后香,让人痴迷如梦.如24节气一样,它提醒人们,夏天到了.昨晚成都下了第一场雷 ...

  3. 撩妹技能 get,教你用 canvas 画一场流星雨

    开始 妹子都喜欢流星,如果她说不喜欢,那她一定是一个假妹子. 现在就一起来做一场流星雨,用程序员的野路子浪漫一下. 要画一场流星雨,首先,自然我们要会画一颗流星. 玩过 canvas 的同学,你画圆画 ...

  4. Test2014-3-1 魅力值比较

    魅力值比较 [问题描述] 大学生恋爱的问题造成了数量众多的异地恋,有许多J大的女生早早被Q大男生追走,这导致了J大男生的强烈不满.就在吐血高调地向一位J大美女展开攻势的之后,J大男生终于爆发了. 为了 ...

  5. Python之路,Day18 - 开发一个WEB聊天来撩妹吧

    Python之路,Day18 - 开发一个WEB聊天来撩妹吧   本节内容: 项目实战:开发一个WEB聊天室 功能需求: 用户可以与好友一对一聊天 可以搜索.添加某人为好友 用户可以搜索和添加群 每个 ...

  6. 【Python撩妹合集】微信聊天机器人,推送天气早报、睡前故事、精美图片分享

    福利时间,福利时间,福利时间 如果你还在为不知道怎么撩妹而烦恼,不知道怎么勾搭小仙女而困惑,又或者不知道怎么讨女朋友欢心而长吁短叹. 那么不要犹豫徘徊,往下看.接下来我会分享怎么使用 Python 实 ...

  7. 分享一个撩妹、装13神技能,0基础用Python暴力破解WiFi密码

    WiFi密码Python暴力破解   Python密码破解部分截图 获取视频资料,转发此文+点击喜欢,然后获取资料请加Python交流群:580478401,就可以获取视频教程+源码 环境准备: py ...

  8. 恋爱话术库撩妹至尊VIP版

    本软件来自互联网,解锁永久至尊VIP 是一款教你撩妹密语软件.和女生聊天没有话题? 不知道怎么逗乐女生? 女生生气了不会哄? 不知道怎么让女生愿意跟你聊下去? 不知道女生对你有没有意思? 遇到不知道怎 ...

  9. jquery checkbox全选 获取值

    <style> table { line-height:35px; }</style> <div align="left" style="m ...

随机推荐

  1. x:Static , StaticResource 和DynamicResource等XAML 扩展用法

    原文:x:Static , StaticResource 和DynamicResource等XAML 扩展用法 前提: <system:String x:Key="{Component ...

  2. Spring Boot MyBatis 通用Mapper插件集成 good

    看本文之前,请确保你已经在SpringBoot中集成MyBatis,并能正常使用.如果没有,那么请先移步 http://blog.csdn.net/catoop/article/details/505 ...

  3. Why aren't more desktop apps written with Qt?(quora.com系列文章)

    As far as I know and have understood in my experience with Qt, it's a very good and easy to learn li ...

  4. iphone开发技巧整合

    1.NSCalendar用法 -(NSString *) getWeek:(NSDate *)d { NSCalendar *calendar = [[NSCalendar alloc] initWi ...

  5. IOS开发之KVC KVO KVB

    KVC(Key Value Coding) KVO(Key Value Observing) KVB(Key Value Binding) KVO是Cocoa的一个重要机制,他提供了观察某一属性变化的 ...

  6. 扩展ASCII码,不同的国家有不同的字符集。Unicode转换为utf8的规则,utf8没有大小端的问题。超过0xFFFF的Unicode字符WINAPI也无能为力(附各种字符编码表及转换表)good

    一.概念 1,ASCII             ASCII(American Standard Code for Information Interchange),中文名称为美国信息交换标准代码.是 ...

  7. XML Serialize/Deserialize

    using System; using System.Collections.Generic; using System.Globalization; using System.IO; using S ...

  8. Httpclient Fluent API简单封装

    import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.List ...

  9. WM_SIZE后于WM_CREATE消息!!在窗口被创建时的顺序!

    WM_SIZE   procedure WMSize (var Message: TWMSize); message WM_SIZE; 参数说明 wParam: Specifies the type ...

  10. FMX App的Application的事件(各种手机的全局按键)

    直接上代码,还有条经验就是SetApplicationEventHandler可注册多个事件方法. unit Unit6; interface uses  System.SysUtils, Syste ...