답안 #866778

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866778 2023-10-27T03:56:42 Z sleepntsheep Osumnjičeni (COCI21_osumnjiceni) C++17
0 / 110
1000 ms 11220 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>

using namespace std;
#define ALL(x) x.begin(), x.end()
using ll = long long;
#define N 200005

int n, q, t[N<<2], lz[N<<2];
pair<int, int> a[N];

void push(int v, int l, int r)
{
    if (lz[v])
    {
        t[v] += lz[v];
        if (l != r)
        {
            int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
            lz[vl]+=lz[v],lz[vr]+=lz[v];
        }
        lz[v] = 0;
    }
}

void update(int v, int l, int r, int x, int y, int k)
{
    push(v, l, r);
    if (r < x || y < l) return;
    if (x <= l && r <= y) { lz[v] += k; push(v, l, r); return; }
    int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
    update(vl, l, m, x, y, k), update(vr, m+1, r, x, y, k);
    t[v] = max(t[vl], t[vr]);
}

void update(int x, int y, int k) { update(0, 0, 2*n, x, y, k); }

void compress()
{
    vector<int> C;
    C.reserve(2*n);
    for (int i = 0; i < n; ++i) C.push_back(a[i].first), C.push_back(a[i].second);
    sort(ALL(C));
    for (int i = 0; i < n; ++i) a[i].first = lower_bound(ALL(C), a[i].first) - C.begin(),
        a[i].second = lower_bound(ALL(C), a[i].second) - C.begin();
}

struct qry
{
    int l, r, i;
    bool operator<(const qry &o)
    {
        if (l/400 != o.l/400) return l<o.l;
        if (r!=o.r) return r>o.r;
        return i<o.i;
    }
} b[N];
int ans[N];

int main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
    compress();
    cin >> q;
    for (int i = 0; i < q; ++i) cin >> b[i].l >> b[i].r, --b[i].l, --b[i].r, b[i].i = i;
    sort(b, b+q);
    int l = b[0].l, r = b[0].l-1;
    for (int i = 0; i < q; ++i)
    {
        auto [L, R, j] = b[i];
        while (l < L) update(a[l].first, a[l].second, -1), ++l;
        while (r > R) update(a[r].first, a[r].second, -1), --r;
        while (l > L) --l, update(a[l].first, a[l].second, 1);
        while (r < R) ++r, update(a[r].first, a[r].second, 1);
        push(0, 0, 2*n);
        ans[j] = t[0];
    }
    for (int i = 0; i < q; ++i) cout << ans[i] << '\n';
    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Incorrect 221 ms 11188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 276 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 276 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1022 ms 11220 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 221 ms 11188 KB Output isn't correct
2 Halted 0 ms 0 KB -