#include<iostream>
#include<string>
#include<regex>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
typedef struct files{
char t;
long long ld=0,lr=0,sd=0,sr=0,s=0;
map<string,struct files> childs;
}file;
file root;
file* nowcata;
file* temcata;
int CCcheck(string s){
if(nowcata->childs.find(s)==nowcata->childs.end()){
return 0;
}else if(nowcata->childs.find(s)->second.t=='f'){
return -1;
}else{
nowcata=&nowcata->childs.find(s)->second;
return 1;
}
}
bool CLcheck(string s,long long fs){
temcata=&temcata->childs.find(s)->second;
if(temcata->lr!=0&&temcata->lr<temcata->sr+fs){
return false;
}else{
return true;
}
}
void CC(string s){
file node;
node.t='c';
nowcata->childs.insert(pair<string,file>(s,node));
nowcata=&nowcata->childs.find(s)->second;
}
pair<int,long long> CFcheck(string f,long long fs){
pair<int,long long> re;
re.first=0;
re.second=fs;
if(nowcata->childs.find(f)!=nowcata->childs.end()){
file node;
node=nowcata->childs.find(f)->second;
if(node.t=='f'){
if((nowcata->lr!=0&&nowcata->lr<nowcata->sr+fs-node.s)||(nowcata->ld!=0&&nowcata->ld<nowcata->sd+fs-node.s)){
return re;
}else{
re.first=1;
re.second=fs-node.s;
return re;
}
}else{
return re;
}
}else if((nowcata->lr!=0&&nowcata->lr<nowcata->sr+fs)||(nowcata->ld!=0&&nowcata->ld<nowcata->sd+fs)){
re.first=0;
return re;
}else{
re.first=1;
return re;
}
}
void CF(string f,long long fs){
file node;
node.t='f';
node.s=fs;
nowcata->childs.insert(pair<string,file>(f,node));
nowcata->childs[f]=node;
}
pair<int ,long long> Copp(vector<string> fp,string f,long long fs){
nowcata=&root;
pair<int,long long> re;
re.first=0;
re.second=fs;
int flag=1,xfs=0;
vector<string>::iterator it=fp.begin();
vector<string>::iterator it2=fp.begin();
for(;it!=fp.end();it++){
flag=CCcheck(*it);
if(flag==-1){
re.first=0;
return re;
}else if(flag==0){
break;
}else{
;
}
}
if(flag==0){
temcata=&root;
for(;it2!=it;it2++){
if(CLcheck(*it2,fs)){
;
}else{
re.first=0;
return re;
}
}
for(;it!=fp.end();it++){
CC(*it);
}
re.second=fs;
re.first=1;
CF(f,fs);
return re;
}else{
re=CFcheck(f,fs);
if(re.first==0){
return re;
}else{
xfs=re.second;
if(xfs>0){
it=fp.begin();
temcata=&root;
for(;it!=fp.end();it++){
if(CLcheck(*it,xfs)){
;
}else{
re.first=0;
return re;
}
}
}
CF(f,fs);
return re;
}
}
}
void Cchange(vector<string> fp,long long fs){
nowcata=&root;
vector<string>::iterator it=fp.begin();
for(;it!=fp.end();it++){
nowcata=&nowcata->childs.find(*it)->second;
nowcata->sr+=fs;
nowcata->s+=fs;
}
nowcata->sd+=fs;
}
long long Cfunc(string ds){
long long fs=0;
pair<int , long long> flag;
cin>>fs;
vector<string> fp;
string f;
regex reg("/");
sregex_token_iterator pos(ds.cbegin(),ds.cend(),reg,-1);
sregex_token_iterator end;
for(;pos!=end;pos++){
fp.push_back(pos->str());
}
vector<string>::iterator it=fp.end();
it--;
f=*it;
fp.pop_back();
flag=Copp(fp,f,fs);
if(flag.first==0){
cout<<"N"<<endl;
}else{
Cchange(fp,flag.second);
cout<<"Y"<<endl;
}
return 0;
}
bool RCcheck(string s){
if(nowcata->childs.find(s)==nowcata->childs.end()){
return false;
}else if(nowcata->childs.find(s)->second.t=='f'){
return false;
}else{
nowcata=&nowcata->childs.find(s)->second;
return true;
}
}
long long RFcheck(string f){
long long fs=0;
if(nowcata->childs.find(f)==nowcata->childs.end()){
return -1;
}else if(nowcata->childs.find(f)->second.t=='f'){
fs=nowcata->childs.find(f)->second.s;
nowcata->sd-=fs;
nowcata->sr-=fs;
nowcata->s-=fs;
nowcata->childs.erase(nowcata->childs.find(f));
return fs;
}else{
fs=nowcata->childs.find(f)->second.s;
nowcata->sr-=fs;
nowcata->s-=fs;
nowcata->childs.erase(nowcata->childs.find(f));
return fs;
}
}
long long Ropp(vector<string> fp, string f){
long long fs;
nowcata=&root;
vector<string>::iterator it=fp.begin();
for(;it!=fp.end();it++){
if(RCcheck(*it)){
;
}else{
return -1;
}
}
fs=RFcheck(f);
return fs;
}
void Rchange(vector<string> fp,long long fs){
nowcata=&root;
vector<string>::iterator it=fp.begin();
vector<string>::iterator en=fp.end();
en--;
for(;it!=en;it++){
nowcata=&nowcata->childs.find(*it)->second;
nowcata->sr-=fs;
nowcata->s-=fs;
}
}
long long Rfunc(string ds){
long long fs=0;
vector<string> fp;
string f;
regex reg("/");
sregex_token_iterator pos(ds.cbegin(),ds.cend(),reg,-1);
sregex_token_iterator end;
for(;pos!=end;pos++){
fp.push_back(pos->str());
}
vector<string>::iterator it=fp.end();
it--;
f=*it;
fp.pop_back();
fs=Ropp(fp,f);
if(fs!=-1){
Rchange(fp,fs);
cout<<"Y"<<endl;
}else{
cout<<"Y"<<endl;
}
return 0;
}
bool QFcheck(long long nlr,long long nld){
if((nowcata->sr<=nlr||nlr==0)&&(nowcata->sd<=nld||nld==0)){
nowcata->lr=nlr;
nowcata->ld=nld;
return true;
}else{
return false;
}
}
bool Qopp(vector<string> fp,long long nlr,long nld){
nowcata=&root;
vector<string>::iterator it=fp.begin();
for(;it!=fp.end();it++){
if(RCcheck(*it)){
;
}else{
return false;
}
}
if(QFcheck(nlr,nld)){
return true;
}else{
return false;
}
}
long long Qfunc(string ds){
long long nlr,nld;
cin>>nld>>nlr;
vector<string> fp;
string f;
regex reg("/");
sregex_token_iterator pos(ds.cbegin(),ds.cend(),reg,-1);
sregex_token_iterator end;
for(;pos!=end;pos++){
fp.push_back(pos->str());
}
if(Qopp(fp,nlr,nld)){
cout<<"Y"<<endl;
}else{
cout<<"N"<<endl;
}
return 0;
}
long long opp(string o,string ds){
string d="root";
d.append(ds);
if(o=="C"){
Cfunc(d);
}else if(o=="R"){
Rfunc(d);
}else{
Qfunc(d);
}
return 0;
}
int main(){
int n;
string o,ds;
cin>>n;
file node;
node.t='c';
root.childs.insert(pair<string,file>("root",node));
for(int i=0;i<n;i++){
cin>>o>>ds;
opp(o,ds);
}
return 0;
}
这代码没什么改头了,随便看看吧,这代码我也不准备用了,直接删了准备重写,估计这这代码就是依靠某bug运行的,改不出来了,遇事不决删了重写。