广东省城乡建设厅网站企业网站的功能
广东省城乡建设厅网站,企业网站的功能,口碑好网站建设价格,电脑网站在哪里找传送门 文章目录题意#xff1a;思路#xff1a;题意#xff1a;
你需要实现如下四个操作 q≤1e7q\le1e7q≤1e7
思路#xff1a;
做的时候想了个链表的思路让队友写了#xff0c;懒。 看了题解感觉题解还是很妙的。 你需要快速插入一个数在前后两端#xff0c;还需要…传送门
文章目录题意思路题意
你需要实现如下四个操作 q≤1e7q\le1e7q≤1e7
思路
做的时候想了个链表的思路让队友写了懒。 看了题解感觉题解还是很妙的。 你需要快速插入一个数在前后两端还需要支持删除一个数和查询中间位置的数标号。 链表的思路比较明显直接维护中点的位置让后每次删除的时候将这个点的链表指向下一个点即可。就是写起来貌似不是很好写。 题解是维护了两个双端队列一个代表左边一个代表右边输出答案的话就是右边的第一个位置。考虑两种情况 (1)lsizersize(1)lsizersize(1)lsizersize此时不平衡需要将左边的最右端元素插入右边最左端。 (2)lsize1rsize(2)lsize1rsize(2)lsize1rsize此时也不平衡需要将右边的最左端元素插入左边的最右端。 让后删除操作就可以直接打个懒标记遇到已经删掉的点的时候再将其移除队列。 复杂度O(nq)O(nq)O(nq)跑了4s4s4s。。
// Problem: G - Boring data structure problem
// Contest: Virtual Judge - 2021多校第九场补题
// URL: https://vjudge.net/contest/454088#problem/G
// Memory Limit: 262 MB
// Time Limit: 6000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize(Ofast,no-stack-protector,unroll-loops,fast-math)
//#pragma GCC target(sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tunenative)
//#pragma GCC optimize(2)
#includecstdio
#includeiostream
#includestring
#includecstring
#includemap
#includecmath
#includecctype
#includevector
#includeset
#includequeue
#includealgorithm
#includesstream
#includectime
#includecstdlib
#includerandom
#includecassert
#includedeque
#define X first
#define Y second
#define L (u1)
#define R (u1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].ltr[u].r)1)
#define Len(u) (tr[u].r-tr[u].l1)
#define random(a,b) ((a)rand()%((b)-(a)1))
#define db puts(---)
using namespace std;//void rd_cre() { freopen(d://dp//data.txt,w,stdout); srand(time(NULL)); }
//void rd_ac() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//AC.txt,w,stdout); }
//void rd_wa() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//WA.txt,w,stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pairint,int PII;const int N20000010,mod1e97,INF0x3f3f3f3f;
const double eps1e-6;int n;
dequeintl,r;
int lsize,rsize;
int bel[N],st[N];void resize() {if(lsizersize) {while(st[l.back()]) l.pop_back();bel[l.back()]^1;r.push_front(l.back()); l.pop_back();lsize--; rsize;} else if(lsize1rsize) {while(st[r.front()]) r.pop_front();bel[r.front()]^1;l.push_back(r.front()); r.pop_front();lsize; rsize--; }
}int solve() {if(r.size()0) return 0;while(st[r.front()]) r.pop_front();return r.front();
}int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0); cinn;int now0;while(n--) {char op[2]; scanf(%s,op);if(op[0]L) l.push_front(now),lsize,bel[now]0;else if(op[0]R) r.push_back(now),rsize,bel[now]1;else if(op[0]G) {int x; scanf(%d,x);st[x]1; if(bel[x]0) lsize--;else rsize--;} else printf(%d\n,solve());resize();}return 0;
}
/**/
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/89325.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!