st

1057 Stack (分块思想)

匿名 (未验证) 提交于 2019-12-02 23:05:13
Input Specification: Push key Pop PeekMedian key 1. Output Specification: Push key Pop PeekMedian Invalid Sample Input: 17 Pop PeekMedian Push 3 PeekMedian Push 2 PeekMedian Push 1 PeekMedian Pop Pop Push 5 Push 4 PeekMedian Pop Pop Pop Pop Sample Output: Invalid Invalid 3 2 2 1 2 4 4 5 3 Invalid    由于N<=10^5,暴力算法肯定超时,我一开始思考用multiset容器可以自动排序,只要找到中值即可 #include<cstdio> #include<set> #include<cstring> #include<stack> using namespace std; stack<int> st; multiset<int> se; int tot=0; int main(){ int n,m; char s[20]; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%s",s); if(strcmp(s,"Pop")==0){ if(tot

python 数据类型 之 集合

匿名 (未验证) 提交于 2019-12-02 22:56:40
集合是一个数学概念:由一个或多个确定的元素所构成的整体叫做集合 集合的三个特性:   1.确定性 (element必须可hash,不可变类型是可hash的)   2.互异性(集合中element 不能重复)   3.无序性(集合中没有先后之分,例如集合:{3,4,6}  等于{6,4,3})   #集合的存在意义在于去重和关系运算 集合的定义: st = set (‘ hello ‘) lis = list (‘ hello ‘) print ( st ) # {‘h‘, ‘o‘, ‘l‘, ‘e‘} print ( lis ) # [‘h‘, ‘e‘, ‘l‘, ‘l‘, ‘o‘] # 【注意】 dic ={}#空花括号{},代表定义字典 print (‘ dic type :% s ‘% type ( dic )) >>: dic type :< class ‘ dict ‘> st = {‘ h ‘, ‘ e ‘, ‘ l ‘, ‘ l ‘, ‘ o ‘}#定义的时候集合内出现了重复的项,但是并没有报错,只是剔除了重复 element print ( st ) # {‘h‘, ‘o‘, ‘l‘, ‘e‘} 1 )集合是无序的, 不重复的数据类型; 2 )因此不支持索引,也不支持切片;也不支持重复;也不支持连接; 3 )支持成员操作符; 4 )支持 for 循环; #

2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)【A题 类型好题】

最后都变了- 提交于 2019-12-02 22:07:06
A. Berstagram Polycarp recently signed up to a new social network Berstagram. He immediately published n posts there. He assigned numbers from 1 to n to all posts and published them one by one. So, just after publishing Polycarp's news feed contained posts from 1 to n — the highest post had number 1, the next one had number 2, ..., the lowest post had number n. After that he wrote down all likes from his friends. Likes were coming consecutively from the 1-st one till the m-th one. You are given a sequence a1,a2,…,am (1≤aj≤n), where aj is the post that received the j-th like. News feed in

与众不同

落爺英雄遲暮 提交于 2019-12-02 19:46:30
https://loj.ac/problem/10121 题目描述   给出一个长度为 \(n\) 的序列,定义完美序列为一段连续的序列满足区间内的数都不相同。给出 \([l,r]\) ,求出这个区间内完美序列的最长长度。 思路   这题就是 \(ST\) 表的较复杂应用,而且想到 \(ST\) 表并不容易。我们用 \(last[i]\) 表示 \(i\) 这个值上一次出现的位置,用 \(st[i]\) 表示以 \(i\) 结尾的最长完美序列的起始位置,那么很容易得到 \(st\) 的递推式 \(st[i]=max(st[i-1],last[a[i]]+1)\) 。我们再用 \(f[i]\) 表示以 \(i\) 结尾的最长完美序列的长度,显然 \(f[i]=i-st[i]+1\) 。   求完这两个数组后,我们考虑对于st数组一定是单调增的,所以对于一个询问区间 \([l,r]\) ,我们可以进行二分,假设二分到的值为 \(pos\) ,表示对于 \([l,pos)\) , \(st\) 数组的值都小于 \(l\) ,对于 \([pos,r]\) , \(st\) 数组的值都大于等于 \(l\) 。那么我们就将询问区间分成两部分来处理,第一部分的最大值显然为 \(pos-l\) ,第二部分就为 \([pos,r]\) 中 \(f\) 的最大值,用 \(ST\) 表维护这个值即可。

Luogu-P1967 货车运输

社会主义新天地 提交于 2019-12-02 17:01:28
题面 分析 可以先求最大生成树森林,然后对每棵树进行树链剖分,然后乱搞... 注意,由于是边权,则统一挂向连接点的更深的(挂向浅的后果自行分析),求路径上最小边时不在同一链就普通处理,在同一链,所求区间应去掉更浅的端点。 本题我以为只有只有一棵生成树 结果CCF原数据真只有一棵 ,感谢luogu的hack,但hack数据好像是错的.... #include<iostream> #include<cstdio> #include<cmath> #include<queue> #include<cstring> #include<algorithm> #define lson x<<1 #define rson x<<1|1 #define ll long long #define rint register int #define mid ((st[x].l + st[x].r) >> 1) using namespace std; template <typename xxx> inline void read(xxx &x) { char c = getchar(),f = 1;x = 0; for(;c ^ '-' && !isdigit(c);c = getchar()); if(c == '-') c = getchar(),f = -1; for(;isdigit(c)

AGC029C - Lexicographic constraints

