CCCPaste

286a398887bfe

class RangeModule {

    TreeMap map;
    public RangeModule() {
        map = new TreeMap<>();
    }
    
    public void addRange(int left, int right) {
        var l = map.floorEntry(left);
        var r = map.floorEntry(right);

        if(l!=null && l.getValue()>=left) left=l.getKey();
        if(r!=null && r.getValue()>right) right=r.getValue();

        map.subMap(left,right).clear();
        map.put(left,right);
    }
    
    public boolean queryRange(int left, int right) {
        var l=map.floorEntry(left);
        return l!=null && l.getValue()>=right;
    }
    
    public void removeRange(int left, int right) {
        var l = map.floorEntry(left); 
        var r = map.floorEntry(right); 

        if (l != null && l.getValue() > left) map.put(l.getKey(), left); 
        if (r != null && r.getValue() > right) map.put(right, r.getValue()); 

        map.subMap(left, right).clear();
    }
}

/**
 * Your RangeModule object will be instantiated and called as such:
 * RangeModule obj = new RangeModule();
 * obj.addRange(left,right);
 * boolean param_2 = obj.queryRange(left,right);
 * obj.removeRange(left,right);
 */