提交地址: 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;
}

  

2017四川省赛E题( Longest Increasing Subsequence)的更多相关文章

  1. 2017四川省赛D题《Dynamic Graph》

    题意:给出一个n个点m条边的有向无环图(DAG),初始的时候所有的点都为白色.然后有Q次操作,每次操作要把一个点的颜色改变,白色<->黑色,对于每次操作,输出满足下列点对<u,v&g ...

  2. LintCode刷题笔记--Longest Increasing Subsequence

    标签: 动态规划 描述: Given a sequence of integers, find the longest increasing subsequence (LIS). You code s ...

  3. 【刷题-LeetCode】300. Longest Increasing Subsequence

    Longest Increasing Subsequence Given an unsorted array of integers, find the length of longest incre ...

  4. [LeetCode] Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  5. 300. Longest Increasing Subsequence

    题目: Given an unsorted array of integers, find the length of longest increasing subsequence. For exam ...

  6. 最长上升子序列 LIS(Longest Increasing Subsequence)

    引出: 问题描述:给出一个序列a1,a2,a3,a4,a5,a6,a7….an,求它的一个子序列(设为s1,s2,…sn),使得这个子序列满足这样的性质,s1<s2<s3<…< ...

  7. 300最长上升子序列 · Longest Increasing Subsequence

    [抄题]: 往上走台阶 最长上升子序列问题是在一个无序的给定序列中找到一个尽可能长的由低到高排列的子序列,这种子序列不一定是连续的或者唯一的. 样例 给出 [5,4,1,2,3],LIS 是 [1,2 ...

  8. 673. Number of Longest Increasing Subsequence最长递增子序列的数量

    [抄题]: Given an unsorted array of integers, find the number of longest increasing subsequence. Exampl ...

  9. LeetCode Number of Longest Increasing Subsequence

    原题链接在这里:https://leetcode.com/problems/number-of-longest-increasing-subsequence/description/ 题目: Give ...

随机推荐

  1. UVa 10213 How Many Pieces of Land ? (计算几何+大数)

    题意:一块圆形土地,在圆周上选n个点,然后两两连线,问把这块土地分成多少块? 析:这个题用的是欧拉公式,在平面图中,V-E+F=2,其中V是顶点数,E是边数,F是面数.对于这个题只要计算V和E就好. ...

  2. Binder使用示例(转载)

    转自:http://blog.csdn.net/new_abc/article/details/8097775

  3. 51nod1393

    思路:一个位num0-num1值=某位num0-num1值相等就代表这段区间内01数字相等,然后还要判断当前位置num0==num1这个情况 #include <bits/stdc++.h> ...

  4. Unity 5.4 公开测试版发布:增强的视觉效果,更佳的性能表现

    为用户提供可靠稳定的产品是我们的一贯使命,现在我们将发布Unity 5.4 beta版本,提供所有的用户公开测试,这包含了Unity Personal Edition版本用户.我们非常希望大家下载并尝 ...

  5. 移动平台unity3d优化

    目录(?)[-] Focus on GPUs 着眼于GPU Good practice 优秀的实践 Sharer optimizations 着色器优化 Focus on CPUs 着眼于CPUs G ...

  6. bzoj 3559: [Ctsc2014]图的分割【最小生成树+并查集】

    读题两小时系列-- 在读懂题意之后,发现M(c)就是c这块最大权割边也就是的最小生成树的最大权边的权值,所以整个问题都可以在MST的过程中解决(M和c都是跟着并查集变的) 不过不是真的最小生成树,是合 ...

  7. [Xcode 实际操作]九、实用进阶-(30)为IAP(支付方式)内购项目添加测试账号,测试内购功能

    目录:[Swift]Xcode实际操作 本文将演示如何添加测试账号,以方便对内购功能进行测试. IAP,即in-App Purchase ,是一种智能移动终端应用程序付费的模式, 在苹果(Apple) ...

  8. .netcore--Controller后台实现企业微信发送消息

    一.获得企业微信管理端权限,登录企业企业微信管理端界面,并创建应用,如下图中的[网站消息推送] 二.参见企业微信API文献,根据corpid=ID&corpsecret=SECRET(其中企业 ...

  9. 【bzoj1726】Roadblocks

    1726: [Usaco2006 Nov]Roadblocks第二短路 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1578  Solved: 795[ ...

  10. 为什么会出现lvs+nginx

    一.ngix(应用层 网络七层负载均衡) 1.异步转发,请求数据和相应数据都要经过ngix,ngix和客户端建立连接 2.轮询所有的tomcat服务器,保证请求成功或者最后一台tomcat服务器也请求 ...