Solved Pro.ID Title Ratio(Accepted / Submitted)
  1001 Salty Fish 16.28%(7/43)
 OK 1002 Nonsense Time                暴力 7.88%(57/723)
  1003 Milk Candy 12.90%(4/31)
  1004 Speed Dog 26.97%(48/178)
  1005 Snowy Smile 8.52%(225/2640)
  1006 Faraway 27.92%(98/351)
  1007 Support or Not 8.33%(3/36)
  1008 TDL 27.63%(921/3333)
  1009 Three Investigators 7.14%(1/14)
  1010 Ridiculous Netizens            点分治 38.71%(24/62)
  1011 11 Dimensions 13.47%(64/475)
  1012 Stay Real 45.04%(1044/2318)

1002 Nonsense Time

题意

给定一个长度n($n \le 50000$)的排列$p_1, p_2, ... ,p_n$,给定一个长度为n的排列$a_1, a_2, ... ,a_n$.

初始排列p是不可见的,从1到n,第$p_{a_i}$个可见,输出此时可见p的LIS。

数据保证纯随机。

思路

由于是随机,所以有人证明lis的期望是O($\sqrt{n}$)。

所以我们利用时间倒流技术,从后往前做。

记录一个LIS,如果要删除的数是LIS上的,就重新算一个LIS,如果要删的数不再LIS上,那什么事也没发生。

复杂度 = $ n \times \lgroup \frac{1}{\sqrt{n}} \times n \times \log n + \frac{1}{\sqrt{n}} \rgroup$

   = $n \times \sqrt{n} \times \log n + \sqrt{n}$

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /**********showtime************/
const int maxn = ;
int p[maxn],a[maxn];
int vis[maxn],used[maxn], ans[maxn];
int que[maxn], dp[maxn];
int n;
int solve() {
int len = ;
for(int i=; i<=n; i++) {
used[i] = ;
if(vis[i]) continue;
int pos = lower_bound(que+, que++len, p[i]) - que;
if(pos > len) {
que[++len] = p[i];
dp[i] = len;
}
else {
que[pos] = p[i];
dp[i] = pos;
}
// for(int i=1; i<=len; i++) cout<<que[i]<<" ";
// cout<<endl;
}
int res = len;
for(int i=n; i>=; i--) {
if(vis[i]) continue;
if(dp[i] == len) {
used[i] = ;
len--;
}
}
return res;
}
int main(){
int T; scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i=; i<=n; i++) scanf("%d", &p[i]);
for(int i=; i<=n; i++) scanf("%d", &a[i]);
for(int i=; i<=n; i++) vis[i] = ; int cur = solve(); for(int i=n; i>=; i--) {
ans[i] = cur;
vis[a[i]] = ;
if(used[a[i]] != ) {
cur = solve();
}
}
for(int i=; i<n; i++) printf("%d ", ans[i]);
printf("%d\n", ans[n]);
}
return ;
}

1011 11 Dimensions

我自己用DP1A了,好像还有康托展开的方法,可以搞搞

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /**********showtime************/
const int maxn = 5e4+;
ll big = 1e18;
ll dp[maxn][];
ll md[maxn],mdd[maxn];
char str[maxn];
vector<int>vec;
int main(){
md[] = ;
for(int i=; i<maxn; i++) md[i] = md[i-] * % mod;
int T; scanf("%d", &T);
while(T--) {
int n,m,q;
scanf("%d%d%d", &n, &m, &q);
mdd[] = ; for(int i=; i<maxn; i++) mdd[i] = mdd[i-] * % m; scanf("%s", str+);
ll sum = , tp = ;
vec.clear();
for(int i=; i<=n; i++) {
for(int j=; j<m; j++) dp[i][j] = ;
} for(int i=n; i>=; i--) {
if(str[i] == '?') {
if(vec.size() < ) vec.pb(i);
}
else {
sum = (sum + md[n-i] * (str[i] - '') % mod) % mod;
tp = (tp + mdd[n-i] * (str[i] - '') % m) % m;
}
}
dp[][tp] = ; int all = vec.size();
for(int i=; i<=all; i++) {
int id = vec[i-];
for(int j=; j<; j++) {
int up = mdd[n - id] * j % m; for(int k=; k<m; k++) {
ll tmp = dp[i][k] + dp[i - ][(k - up + m) % m];
if(tmp <= big) {
dp[i][k] = tmp;
}
else dp[i][k] = big+;
}
}
} while(q--) {
ll cur = sum;
int flag = ;
int y = ;
ll k; scanf("%lld", &k);
k--;
for(int i=all; i>=; i--) {
int id = vec[i-];
int flag = ;
for(int j=; j<; j++) {
int tmp = (y + j * mdd[n-id] % m) % m;
if(dp[i-][(m - tmp) % m] > k) {
y = tmp;
cur = (cur + j * md[n-id] % mod) % mod;
flag = ;
break;
}
else {
k -= dp[i-][(m - tmp) % m];
}
}
if(flag) {k=; break;}
}
if(k) puts("-1");
else
printf("%lld\n", cur);
}
}
return ;
}

