2019牛客暑期多校训练营(第三场)J LRU management
2019-07-26 16:28
465 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_28959053/article/details/97395060
- 介个博客的意义是记录dubug的一天
- bug来源:当重复插入的是链表中唯一一个元素时。。整个链表会消失orz。。特判了一下就过了。。本来都不报希望了orz
ps:手动模拟链表好累啊QAQ - 代码:
#include<bits/stdc++.h> using namespace std; struct lis{ string s; int v; int f,b; }l[1000005]; unordered_map<string,int> m; int main(){ int t; scanf("%d",&t); while(t--){ m.clear(); int n,k; scanf("%d %d",&n,&k); int back=-1; int front=-1; int size=0; while(n--){ int op,x; char ss[13]; scanf("%d %s %d",&op,ss,&x); string s(ss); if(op==0){ if(!m.count(s)||m[s]==-1){ back++; l[back].s=s; if(size!=0) { l[back].f=back-1; l[back-1].b=back; l[back].v=x; } else { l[back].v=x; front=back; l[back].f=-1; } l[back].b=-1; size++; m[s]=back; printf("%d\n",x); } else{ int gps=m[s]; int ff=l[gps].f; int bb=l[gps].b; if(ff==-1&&bb==-1) {//处理的bug printf("%d\n",l[gps].v); continue; } if(ff!=-1) l[ff].b=l[gps].b; else front=bb,l[bb].f=-1; if(bb!=-1) l[bb].f=l[gps].f; else back=ff,l[ff].b=-1; printf("%d\n",l[gps].v); l[back].b=back+1; back++; l[back].s=s; l[back].v=l[gps].v; l[back].b=-1; l[back].f=back-1; m[s]=back; } if(size>k){ m[l[front].s]=-1; l[l[front].b].f=-1; front=l[front].b; size--; } int no=front; } else{ if(!m.count(s)||m[s]==-1) { printf("Invalid\n"); continue; } int g=m[s]; if(x==0){ printf("%d\n",l[g].v); } else if(x==-1){ if(l[g].f!=-1){ printf("%d\n",l[l[g].f].v); } else{ printf("Invalid\n"); } } else if(x==1){ if(l[g].b!=-1){ printf("%d\n",l[l[g].b].v); } else{ printf("Invalid\n"); } } } } } } /* 10 10 10 0 1 0 0 2 1 0 3 2 0 4 3 0 1 4 0 3 5 0 4 6 1 1 -1 1 4 1 1 2 1 8 3 0 0101010 1 0 0101011 2 1 0101010 1 0 1100000 3 0 0101011 -1 0 1111111 4 1 0101011 -1 1 0101010 0 1 5 1 0 0 10 0 00 20 1 0 1 1 00 -1 */
相关文章推荐
- 2019牛客暑期多校训练营(第三场)
- 2019牛客暑期多校训练营(第三场) B题
- 2019牛客暑期多校训练营 第三场
- 2019牛客暑期多校训练营(第三场)
- 2019牛客暑期多校训练营(第四场) J 题 free
- 2019牛客暑期多校训练营(第六场)D Move 二分
- 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)
- 2019牛客暑期多校训练营(第一场) - A - Equivalent Prefixes - 单调栈
- 2019牛客暑期多校训练营(第二场) - H - Second Large Rectangle - dp
- 2019 牛客暑期多校训练营(第四场)J Free
- 2019牛客暑期多校训练营(第六场)J(枚举)
- 2019牛客暑期多校训练营(第七场) B Irreducible Polynomial
- 2019牛客暑期多校训练营(第七场)H(数位DP)
- 2019牛客暑期多校训练营(第二场),H
- 2019牛客暑期多校训练营 第四场
- 2019牛客暑期多校训练营(第七场)D Number
- 2019牛客暑期多校训练营(第一场),A题(笛卡尔树)
- 2019牛客暑期多校训练营(第二场)
- 2019牛客暑期多校训练营(第七场)J A+B problem
- 2019牛客暑期多校训练营 第二场