1 条题解
-
0
deque空间会爆,list的size是线性的,可能被卡掉(虽然并没有),所以可以手写一个list
AC代码:
#include<bits/stdc++.h> #define maxn 1000010 using namespace std; #include<ext/rope> using namespace __gnu_cxx; //rbtree //#define rbtree_open #ifdef rbtree_open #include<ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define settree(a) tree<a,null_type,less<a>,rb_tree_tag,tree_order_statistics_node_update> #define kth(a) find_by_order(a-1) #define nth(a) order_of_key(a) #endif #define int long long //#define int __int128 //#pragma GCC optimize(2) //#define superfast //开启后只能读入整型 #ifdef superfast constexpr int MAXSIZE = 1 << 20; char buf[MAXSIZE], *p1, *p2; #define gc() \ (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) \ ? EOF \ : *p1++) char pbuf[1 << 20], *pp = pbuf; const __inline void push(const char &c) { if (pp - pbuf == 1 << 20) fwrite(pbuf, 1, 1 << 20, stdout), pp = pbuf; *pp++ = c; } #else #define gc getchar #define pushc putchar #endif #ifdef int #define inf 0x3f3f3f3f3f3f3f3f #else #define inf 0x3f3f3f3f #endif //#define rd_open template<typename T>typename enable_if<is_integral<T>::value && is_signed<T>::value>::type __inline read(T &x){x=0;char ch=gc();bool f=0;while(ch<'0'||ch>'9'){if(ch=='-') f=1;if(ch==EOF) return;ch=gc();}while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=gc();if(f) x=-x;}__inline void read(double &x){scanf("%lf",&x);}__inline void read(string &x){cin>>x;}__inline void read(char &x){cin>>x;}__inline void read(char *x){cin>>x;}__inline int read(){int x = 0,y = 1;char ch = gc();while(ch < '0'||ch > '9'){if(ch == '-') y = -1;if(ch ==EOF)return 0;ch = gc();}while(ch >= '0'&&ch <= '9'){x = x*10+ch-48;ch = gc();}return x*y;}template<typename T,typename ...Args>inline void read(T &tmp,Args &...tmps){read(tmp),read(tmps...);} //#define pr_open template<typename T>typename enable_if<is_integral<T>::value && is_signed<T>::value>::type __inline print(T x){if(x<0) x=-x,putchar('-');static int sta[30];int top = 0;do sta[top++] = x % 10, x /= 10;while (x);while (top) putchar(sta[--top] + 48);}inline void print(double x){printf("%lf",x);}inline void print(char x){putchar(x);}inline void print(char* x){fputs(x,stdout);}inline void print(string x){fputs(x.c_str(),stdout);}template<typename T,typename ...Args>inline void print(T tmp,Args ...tmps){print(tmp);print(tmps...);} // #if __cplusplus <= 201703L // #define rd_open template<typename T>typename enable_if<is_integral<T>::value>::type __inline read(T &x){x=0;char ch=gc();bool f=0;while(ch<'0'||ch>'9'){if(ch=='-') f=1;if(ch==EOF) return;ch=gc();}while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=gc();if(f) x=-x;}__inline void read(double &x){scanf("%lf",&x);}__inline void read(string &x){cin>>x;}__inline void read(char &x){cin>>x;}__inline void read(char *x){cin>>x;}__inline int read(){int x = 0,y = 1;char ch = gc();while(ch < '0'||ch > '9'){if(ch == '-') y = -1;if(ch ==EOF)return 0;ch = gc();}while(ch >= '0'&&ch <= '9'){x = x*10+ch-48;ch = gc();}return x*y;}template<typename T,typename ...Args>inline void read(T &tmp,Args &...tmps){read(tmp),read(tmps...);} // #define pr_open template<typename T>typename enable_if<is_integral<T>::value>::type __inline print(T x){if(x<0) x=-x,putchar('-');static int sta[30];int top = 0;do sta[top++] = x % 10, x /= 10;while (x);while (top) putchar(sta[--top] + 48);}inline void print(double x){printf("%lf",x);}inline void print(char x){putchar(x);}inline void print(char* x){fputs(x,stdout);}inline void print(string x){fputs(x.c_str(),stdout);}template<typename T,typename ...Args>inline void print(T tmp,Args ...tmps){print(tmp);print(tmps...);} // #else #define rd_open template<typename T>inline void read(T &x){x=0;char ch=gc();bool f=0;while(ch<'0'||ch>'9'){if(ch=='-') f=1;if(ch==EOF) exit(0);ch=gc();}while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=gc();if(f) x=-x;}inline void read(double &x){scanf("%lf",&x);}inline void read(string &x){cin>>x;}inline void read(char &x){cin>>x;}int read(){int x = 0,y = 1;char ch = gc();while(ch < '0'||ch > '9'){if(ch == '-') y = -1;if(ch ==EOF)exit(0);ch = gc();}while(ch >= '0'&&ch <= '9'){x = x*10+ch-48;ch = gc();}return x*y;}template<typename T,typename ...Args>inline void read(T &tmp,Args &...tmps){read(tmp),read(tmps...);} #define pr_open template<typename T>inline void print(T x){if(x<0) x=-x,putchar('-');static int sta[30];int top = 0;do sta[top++] = x % 10, x /= 10;while (x);while (top) putchar(sta[--top] + 48);}inline void print(double x){printf("%lf",x);}inline void print(char x){putchar(x);}inline void print(string x){fputs(x.c_str(),stdout);}template<typename T,typename ...Args>inline void print(T tmp,Args ...tmps){print(tmp);print(tmps...);} // #endif #define groups struct group{struct edge{int t,lon;};struct qwq{int d, u;__inline bool operator<(qwq a) const{return d<a.d;}};int n,m;vector<edge> e[maxn];int d[maxn], vis[maxn];deque<qwq> q;const __inline void spfa(int t){for(int i=1; i<=n; ++i) d[i]=inf;d[t]=0;q.push_back({0,t});vis[t]=1;while(q.size()){int f=q.front().u;q.pop_front();vis[f]=0;for(auto i:e[f]){int fto=i.t;int w=i.lon;if(d[f]+w<d[fto]){d[fto]=d[f]+w;if(!vis[fto]){if(d[fto]>q.front().d)q.push_back({d[fto],fto}),vis[fto]=1;else q.push_front({d[fto],fto}),vis[fto]=1;}}}}}priority_queue<qwq> qwq;void dj(int t){for(int i=0; i<=n; ++i) d[i]=inf,vis[i]=0;d[t] = 0,qwq.push({0, t});while(qwq.size()){int u = qwq.top().u;qwq.pop();if (vis[u]) continue;vis[u]=1;for(auto i:e[u])if(d[i.t]>d[u]+i.lon)d[i.t]=d[u]+i.lon,qwq.push({d[i.t],i.t});}}}; #define hash_open struct my_hash{static int splitmix64(int x){x += 0x9e3779b97f4a7c15;x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;x = (x ^ (x >> 27)) * 0x94d049bb133111eb;return x ^ (x >> 31);}size_t operator()(int x) const{static const int FIXED_RANDOM =chrono::steady_clock::now().time_since_epoch().count();return splitmix64(x + FIXED_RANDOM);}size_t operator()(pair<int, int> x) const{static const int FIXED_RANDOM =chrono::steady_clock::now().time_since_epoch().count();return splitmix64(x.first + FIXED_RANDOM) ^(splitmix64(x.second + FIXED_RANDOM) >> 1);}}; #define qpow_open inline int pw(int a,int b,int _the_mod_in_qpow){int ans=1;while(b){if(b&1) ans*=a,ans%=_the_mod_in_qpow;a*=a,a%=_the_mod_in_qpow,b>>=1;}return ans;}inline int pw(int a,int b){int ans=1;while(b){if(b&1) ans*=a;a*=a,b>>=1;}return ans;} #define shai_open struct isp{bitset<maxn+5>v;vector<int>p;void eu(){v[1]=1;for(int i = 2; i <= maxn; i++){if(!v[i])p.push_back(i);for (int j=0; j<p.size()&& i*p[j]<= maxn; j++){v[i*p[j]]= 1;if (!(i%p[j]))break;}}}void Era(){for(int i=2; i<=maxn; ++i) v[i]=1;for(int i=2; i<=maxn; ++i){if(v[i]){p.push_back(i);if(i*i>maxn) continue;for(int j=i*i; j<=maxn; j+=i)v[j]=0;}}}map<int,int>mp;const __inline int get(int A,bool c=1){if(c) mp.clear();if(A<2) return 1;for(int j:p){while(!(A%j))A/=j,++mp[j];if(A==1) break;if(j*j>A){++mp[A];break;}}return 0;}const __inline int fn(int A){int ans=A;for(int j:p){if(!(A%j)) ans=ans/j*(j-1);while(!(A%j))A/=j;if(A==1) break;if(j*j>A)break;}if(A>1) ans=ans/A*(A-1);return ans;}}; rd_open pr_open qpow_open template <typename T> __inline void read(T *l,T *r) { for(auto i=l; i<r; i++) { read(*i); } } template <typename T> __inline void print(T *l,T *r) { for(auto i=l; i<r; i++) { print(*i); putchar(32); } putchar(10); } //shai_open //groups //hash_open //segment_tree // unordered_map<int, int, my_hash> cnt; // unordered_map<pair<int,int>, int, my_hash> cnt; int m,q; struct l { struct qwq { int num; qwq *f; qwq *t; }; int sz; qwq *bg,*ed; __inline void push_back(int a) //code by langmou { qwq *r=new qwq; r->num=a; if(sz++) { r->f=ed; ed->t=r; ed=r; } else ((bg=ed=r)->f=r)->t=r; } __inline void push_front(int a) //code by langmou { qwq *r=new qwq; //code by langmou r->num=a; if(sz++) { r->t=bg; bg->f=r; bg=r; } else ((bg=ed=r)->f=r)->t=r; } __inline void pop_back() { if(--sz) { ed=ed->f; delete ed->t; } else delete ed; } __inline void pop_front() { if(--sz) { bg=bg->t; delete bg->f; } else delete bg; } __inline int front() { return bg->num; } __inline int back() { return ed->num; } }; l d[maxn]; string s; int a,b; signed main() { read(q); ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); //code by langmou while(q--) { cin>>s>>a; if(s=="push_back") { cin>>b; d[a].push_back(b); if(__cplusplus>201103)puts("code by langmou"),d[0].pop_back(); } if(s=="push_front") { cin>>b; d[a].push_front(b); if(__cplusplus>201103)puts("code by langmou"),d[0].pop_back(); } if(s=="pop_back") { if(d[a].sz) d[a].pop_back(); } if(s=="pop_front") { if(d[a].sz) d[a].pop_front(); } if(s=="front") { if(d[a].sz) print(d[a].front()),putchar(10); if(__cplusplus>201103)puts("code by langmou"),d[0].pop_back(); } if(s=="back") { if(d[a].sz) print(d[a].back()),putchar(10); } if(s=="size") { print(d[a].sz); putchar(10); } if(__cplusplus>201103)puts("code by langmou"),d[0].pop_back(); } }
信息
- ID
- 4672
- 时间
- 2000ms
- 内存
- 250MiB
- 难度
- 3
- 标签
- 递交数
- 27
- 已通过
- 4
- 上传者