Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int lefts [];
- int rights [];
- public void solve () throws Exception {
- int n = nextInt();
- int k = nextInt();
- lefts = new int [n];
- rights = new int [n];
- for (int i = 0; i < n; i++) {
- lefts [i] = nextInt();
- rights [i] = nextInt();
- }
- int m = nextInt();
- int r [] = new int [k + 1];
- for (int i = 0; i < m; i++) {
- for (int j = 0; j <= k; j++) {
- r [j] = -1;
- }
- int ll = nextInt() - 1;
- int rr = nextInt() - 1;
- int ret = 0;
- for (int j = ll; j <= rr; j++) {
- r [lefts[j]] = max (r [lefts[j]], rights[j]);
- }
- int start = -1;
- int right = -1;
- for (int j = 0; j <= k; j++) {
- if (r[j] != -1) {
- start = j;
- right = r [j];
- break;
- }
- }
- for (int j = start + 1; j <= k; j++) {
- if (r[j] == -1) continue;
- if (j > right) {
- ret++;
- right = r [j];
- } else {
- right = max (right, r[j]);
- }
- }
- ret++;
- out.println((ret * 2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement