Submission #1014093

# Submission time Handle Problem Language Result Execution time Memory
1014093 2024-07-04T10:39:52 Z Ariadna Curtains (NOI23_curtains) C++14
9 / 100
1500 ms 13512 KB
#include <bits/stdc++.h>

using namespace std;

struct Segtree {
    int n;
    vector<int> st, lz;

    Segtree(const int N) {
        n = N;
        st = vector<int>(4*n, 0);
        lz = vector<int>(4*n, 0);
    }

    void push(int p, int l, int r) {
        if (lz[p] == 0) return;
        if (l != r) {
            st[2*p] += lz[p];
            st[2*p+1] += lz[p];
            lz[2*p] += lz[p];
            lz[2*p+1] += lz[p];
        }
        lz[p] = 0;
    }

    void add(int p, int l, int r, int i, int j, int v) {
        if (i > j) return;
        push(p, l, r);
        if (l == i && r == j) {
            st[p] += v;
            lz[p] += v;
        } else {
            int m = (l+r)/2;
            add(2*p, l, m, i, min(m, j), v);
            add(2*p+1, m+1, r, max(m+1, i), j, v);
            st[p] = min(st[2*p], st[2*p+1]);
        }
    }

    int Min(int p, int l, int r, int i, int j) {
        if (i > j) return 1e9;
        push(p, l, r);
        if (l == i && r == j) return st[p];
        int m = (l+r)/2;
        return min(Min(2*p, l, m, i, min(m, j)), Min(2*p+1, m+1, r, max(i, m+1), j));
    }

    void add(int i, int j, int v) { add(1, 0, n-1, i, j, v); }
    int Min(int i, int j) { return Min(1, 0, n-1, i, j); }
};

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<pair<int, int>> curtains(m);
    for (int i = 0; i < m; ++i) {
        cin >> curtains[i].first >> curtains[i].second;
        --curtains[i].first; --curtains[i].second;
    }

    vector<pair<pair<int, int>, int>> queries(q);
    for (int i = 0; i < q; ++i) {
        cin >> queries[i].first.first >> queries[i].first.second;
        --queries[i].first.first; --queries[i].first.second;
        queries[i].second = i;
    }

    sort(curtains.begin(), curtains.end());
    sort(queries.begin(), queries.end());

    vector<bool> ans_query(q);
    Segtree Stage(n);

    int min_j = 0;
    unordered_set<int> used, up;
    for (int i = 0; i < q; ++i) {
        int l = queries[i].first.first, r = queries[i].first.second;

        for (int j: used) {
            if (curtains[j].first >= l && curtains[j].second <= r) continue;
            Stage.add(curtains[j].first, curtains[j].second, -1);
            up.insert(j);
        }

        for (int j: up) used.erase(j);
        up.clear();

        for (int j = min_j; j < m && curtains[j].first <= r; ++j) {
            if (curtains[j].first < l) {
                min_j = j+1;
                continue;
            }
            if (curtains[j].second <= r) {
                if (used.find(j) == used.end()) {
                    Stage.add(curtains[j].first, curtains[j].second, 1);
                    used.insert(j);
                }
            }
        }

        ans_query[queries[i].second] = (Stage.Min(l, r)>0);
    }

    for (int i = 0; i < q; ++i) {
        if (ans_query[i]) cout << "YES\n";
        else cout << "NO\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 161 ms 604 KB Output is correct
14 Correct 174 ms 604 KB Output is correct
15 Correct 169 ms 704 KB Output is correct
16 Correct 155 ms 600 KB Output is correct
17 Correct 11 ms 604 KB Output is correct
18 Correct 11 ms 604 KB Output is correct
19 Correct 11 ms 604 KB Output is correct
20 Correct 86 ms 604 KB Output is correct
21 Correct 102 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 161 ms 604 KB Output is correct
14 Correct 174 ms 604 KB Output is correct
15 Correct 169 ms 704 KB Output is correct
16 Correct 155 ms 600 KB Output is correct
17 Correct 11 ms 604 KB Output is correct
18 Correct 11 ms 604 KB Output is correct
19 Correct 11 ms 604 KB Output is correct
20 Correct 86 ms 604 KB Output is correct
21 Correct 102 ms 604 KB Output is correct
22 Correct 1269 ms 12140 KB Output is correct
23 Execution timed out 1544 ms 11600 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 11 ms 600 KB Output is correct
6 Correct 11 ms 604 KB Output is correct
7 Correct 11 ms 608 KB Output is correct
8 Execution timed out 1531 ms 9644 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 161 ms 604 KB Output is correct
14 Correct 174 ms 604 KB Output is correct
15 Correct 169 ms 704 KB Output is correct
16 Correct 155 ms 600 KB Output is correct
17 Correct 11 ms 604 KB Output is correct
18 Correct 11 ms 604 KB Output is correct
19 Correct 11 ms 604 KB Output is correct
20 Correct 86 ms 604 KB Output is correct
21 Correct 102 ms 604 KB Output is correct
22 Execution timed out 1556 ms 13512 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 161 ms 604 KB Output is correct
14 Correct 174 ms 604 KB Output is correct
15 Correct 169 ms 704 KB Output is correct
16 Correct 155 ms 600 KB Output is correct
17 Correct 11 ms 604 KB Output is correct
18 Correct 11 ms 604 KB Output is correct
19 Correct 11 ms 604 KB Output is correct
20 Correct 86 ms 604 KB Output is correct
21 Correct 102 ms 604 KB Output is correct
22 Correct 1269 ms 12140 KB Output is correct
23 Execution timed out 1544 ms 11600 KB Time limit exceeded
24 Halted 0 ms 0 KB -