隐藏页面特效

CCF 202012-3 带配额的文件系统

100%

(参考了这里

#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e6+15; const ll inf=(ll)(1e18)<<2; #define pb push_back #define mp make_pair struct node{ int fa; map<string, int> ch;//目录下的孩子文件 int typ;//0 directory 1 file ll siz; ll LD,LR;//目录配额,后代配额; ll D_size,R_size;//实际占用的大小 node(int typ=0,ll siz=0):typ(typ),siz(siz){ fa=0; ch.clear(); LD=inf,LR=inf; D_size=0,R_size=0; } }d[N]; int rt=0,cnt=0; vector<pair<int,string> >rbk; void rollback(){ for(auto &t:rbk) d[t.first].ch.erase(t.second); } bool C(){ string path="",to="";ll v=0,changesize=0; cin>>path;cin>>v; int sz=path.size(),x=rt; rbk.clear(); //directory for(int i=1;i<sz;++i){ if(path[i]=='/'){ if(!d[x].ch[to]){ d[x].ch[to]=++cnt; d[cnt].fa=x; rbk.pb(mp(x,to)); } x=d[x].ch[to]; if(d[x].typ==1) return rollback(),0; to.clear(); } else to+=path[i]; } //file if(d[x].ch[to]){ if(d[d[x].ch[to]].typ==0) return rollback(),0; changesize=-d[d[x].ch[to]].siz+v; } else{ changesize=v; } if(d[x].D_size+changesize>d[x].LD) return rollback(),0; for(int y=x;~y;y=d[y].fa){ if(d[y].R_size+changesize>d[y].LR) return rollback(),0; } if(!d[x].ch[to]){ d[x].ch[to]=++cnt; d[cnt]=node(1,v); d[cnt].fa=x; } else{ d[d[x].ch[to]].siz=v; } d[x].D_size+=changesize; for(int y=x;~y;y=d[y].fa) d[y].R_size+=changesize; return 1; } bool R(){ string path,to; cin>>path;int sz=path.size(),x=rt; for(int i=1;i<sz;++i){ if(path[i]=='/'){ if(!d[x].ch[to]) return 1; x=d[x].ch[to]; if(d[x].typ==1) return 1; to.clear(); } else to+=path[i]; } int t=d[x].ch[to]; if(!t) return 1; ll delsiz=0; if(d[t].typ==1){ d[x].D_size-=(delsiz=d[t].siz); d[x].ch.erase(to); d[t]=node(); } else{ delsiz=d[t].R_size; d[x].ch.erase(to); d[t]=node(); } for(int y=x;~y;y=d[y].fa) d[y].R_size-=delsiz; return 1; } bool Q(){ string path="",to="";ll ld=0,lr=0; cin>>path;cin>>ld>>lr; if(ld==0) ld=inf; if(lr==0) lr=inf; int sz=path.size(),x=rt; for(int i=1;i<sz;++i){ if(path[i]=='/'){ if(!d[x].ch[to]) return 0; x=d[x].ch[to]; if(d[x].typ==1) return 0; to.clear(); } else to+=path[i]; } int Qnode=rt; if(to==""){ Qnode=rt; } else{ if(!d[x].ch[to]) return 0; else Qnode=d[x].ch[to]; } if(d[Qnode].typ == 1) return 0; if(ld<d[Qnode].D_size||lr<d[Qnode].R_size) return 0; d[Qnode].LD=ld,d[Qnode].LR=lr; return 1; } void print(bool f){puts(f?"Y":"N");} int main(){ int n;char opt[4]; d[rt].fa=-1; cin>>n; for(int i=0;i<n;++i){ scanf("%s",opt); if(opt[0]=='C') print(C());else if(opt[0]=='R') print(R());else if(opt[0]=='Q') print(Q()); } return 0; }

 


__EOF__

本文作者shenben
本文链接https://www.cnblogs.com/shenben/p/14494159.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   神犇(shenben)  阅读(689)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决
历史上的今天:
2017-03-07 1101: [POI2007]Zap
2017-03-07 POJ2417 Discrete Logging【BSGS】
2017-03-07 1076: [SCOI2008]奖励关
2017-03-07 2318: Spoj4060 game with probability Problem
2017-03-07 3450: Tyvj1952 Easy
2017-03-07 1426: 收集邮票
2017-03-07 2698: 染色
点击右上角即可分享
微信分享提示