2019DX#6的更多相关文章

  1. 2019DX#10

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 Minimum Spanning Trees 22.22%(2/9)   1002 Lin ...

  2. 2019dx#9

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 Rikka with Quicksort 25.85%(38/147)   1002 Ri ...

  3. 2019DX#8

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 Acesrc and Cube Hypernet 7.32%(3/41)   1002 A ...

  4. 2019dx#7

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 A + B = C 10.48%(301/2872)   1002 Bracket Seq ...

  5. 2019DX#5

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 fraction 辗转相除 4.17%(7/168) ok  1002 three arr ...

  6. 2019dx#4

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 AND Minimum Spanning Tree 31.75%(1018/3206)   ...

  7. 2019DX#3

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 Azshara's deep sea 凸包 6.67%(6/90)  

  8. 2019DX#2

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 Another Chess Problem 8.33%(1/12)   1002 Beau ...

  9. 2019DX#1

    1001 Blank 题意 有一个长度为n(n<=100)的位子,填入四种颜色,有m个限制,某个区间的颜色个数要恰好等于x个.问颜色个数的方案数. 思路 DP 四维的DP,利用滚动数组优化一维空 ...

随机推荐

  1. 谈谈用Boox Max 2 阅读A4纸文献的体验

    首先说说选择Boox的几个原因: 护眼.这个不用多说,之所以除了电脑,还要电子阅读器,主要是为了护眼. 减少纸质书籍购买.纸质书籍拿在手上是有质感,读起来也更舒服,可一则一些外文书买纸质的是很贵的,相 ...

  2. dz6.0的一个sql注入漏洞

    今天开始着手分析第一个漏洞,找了一上午靶机,发现一个含有成人内容的违法网站是用dz6.0搭的,今天就看看dz这个版本的洞了 问题函数位置:my.php第623行 if(is_array($descri ...

  3. EF Core的Code First 基础

    一.创建实体类与映射类 通过NuGet引用Microsoft.EntityFrameworkCore 1.创建实体类 Code First可以通过为实体类字段添加相应特性,来创建对应的字段类型等,举例 ...

  4. 【Android】drawable VS mipmap

    Android Studio 创建工程后默认的资源文件夹如下图所示: 一直有些疑惑的是 mipmap 和 drawable 文件夹有什么区别,以及是否还需要创建 drawable-xhdpi, dra ...

  5. 深入理解JVM-类加载器深入解析(2)

    深入理解JVM-类加载器深入解析(2) 加载:就是把二进制形式的java类型读入java虚拟机中 连接: 验证: 准备:为类变量分配内存,设置默认值.但是在到达初始化之前,类变量都没有初始化为真正的初 ...

  6. vue-cli3.0创建项目报npm install --loglevel error 踩坑的那把辛酸泪

    创建项目 vue create vue-pro 然后如下图 一开始以为是npm的问题,卸载了Mac的node ,安装nvm,然后再安装node (可参考: Mac中nvm的安装和使用   https: ...

  7. MySQL操作命令梳理(1)

    一.索引 1.创建索引 索引的创建可以在CREATE TABLE语句中进行,也可以单独用CREATE INDEX或ALTER TABLE来给表增加索引.以下命令语句分别展示了如何创建主键索引(PRIM ...

  8. 数据结构之稀疏矩阵C++版

    //只是简单的演示一下,这个实际运用视乎不怎么多,所以java版不再实现 /* 希疏矩阵应用于对数据的压缩,仅仅保留不为0的数据 稀疏矩阵的转置,可以由多种方式,下面演示的稍显简单,时间复杂度略高O( ...

  9. 【POJ - 2385】Apple Catching(动态规划)

    Apple Catching 直接翻译了 Descriptions 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速 ...

  10. 算法与数据结构基础 - 字典树(Trie)

    Trie基础 Trie字典树又叫前缀树(prefix tree),用以较快速地进行单词或前缀查询,Trie节点结构如下: //208. Implement Trie (Prefix Tree)clas ...