放肆的年华 提交于 2019-12-02 16:17:18
记录我心路历程吧,这道小水题暴露出我很多问题。 给定 \(n\) 个字符串长度 \(a_i\) ,求字符集最小多大,才能构造出按字典序比较 \(s_1 < s_2 < \dots < s_n\) 。 当 \(a_i < a_{i+1}\) 时,显然全补 \(0\) 就行。否则,是一个高精度 \(+1\) 。二分字符集大小,判断行不行。 以下是我做题过程。 首先,除了二分部分,全部推出来了。但是加法的细节写烂了,各种没判。 然后没有特判字符集为 \(1\) 的情况,硬是跑了 1e9 差点T。(最后改改还是T了) 然后考虑贪心的过程,写了一个错的。在字符不够的时候新开一个,实际上会导致前面的浪费。 blog 写到最后发现还是一道sb题,就当水了一个 blog 吧。 #include <bits/stdc++.h> const int MAXN = 500010; int n, st[MAXN], col[MAXN], top; void add() { if (st[top] > 1 && st[top - 1] != st[top] - 1) { st[top + 1] = st[top]; col[top + 1] = col[top]; --st[top]; ++top; } ++col[top]; } int A[MAXN]; bool judge(int cnt) { int

Python爬虫实战之模拟登录淘宝并获取所有订单 !

懵懂的女人 提交于 2019-12-02 11:21:25
经过多次尝试,模拟登录淘宝终于成功了,实在是不容易,淘宝的登录加密和验证太复杂了,煞费苦心,在此写出来和大家一起分享,希望大家支持。 温馨提示 现在淘宝换成了滑块验证了,比较难解决这个问题,以下的代码没法用了,仅作学习参考研究之用吧。 本篇内容 1. python模拟登录淘宝网页 2. 获取登录用户的所有订单详情 3. 学会应对出现验证码的情况 4. 体会一下复杂的模拟登录机制 探索部分成果 1. 淘宝的密码用了AES加密算法,最终将密码转化为256位,在POST时,传输的是256位长度的密码。 2. 淘宝在登录时必须要输入验证码,在经过几次尝试失败后最终获取了验证码图片让用户手动输入来验证。 3. 淘宝另外有复杂且每天在变的 ua 加密算法,在程序中我们需要提前获取某一 ua 码才可进行模拟登录。 4. 在获取最后的登录 st 码时,历经了多次请求和正则表达式提取,且 st 码只可使用一次。 整体思路梳理 1. 手动到浏览器获取 ua 码以及 加密后的密码,只获取一次即可,一劳永逸。 2. 向登录界面发送登录请求,POST 一系列参数,包括 ua 码以及密码等等,获得响应,提取验证码图像。 3. 用户输入手动验证码,重新加入验证码数据再次用 POST 方式发出请求,获得响应,提取 J_Htoken。 4. 利用 J_Htoken 向 alipay 发出请求,获得响应,提取 st

Colorful String

柔情痞子 提交于 2019-12-02 11:21:09
Colorful String 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 1e6+5; 5 char s[maxn]; 6 int n; 7 int record[maxn]; // 记录i结点在原字符串的位置 8 int sum[maxn*4]; 9 void pushup(int rt) { 10 sum[rt] |= sum[rt*2]; 11 sum[rt] |= sum[rt*2+1]; 12 } 13 void build(int l, int r, int rt) { 14 if (l == r) { 15 sum[rt] |= 1<<(s[l]-'a'); 16 return; 17 } 18 int mid = (l+r)/2; 19 build(l,mid,rt*2); 20 build(mid+1,r,rt*2+1); 21 pushup(rt); 22 } 23 int query(int be, int ed, int l, int r, int rt) { 24 if (be <= l && r <= ed) { 25 return sum[rt]; 26 } 27 int mid = (l+r)/2, res

P3649 [APIO2014]回文串

a 夏天 提交于 2019-12-02 11:19:57
P3649 [APIO2014]回文串 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 300010; 5 char s[maxn]; 6 int n; 7 struct PAM { 8 int last; 9 struct Node { 10 int cnt, len, fail, son[27]; // cnt为以i为结尾的回文子串个数,len为长度 11 Node(int len, int fail) : len(len), fail(fail), cnt(0){ 12 memset(son, 0, sizeof(son)); 13 }; 14 }; 15 vector<Node> st; 16 inline int newnode(int len, int fail = 0) { 17 st.emplace_back(len, fail); 18 return st.size()-1; 19 } 20 inline int getfail(int x, int n) { 21 while (s[n-st[x].len-1] != s[n]) x = st[x].fail; 22 return x; 23 } 24 inline void

Codeforces Round #595 (Div. 3)

北城余情 提交于 2019-12-02 05:28:13
题目链接: https://codeforces.com/contest/1249/problem/A A. Yet Another Dividing into Teams 题意:n个学生,分成任意组,要求每组中任意两名学生的技能值相差不等于1,问最小分组。 思路:易得答案非 1 即 2 ,排序完for一遍判断相邻差值等于 1 是否存在即可。 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1e5 +50; 4 int a[maxn]; 5 int main() 6 { 7 std::ios::sync_with_stdio(false); 8 int t; 9 cin >> t; 10 while(t--) 11 { 12 int n; 13 cin >> n; 14 for(int i = 0;i < n;i++) 15 { 16 cin >> a[i]; 17 } 18 sort(a, a + n); 19 bool flag = false; 20 for(int i = 1;i < n;i++) 21 { 22 if(a[i] - a[i - 1] == 1) 23 { 24 flag = true; 25 break; 26 } 27 } 28 if(flag) cout << 2