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,利用滚动数组优化一维空 ...
随机推荐
- bootstrap开发响应式网页的常用的一些 类的说明
1.navbar-导航条 1.navbar-fixed-top,让导航条固定显示在页面上部(注意:固定的导航条会遮住代码,解决方案,给body设置padding-top的值[大于或等于]为我们导航条的 ...
- Android开发进阶——自定义View的使用及其原理探索
在Android开发中,系统提供给我们的UI控件是有限的,当我们需要使用一些特殊的控件的时候,只靠系统提供的控件,可能无法达到我们想要的效果,这时,就需要我们自定义一些控件,来完成我们想要的效果了.下 ...
- Java经典编程题
[程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? //这是一个菲波拉契数列问题p ...
- 调测Onvif事件总结解决办法
主要在调测事件用例的过程中,发现了大量的信息,和未曾碰到的场景和非法错误等信息,先总结解决办法如下: (1)测试过程中发现以前的一个难题解决了,原先在生成soap空间命名的文件中有部分需要下载,离线生 ...
- Flink+Druid构建实时OLAP的探索
场景 k12在线教育公司的业务场景中,有一些业务场景需要实时统计和分析,如分析在线上课老师数量.学生数量,实时销售额,课堂崩溃率等,需要实时反应上课的质量问题,以便于对整个公司的业务情况有大致的了解. ...
- Caffeine Cache-高性能Java本地缓存组件
前面刚说到Guava Cache,他的优点是封装了get,put操作:提供线程安全的缓存操作:提供过期策略:提供回收策略:缓存监控.当缓存的数据超过最大值时,使用LRU算法替换.这一篇我们将要谈到一个 ...
- Zookeeeper环境搭建(二)
zk一般是有2n+1个节点组成的集群.在Zookeeper服务有两个角色,一个是leader,负责写服务和数据同步:剩下的是follower,提供读服务.(为什么是2n+1个节点请看paxos算法) ...
- echarts3.x遇到的坑
此文章用来记录echarts3.x遇到的坑,方便以后自己不再犯. 1.柱形图设置了yAxis.splitArea.show=true,后面设置的splitLine就会变不可见了.也没在官方文档中找到说 ...
- JAVA-SpringMVC 概述及组件介绍
一.SpringMVC概述 SpringMVC是一个WEB层.控制层框架,主要用来负责与客户端交互,业务逻辑的调用. SpringMVC是Spring家族中的一大组件,Spring整合SpringMV ...
- UWP实现吸顶的Pivot
话不多说,先上效果 这里使用了一个ScrollProgressProvider.cs,我们这篇文章先解析一下整体的动画思路,以后再详细解释这个Provider的实现方式. 结构 整个页面大致结构是 & ...
