题目链接:http://poj.org/problem?id=2299 求逆序数的经典题,求逆序数可用树状数组,归并排序,线段树求解,本文给出树状数组,归并排序,线段树的解法. 归并排序: #include<cstdio> #include<iostream> using namespace std; #define max 500002 int arr[max],b[max];//b[]为临时序列,arr[]为待排序数列,结果在arr[]中 int tp[max]; ;//总逆序…
题目地址:http://poj.org/problem?id=2777 Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30995 Accepted: 9285 Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of pr…
http://poj.org/problem?id=2828 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 10478 Accepted: 5079 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a lo…
题目链接: poj 2777 Count Color 题目大意: 给出一块长度为n的板,区间范围[1,n],和m种染料 k次操作,C a b c 把区间[a,b]涂为c色,P a b 查询区间[a,b]有多少种不同颜色 解题思路: 很明显的线段树的区间插入和区间查询,但是如何统计有多少不同的颜色呢? 如果每个结点数组来存储颜色的种类,空间复杂度很高,而且查询很慢 颜色最多只有30种,可以用位运算中的“按位或|” 颜色也用二进制来处理,和存储: 第一种颜色的二进制表示1 第二种颜色…