2019DX#6
| 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的更多相关文章
- 2019DX#10
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Minimum Spanning Trees 22.22%(2/9) 1002 Lin ...
- 2019dx#9
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Rikka with Quicksort 25.85%(38/147) 1002 Ri ...
- 2019DX#8
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Acesrc and Cube Hypernet 7.32%(3/41) 1002 A ...
- 2019dx#7
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 A + B = C 10.48%(301/2872) 1002 Bracket Seq ...
- 2019DX#5
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 fraction 辗转相除 4.17%(7/168) ok 1002 three arr ...
- 2019dx#4
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 AND Minimum Spanning Tree 31.75%(1018/3206) ...
- 2019DX#3
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Azshara's deep sea 凸包 6.67%(6/90)
- 2019DX#2
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Another Chess Problem 8.33%(1/12) 1002 Beau ...
- 2019DX#1
1001 Blank 题意 有一个长度为n(n<=100)的位子,填入四种颜色,有m个限制,某个区间的颜色个数要恰好等于x个.问颜色个数的方案数. 思路 DP 四维的DP,利用滚动数组优化一维空 ...
随机推荐
- python传递参数
1.脚本 # -*- coding: utf-8 -*- from sys import argvscript, first,second = argv #将命令中输入的参数解包后传递给左边 age ...
- python 实现两个文本文件内容去重
实现两个文本内容去重,输出两个文本不重复的结果 两个测试文本内容如下 1.txt中内容为 1 2 3 4 5 6 7 8 2.txt中内容为 1 2 3 4 5 6 7 8 9 10 11 12 13 ...
- oracle常用的一些sql命令
//查看系统当前时间 HH24 24小时制 MI是正确的分钟 select to_char(sysdate,'yyyy-mm-dd HH24:MI:SS') from dual //HH非24 ...
- 7z 命令行方式生成自解压exe
一.下载 7z是一个免费的工具,除了通过命令行的方式提供各种文件.压缩包相关的操作外,还提供了一种方式可以打出自解压的exe程序.该程序从运行到结束经历了三个流程: (1) 解压文件到用户临时目录: ...
- 1、大型项目的接口自动化实践记录--robotframework环境搭建
因为人力.团队技术问题,选用robotframework来做自动化,首先说下环境搭建 齐涛道长的入门教程非常棒:http://blog.csdn.net/tulituqi/article/detail ...
- spark shuffle读操作
提出问题 1. shuffle过程的数据是如何传输过来的,是按文件来传输,还是只传输该reduce对应在文件中的那部分数据? 2. shuffle读过程是否有溢出操作?是如何处理的? 3. shuff ...
- javascript中的浅拷贝和深拷贝(拷贝引用和拷贝实例)
作者:千锋教育链接:https://www.zhihu.com/question/23031215/answer/326129003来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...
- Java 复制PDF文档的2种方法
本文将介绍通过Java程序来复制PDF页面,包括: 跨文档复制,即从文档1复制到文档2 在同一文档内复制,即从页面A复制到页面B 使用工具:Free Spire.PDF for Java (免费版) ...
- 电脑查询pico的mac
配置好adb或者sdk后, adb shell cat /sys/class/net/wlan0/address
- Intellij IDEA 2019.2 设置Git
点击File选择Settings 查找Git 选择Git安装路径bin目录下git.exe并点击text是否可用 选择OK安装完成. IDEA 拉去github 或 gogs上的项目(选择VCS —— ...
