import java.util.HashMap; import java.util.Scanner; /** * Created by gzd on 2016/9/10. */ public class Test360R2 { public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNextLine()){ int op = in.nextInt(); int maxMen = in.nextInt(); String[] str = new String[op]; String abc = in.nextLine(); for(int i = 0; i < op; ++i){ str[i] = in.nextLine(); } result(maxMen,str); } } public static void result(int max,String[] str){ int[] count = new int[max]; int hhh = 1; HashMap<Integer,int[]> map3 = new HashMap<>(); HashMap<Integer,Integer> map2 = new HashMap<>(); for(int i = 0; i < str.length; ++i){ String[] single = str[i].split(" "); if(single[0].equals("new")){ int newSize = Integer.parseInt(single[1]); int maxLen = 0; int mflag = 0; for(int m = 0;m < max; ++m){ if(count[m] == 1){ maxLen = 0; mflag = m+1; }else if(count[m] == 0){ maxLen++; } if(maxLen >= newSize){ for(int k = 0;k < maxLen;k++){ count[mflag + k] = 1; } int[] o = new int[2]; o[0] = mflag; o[1] = mflag+maxLen; map3.put(hhh,o); System.out.println(hhh); hhh++; break; } } if(maxLen < newSize) System.out.println("NULL"); }else if(single[0].equals("del")){ int handle = Integer.parseInt(single[1]); int[] o = map3.get(handle); if(o == null){ System.out.println("ILLEGAL_OPERATION"); }else{ for(int p = o[0];p < o[1];p++){ count[p] = 0; } } }else if(single[0].equals("def")){ int mark = 0; for(int u = 0;u < max; ++u){ if(count[u] == 1){ count[mark] = count[u]; count[u] = 0; mark++; } } } } } }
点赞 2

相关推荐

七牛云头号黑子:人家是过度包装被看出来没过简历,你是包都不包啊兄弟
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务