http://codeforces.com/problemset/problem/12/D

这里的BIT查询,指的是查询[1, R]或者[R, maxn]之间的最值,这样就够用了。

设三个权值分别是b[1], b[2], b[2];

首先,先把b[1]值离散化,离散成一个个id,那么只能是在id比较大的地方找了。然后把b[2]排序,倒序查询,也就是先查询最大的,当然它是没可能自杀的,因为它已经最大了,然后查询完后,把它压进bit后,以后在bit查询,就不需要管b[2]了,因为在bit里面的b[2]永远都是较大者,其实这是一个常用的方法啦。hack点是相同的值不能提前更新,细节看代码 + 慢慢debug

现在说说bit的作用,bit维护的是b[3],因为我们已经离散化b[1]了,那么每一个元素的下标就相当于离散化的b[1],所以加进去BIT的时候用id做下标即可。bit维护后缀最大值。

hack点的意思是,假如你的a[i].b[2] == a[j].b[2],那么不能在查询a[j]前提前把a[i]加入bit,因为bit查询默认是b[2]成立的,但是提前更新了的话,不成立。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
#include <stack>
const int maxn = 5e5 + ;
int c[maxn], en;
int lowbit(int x) {
return x & (-x);
}
void upDate(int pos, int val) {
while (pos) {
c[pos] = max(c[pos], val);
pos -= lowbit(pos);
}
}
int ask(int pos) {
int ans = -;
while (pos <= en) {
ans = max(ans, c[pos]);
pos += lowbit(pos);
}
return ans;
}
struct Node {
int a[], id;
}a[maxn];
stack<int> st;
bool cmp0(struct Node a, struct Node b) {
return a.a[] < b.a[];
}
bool cmp1(struct Node a, struct Node b) {
return a.a[] < b.a[];
} void work() {
int n;
scanf("%d", &n);
for (int i = ; i <= n; ++i) scanf("%d", &a[i].a[]);
for (int i = ; i <= n; ++i) scanf("%d", &a[i].a[]);
for (int i = ; i <= n; ++i) scanf("%d", &a[i].a[]);
sort(a + , a + + n, cmp0);
en = ;
a[].id = en;
for (int i = ; i <= n; ++i) {
if (a[i].a[] == a[i - ].a[]) {
a[i].id = en;
} else a[i].id = ++en;
}
en += ;
memset(c, -, sizeof c);
sort(a + , a + + n, cmp1);
// for (int i = 1; i <= n; ++i) {
// cout << a[i].a[1] << " " << a[i].a[2] << " " << a[i].a[3] << " " << a[i].id << endl;
// }
st.push(n);
int ans = ;
for (int i = n - ; i >= ; --i) {
if (a[i].a[] == a[i + ].a[]) {
st.push(i);
int res = ask(a[i].id + );
ans += res > a[i].a[];
} else {
while (!st.empty()) {
int res = st.top();
st.pop();
upDate(a[res].id, a[res].a[]);
}
int res = ask(a[i].id + );
ans += res > a[i].a[];
st.push(i);
// upDate(a[i].id, a[i].a[3]);
}
}
cout << ans << endl;
}
int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

Codeforces Beta Round #12 (Div 2 Only) D. Ball 树状数组查询后缀、最值的更多相关文章

  1. Codeforces Beta Round #79 (Div. 1 Only) B. Buses 树状数组

    http://codeforces.com/contest/101/problem/B 给定一个数n,起点是0  终点是n,有m两车,每辆车是从s开去t的,我们只能从[s,s+1,s+2....t-1 ...

  2. Codeforces Beta Round #12 (Div 2 Only) D. Ball sort/map

    D. Ball Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/12/D D ...

  3. Codeforces Beta Round #12 (Div 2 Only)

    Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...

  4. Codeforces Round #381 (Div. 2) D dfs序+树状数组

    D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  5. Codeforces Beta Round #14 (Div. 2) D. Two Paths 树的直径

    题目链接: http://codeforces.com/contest/14/problem/D D. Two Paths time limit per test2 secondsmemory lim ...

  6. Codeforces Round #301 (Div. 2) E . Infinite Inversions 树状数组求逆序数

                                                                    E. Infinite Inversions               ...

  7. 【Codeforces Round #433 (Div. 1) C】Boredom(树状数组)

    [链接]h在这里写链接 [题意] 给你一个n*n的矩阵. 其中每一列都有一个点. 任意两个点构成了矩形的两个对角点 ->即任意两个点确定了一个矩形. ->总共能确定n*(n-1)/2个矩形 ...

  8. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  9. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

随机推荐

  1. 【转】JBoss Web和 Tomcat的区别

    转载于:http://www.verydemo.com/demo_c202_i780.html JBoss Web和 Tomcat的区别 在Web2.0的浪潮中,各种页面技术和框架不断涌现,为服务器端 ...

  2. XAMPP的端口被占用

    打开xampp\apache\conf\httpd.conf文件把80端口修改为:8081;打开xampp\apache\conf\extre\httpd-ssl.conf文件把443修改为4433或 ...

  3. bzoj 4503 两个串 —— FFT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4503 推式子即可: 不知怎的调了那么久,应该是很清晰的. 代码如下: #include< ...

  4. Android开发:显式/隐式Intent

    显式跳转 是在已知包名和类名的情况下常用的跳转方法: Intent mIntent = new Intent(); mIntent.setClassName("com.android.set ...

  5. nagios对windows流量的检测

    windows下用于和 nagios 整合监控的方式主要有三种:nsclient++ .nrpe_nt.SNMP.三者各自的特点主要如下: 1.nsclient++比较成熟稳定,文档也丰富,内置很多了 ...

  6. kafka之五:如何手动更新Kafka中某个Topic的偏移量

    本文介绍如何手动跟新zookeeper中的偏移量.我们在使用kafka的过程中,有时候需要通过修改偏移量来进行重新消费.我们都知道offsets是记录在zookeeper中的,所以我们想修改offse ...

  7. 苹果app(iOS app)的URL schemes

    最近折腾iOS快捷启动应用或应用内的某个动作的神器launch center pro (LCP),发现很多国产app并没有被LCP官方收录,所以不得不想办法找到app的url schemes. 下面是 ...

  8. socket辅助类

    using System; using System.Collections; using System.Net; using System.Net.Sockets; using System.Tex ...

  9. 201621123016 《Java程序设计》第九周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 2. 书面作业 本次作业题集集合 1. List中指定元素的删除(题集题目) 1.1 实验总结.并回答:列举至 ...

  10. Linux下mysql启动失败

    原因:强制重启服务器之后,发现mysql启动 失败 解决方法:强制清空 报错路径下的tmp文件,清空之后在tmp下面新建一个文件夹,文件夹的名字在你清空tmp之后启动mysql系统会给你提示 欧克,完 ...