lightoj 1085 树状数组+dp
来源:互联网 发布:离地间隙高的轿车 知乎 编辑:程序博客网 时间:2024/05/20 02:28
Description
Given a binary number, we are about to do some operations on the number. Two types of operations can be here.
‘I i j’ which means invert the bit from i to j (inclusive)
‘Q i’ answer whether the ith bit is 0 or 1
The MSB (most significant bit) is the first bit (i.e. i=1). The binary number can contain leading zeroes.
Input
Input starts with an integer T (≤ 10), denoting the number of test cases.
Each case starts with a line containing a binary integer having length n (1 ≤ n ≤ 105). The next line will contain an integer q (1 ≤ q ≤ 50000) denoting the number of queries. Each query will be either in the form ‘I i j’ where i, j are integers and 1 ≤ i ≤ j ≤ n. Or the query will be in the form ‘Q i’ where i is an integer and 1 ≤ i ≤ n.
Output
For each case, print the case number in a single line. Then for each query ‘Q i’ you have to print 1 or 0 depending on the ith bit.
Sample Input
2
0011001100
6
I 1 10
I 2 7Description
An increasing subsequence from a sequence A1, A2 … An is defined by Ai1, Ai2 … Aik, where the following properties hold
- i1 < i2 < i3 < … < ik and
- Ai1 < Ai2 < Ai3 < … < Aik
Now you are given a sequence, you have to find the number of all possible increasing subsequences.
Input
Input starts with an integer T (≤ 10), denoting the number of test cases.
Each case contains an integer n (1 ≤ n ≤ 105) denoting the number of elements in the initial sequence. The next line will contain n integers separated by spaces, denoting the elements of the sequence. Each of these integers will be fit into a 32 bit signed integer.
Output
For each case of input, print the case number and the number of possible increasing subsequences modulo 1000000007.
Sample Input
3
3
1 1 2
5
1 2 1000 1000 1001
3
1 10 11
Sample Output
Case 1: 5
Case 2: 23
Case 3: 7
这个题,讲道理单纯作为一个dp来讲
弱智的一匹
但是学长们把它放在树状数组专题测试里面
这就很诡异了
想了一会发现没啥思路….
看看剩下其他俩题卧槽都不会…这就很尴尬了….
然后按照寻常dp的思路想了想发现了一点东西….
按照最垃圾的那种dp做法这个题应该是每一个都从前面转移,
从前向后的一个过程…..
但是10^5的数据量n^2不炸就不对了….
然后就突然看到了这个求和的过程…
既然是求和的一个过程那么就很好理解了….
用把自己转移到其他可达状态的那种写法
nlgn勉强写出来了….
然后还有一点是xjb写的,比如那个排序为什么一样大是大序号在前我也不知道
一发不过xjb改反正就这么写完就是能过….
等想明白了补充….
#include<iostream>#include<memory.h>#include<algorithm>#include<cstdio>#include<string>using namespace std;int lowbit(int x) { return x&-x;}int ga[100001];int c[100001];int n, m;int sss[100000];int gs(int x){ int q = 0; for (int y = x;y > 0;y -= lowbit(y))q += c[y],q%=1000000007; return q;}void gengxin(int xiabiao, int zhi){ for (int q = xiabiao;q <= n;q += lowbit(q)) { c[q] += zhi; c[q] %= 1000000007; //if (c[q] < 0)c[q] = 0; }}int asasa(int qqw, int wwe){ if (ga[qqw] != ga[wwe])return ga[qqw] < ga[wwe]; else return qqw > wwe;}int main(){ int T; cin >> T; int u = 0; while (T--) { memset(c, 0, sizeof(c)); memset(sss, 0, sizeof(sss)); cin >> n; for (int a = 1;a <= n;a++)scanf("%d", &ga[a]), sss[a]=a; sort(sss + 1, sss + 1 + n,asasa); for (int a = 1;a <= n;a++)gengxin(sss[a], gs(sss[a])+1); printf("Case %d: %d\n", ++u, gs(n)); } return 0;}
- lightoj 1085 树状数组+dp
- LightOJ-1085-树状数组,离散化,dp
- Lightoj 1085 All Possible Increasing Subsequences (树状数组+DP)
- lightoj 1085 - All Possible Increasing Subsequences 【树状数组优化dp】
- LightOJ 1085 All Possible Increasing Subsequences (DP&离散化&树状数组)
- [dp+树状数组优化] LightOJ 1145 - Dice (I)
- lightoj 1085【离散化+树状数组】
- lightoj 1085【离散化+树状数组】
- LightOj 1188 树状数组
- LightOJ 1118 树状数组+离线
- [树状数组]LightOJ 1085 - All Possible Increasing Subsequences
- hdu5125 dp+树状数组
- hdu4521 dp+树状数组
- HDU5542(dp+树状数组)
- HDU5542(dp + 树状数组)
- [树状数组]LightOJ 1266 - Points in Rectangle
- BNU12999【LightOJ 1080 - Binary Simulation】+【树状数组】
- LightOJ - 1301 Monitoring Processes(树状数组)
- 多线程中的使用共享变量的问题
- 进程间通信相关函数
- CentOS 6 安装Teamviewer
- Android——NDK笔记
- java优先级的一个细节
- lightoj 1085 树状数组+dp
- 1010. 一元多项式求导 (25)
- linux系统编程之文件与I/O(五):文件的内核结构file和dup实现重定向
- 51nod-【1042 数字0-9的数量】
- Shell脚本
- Dom4j-使用指导
- centos连接不上网络的处理办法
- Leetcode #240 Search a 2D Matrix II
- 使用log4j记录日志