当前位置:网站首页>Ccf-csp 202012-3 file system with quota
Ccf-csp 202012-3 file system with quota
2022-06-09 02:42:00 【Confident little screw】
Original link : File systems with quotas
This question is really !! complex !! miscellaneous !!
I really can't write it out ..... Since I can't write it ! Then refer to others :CSP202012-3 File systems with quotas , This is the best explanation of this problem I have ever seen , The following code is also based on this blog , Worship big brother !
#include <bits/stdc++.h>
using namespace std;
const int N=4e6+10;
#define ll unsigned long long
string path;
ll filesize,ld,lr;
struct Node
{
int father;
map<string,int> child;
int type;
ll ld,lr;
ll fsize;
ll ldsum,lrsum;
}node[4000010];
int num=0;
vector<pair<int,string>> record;
void reback()
{
for(int i=0;i<record.size();i++)
{
int a=record[i].first;
string b=record[i].second;
node[a].child.erase(node[a].child.find(b));
}
}
string func(vector<string> v)
{
int id=0;
int last= v.size()-1>=0 ? v.size()-1:0;
int cur=0;
int pre=num;
string t;
record.clear();
while(cur<last)
{
t=v[cur];
cur++;
if(node[id].child.find(t)==node[id].child.end())
{
num++;
node[id].child[t]=num;
node[num].father=id;
node[num].type=2;
node[num].ld=LLONG_MAX/3;
node[num].lr=LLONG_MAX/3;
record.push_back(make_pair(id,t));
id=num;
}
else
{
int childid=node[id].child[t];
if(node[childid].type==1)
{
num=pre;
reback();
return "N";
}
id=childid;
}
}
if(v.size()>0) t=v[last];
if(node[id].child.find(t)!=node[id].child.end())
{
int childid=node[id].child[t];
if(node[childid].type==2)
{
num=pre;
reback();
return "N";
}
}
ll changesize=0;
if(node[id].child.find(t)==node[id].child.end()) changesize=filesize;
else changesize=-node[node[id].child[t]].fsize+filesize;
if(node[id].ldsum+changesize>node[id].ld)
{
num=pre;
reback();
return "N";
}
cur=id;
while(cur!=-1)
{
if(node[cur].lrsum+changesize>node[cur].lr)
{
num=pre;
reback();
return "N";
}
cur=node[cur].father;
}
if(node[id].child.find(t)==node[id].child.end())
{
num++;
node[num].type=1;
node[num].father=id;
node[num].fsize=filesize;
node[id].child[t]=num;
}
else node[node[id].child[t]].fsize=filesize;
node[id].ldsum+=changesize;
cur=id;
while(cur!=-1)
{
node[cur].lrsum+=changesize;
cur=node[cur].father;
}
return "Y";
}
string funr(vector<string> v)
{
int id=0;
int last= v.size()-1>=0 ? v.size()-1:0;
int cur=0;
int pre=num;
string t;
while(cur<last)
{
t=v[cur];
cur++;
if(node[id].child.find(t)==node[id].child.end()) return "Y";
else
{
int childid=node[id].child[t];
if(node[childid].type==1) return "Y";
id=childid;
}
}
if(v.size()>0) t=v[last];
if(node[id].child.find(t)==node[id].child.end()) return "Y";
ll delsize=0;
int delnode=node[id].child[t];
if(node[delnode].type==1)
{
node[id].ldsum-=node[delnode].fsize;
delsize=node[delnode].fsize;
node[id].child.erase(node[id].child.find(t));
}
else if(node[delnode].type==2)
{
delsize=node[delnode].lrsum;
node[id].child.erase(node[id].child.find(t));
}
cur=id;
while(cur!=-1)
{
node[cur].lrsum-=delsize;
cur=node[cur].father;
}
return "Y";
}
string funq(vector<string> v)
{
if(ld==0) ld=LLONG_MAX/3;
if(lr==0) lr=LLONG_MAX/3;
int id=0;
int cur=0;
int last= v.size()-1>=0 ? v.size()-1:0;
string t;
while(cur<last)
{
t=v[cur];
cur++;
if(node[id].child.find(t)==node[id].child.end()) return "N";
else
{
int childid=node[id].child[t];
if(node[childid].type==1) return "N";
id=childid;
}
}
if(v.size()>0) t=v[last];
int qnode=0;
if(t=="") qnode=0;
else
{
if(node[id].child.find(t)==node[id].child.end()) return "N";
else qnode=node[id].child[t];
}
if(node[qnode].type==1) return "N";
if(ld<node[qnode].ldsum || lr<node[qnode].lrsum) return "N";
node[qnode].ld=ld;
node[qnode].lr=lr;
return "Y";
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; cin>>n;
char op;
node[0].father=-1;
node[0].type=2;
node[0].ld=LLONG_MAX/3;
node[0].lr=LLONG_MAX/3;
for(int i=1;i<=n;i++)
{
cin>>op>>path;
stringstream ss(path);
string t;
vector<string> v;
while(getline(ss,t,'/')) v.push_back(t);
v.erase(v.begin());
if(op=='C')
{
cin>>filesize;
cout<<func(v)<<endl;
}
else if(op=='R')
{
cout<<funr(v)<<endl;
}
else if(op=='Q')
{
cin>>ld>>lr;
cout<<funq(v)<<endl;
}
}
return 0;
}
边栏推荐
- 杰理之如何修改 ad_key 连接的引脚?【篇】
- Range of acwing 789 numbers
- How does JVM handle exceptions? The principle that finally blocks must execute?
- Tiflash source code reading (III) design and implementation analysis of tiflash deltatree storage engine - Part 1
- Export related knowledge
- Self implemented web server
- 杰理之SPI 从机【篇】
- pkg-config --modversion opencvPackage opencv was not found in the pkg-config search path. Perhaps y
- 【网络协议】| 【01】网络字节序大端、小端
- Jericho's notes on SPI host configuration parameters: 【 chapter 】
猜你喜欢

Ccf-csp 201903-2 24:00

蓝桥杯_青蛙的约会_扩展欧几里得

Jsnpp框架的全链式语法初探

toggleRowSelection()失效的2個重要影響因素

Go to MFC from Win32

Navicat tool batch imports JSON format data to Doris

Leetcode 1371. Each vowel contains an even number of times the longest substring XOR + prefix and

Problems and solutions in using renrenfast

Leetcode 801. Minimum number of exchanges DP to increment the sequence

Interface test series - interface test practice of transfer transaction business scenarios
随机推荐
Leetcode 801. Minimum number of exchanges DP to increment the sequence
Calendar time operation
[network protocol] | [01] network byte order big end and small end
(10.3) [steganography mitigation] steganography protection, steganography interference and steganography detection
Basic method of missing data filling (1) -- k-nearest neighbors (KNN) filling
I'm sorry if I don't understand. The final battle
杰理之关于 SPI 主机配置参数的几个说明篇】
Range of acwing 789 numbers
Interface test series - interface test practice of transfer transaction business scenarios
Jericho's several descriptions on SPI host configuration parameters]
Gradle view the dependency tree of a package
Leetcode 454. Quad add II hash
QT project add compile error reporting option
Tell me about the bug that impressed you
Unity中,继承MonoBehaviour游戏对象的生命周期
Ccf-csp 201903-2 24:00
动态规划/n的k拆分 n的最大加数k拆分
独家 | 维信金科申请消费金融牌照未果
LeetCode 1155. 擲骰子的N種方法**
说说你印象中比较深刻的 Bug