提交地址: https://www.icpc-camp.org/contests/4rgOTH2MbOau7Z

题意:

  给出一个整数数组,F[i]定义为以i结尾的最长上升子序列,然后问以此删除掉第i个数后F[1]^2 xor f[3]^2 xor .. xor F[n]^2 , 当然不会算删除的那个。 n <= 5000

思路:

  比赛的时候看完了觉得是个傻逼题,觉得n^2logn能够跑过不知道为啥这么少人交,然后兴致冲冲的敲了一发返回T才意识到没那么简单,题目是把log给卡了的,然后n^2肯定是能过的,不过一直也没有思路,然后赛后听了题解,也不是很懂,也是最近才有时间想起来这个题目的。

  感觉没有思路是因为没有真正的理解LIS的原理,以前都是一直套的板子,所以不是很懂。然后补的时候仔细想了下,就是把v[i]当做以LIS长度为i结尾最小值,然后形成一个单调的队列,就可以使用二分查找到当前的值应该在v数组的哪个位置进而求得以a[i]结尾的LIS,然后更新当前的v[a[i]]数组。然后这个题目呢感觉就是挖掘这个本质,也是这道题让我懂了LIS的原理,因为删除了一个数,那么当前数的LIS值肯定是在原LIS值或者原LIS-1,所以我们就不需要二分去查找当前值应该属于哪个位置了,加入当前数的原LIS值为b我们只需要判断v[b]是否小于a[i],如果不是那v[b-1]肯定小于a[i],然后就降低了一个log

代码:

/** @xigua */
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <cstring>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <climits>
#include <ctime>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 5e3 + 5;
const int mod = 1e9 + 7;
const int INF = 1e8 + 5;
const ll inf = 1e15 + 5;
const db eps = 1e-8;
int d[maxn], a[maxn];void LIS(int n) {vector<int> v;for (int i = 1; i <= n; i++) {int si = v.size();int p = lower_bound(v.begin(), v.end(), a[i]) - v.begin(); //lower是严格 upper是不严格if (p == si) v.push_back(a[i]);else {v[p] = a[i];}d[i] = p + 1;}
}void solve() {int n;while (cin >> n) {for (int i = 1; i <= n; i++)cin >> a[i];LIS(n);for (int i = 1; i <= n; i++) {int ans = 0;int v[maxn];for (int j = 1; j <= n; j++)v[j] = n + 1;   //初始化为最大v[0] = 0;   //为了处理第一个数for (int j = 1; j <= n; j++) {if (i == j) continue;if (v[d[j]-1] < a[j]) {ans ^= d[j] * d[j];v[d[j]] = min(v[d[j]], a[j]);}else {ans ^= (d[j] - 1) * (d[j] - 1);v[d[j]-1] = min(v[d[j]-1], a[j]);}}printf("%d%c", ans, i == n ? '\n' : ' ');}}}int main() {int t = 1, cas = 1;// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);//scanf("%d", &t);while(t--) {// printf("Case %d: ", cas++);solve();}return 0;
}

  

转载于:https://www.cnblogs.com/ost-xg/p/7191032.html

2017四川省赛E题( Longest Increasing Subsequence)相关推荐

  1. leetcode(300)—— Longest Increasing Subsequence(最长递增子序列)

    参考 Python 解法: 动态规划 -- 最长递增子序列(LIS) 原题位置:Longest Increasing Subsequence | LeetCode OJ 题目的说明: 严格递增: 子序 ...

  2. Rosalind Java|Longest Increasing Subsequence动态规划算法

    Rosalind编程问题之计算集合中最长的递增元素子集. Longest Increasing Subsequence Problem: A subsequence of a permutation ...

  3. HPU第三次积分赛-D:Longest Increasing Subsequence(DP)

    Longest Increasing Subsequence 描述 给出一组长度为n的序列,a1​,a2​,a3​,a4​...an​, 求出这个序列长度为k的严格递增子序列的个数 输入 第一行输入T ...

  4. [Swift]LeetCode673. 最长递增子序列的个数 | Number of Longest Increasing Subsequence

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  5. The Longest Increasing Subsequence (LIS)

    传送门 The task is to find the length of the longest subsequence in a given array of integers such that ...

  6. C++longest increasing subsequence 最长递增子序列的实现之二(附完整源码)

    C++longest increasing subsequence 最长递增子序列的实现 C++longest increasing subsequence 最长递增子序列的的实现完整源码(定义,实现 ...

  7. C++longest increasing subsequence 最长递增子序列的实现之一(附完整源码)

    C++longest increasing subsequence 最长递增子序列的实现 C++longest increasing subsequence 最长递增子序列的的实现完整源码(定义,实现 ...

  8. leetcode 300. Longest Increasing Subsequence | 300. 最长递增子序列(动态规划)

    题目 https://leetcode.com/problems/longest-increasing-subsequence/ 题解 难得有官方题解的一道题. 参考:https://leetcode ...

  9. [leetcode] 300. Longest Increasing Subsequence (Medium)

    题意: 求最长增长的子序列的长度. 思路: 利用DP存取以i作为最大点的子序列长度. Runtime: 20 ms, faster than 35.21% of C++ online submissi ...

最新文章

  1. MySQL最高每秒57万写入,带你装X,带你飞!
  2. 1114:白细胞计数
  3. 机器学习 文本分类 代码_无需担心机器学习-如何在少于10行代码中对文本进行分类
  4. linux更新系统内核,如何更新Linux内核来提升系统性能?
  5. 织梦留言簿使用及修改
  6. 【Linux】Docker 基础与实战,看这一篇就够了
  7. php fpm 日志记录,使用Nginx在PHP-FPM 7上启用错误日志记录?
  8. 登峰连接程式改坐标软件_如何用SOLIDWORKS方程式驱动圆柱波浪线?
  9. python与java前景-java和Python的前景谁更好
  10. SqlDbx 个人版本使用指定的instant client
  11. Quartz配置RAMJobStore-007
  12. 电力、电气、电工知识汇总
  13. xshell写JS脚本自动进行操作
  14. 【HTML期末学生大作业】 制作一个简单HTML保护野生动物老虎网页设计专题(HTML+CSS)
  15. IT项目管理 第三章
  16. 学习ubuntu基础看完这一篇就够了,我是貔貅带你打开ubuntu的大门
  17. python 吉他_Python中用于比较吉他弦的Matplotlib幅值_频谱单位
  18. Task 编程中的异常处理
  19. 积分商城搭建的要点与优势有哪些?
  20. 放大缩小不习惯?只需两步教你solid works如何设置反转滚轮缩放

热门文章

  1. Linux系统配置及服务管理_第03章用户管理
  2. ansible操作远程服务器报Error: ansible requires the stdlib json or simplejson module, neither was found!...
  3. Citrix基础端口了解
  4. 【转载】一个通过JSONP跨域调用WCF REST服务的例子(以jQuery为例)
  5. Linux服务器的优化
  6. Linux下SVN 命令操作手册
  7. jquery mobile常用的data-role类型
  8. 有关ArrayList增加Map引发的一个BUG
  9. row_number()over函数的使用(转)
  10. 网站页面间脚本传值 sessionStorage