Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
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); */
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)