提出 #74114462


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int N = 8e5 + 5;
int n, cnt, cntt, ans, tmp[N * 2];
struct SQ {
    int x, y, xx, yy;
} a[N];
struct Seg {
    int l, r, x, val;
    bool operator<(const Seg &o) const {
        return x < o.x;
    }
} b[N * 2];
struct ST {
#define left now * 2
#define right now * 2 + 1
    int sum[8 * N], cnt[8 * N];
    inline void push_up(int now, int l, int r) {
        if (cnt[now])
            sum[now] = tmp[r + 1] - tmp[l];
        else if (l == r)
            sum[now] = 0;
        else
            sum[now] = sum[left] + sum[right];
    }
    inline void update(int now, int l, int r, int x, int y, int val) {
        //	cout << l << ' ' << r << endl;
        if (x <= l && r <= y) {
            cnt[now] += val;
            push_up(now, l, r);
            return;
        }
        int mid = (l + r) / 2;
        if (x <= mid)
            update(left, l, mid, x, y, val);
        if (y > mid)
            update(right, mid + 1, r, x, y, val);
        push_up(now, l, r);
    }
} st;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int H, W, h, w, n;
    cin >> H >> W >> h >> w >> n;

    int tot = (H - h + 1) * (W - w + 1);

    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        a[i].x = max(1LL, x - h + 1);
        a[i].y = max(1LL, y - w + 1);
        a[i].xx = min(H - h + 1, x);
        a[i].yy = min(W - w + 1, y);
        tmp[++cnt] = a[i].y, tmp[++cnt] = a[i].yy + 1;
    }
    sort(tmp + 1, tmp + cnt + 1);
    cnt = unique(tmp + 1, tmp + cnt + 1) - tmp - 1;
    for (int i = 1; i <= n; i++) {
        a[i].y = lower_bound(tmp + 1, tmp + cnt + 1, a[i].y) - tmp;
        a[i].yy = lower_bound(tmp + 1, tmp + cnt + 1, a[i].yy + 1) - tmp;
        b[++cntt] = Seg{a[i].y, a[i].yy, a[i].x, 1};
        b[++cntt] = Seg{a[i].y, a[i].yy, a[i].xx + 1, -1};
    }
    int nn = 2 * n;
    sort(b + 1, b + nn + 1);
    for (int i = 1; i <= nn; i++) {
        if (i > 1)
            ans += st.sum[1] * (b[i].x - b[i - 1].x);
        st.update(1, 1, cnt, b[i].l, b[i].r - 1, b[i].val);
    }
    cout << tot - ans << endl;
}

提出情報

提出日時
問題 F - Grid Clipping
ユーザ NoobDidi
言語 C++23 (GCC 15.2.0)
得点 500
コード長 2240 Byte
結果 AC
実行時間 240 ms
メモリ 41852 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 4
AC × 28
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3728 KiB
00_sample_01.txt AC 1 ms 3684 KiB
00_sample_02.txt AC 1 ms 3560 KiB
00_sample_03.txt AC 1 ms 3444 KiB
01_handmade_00.txt AC 76 ms 25376 KiB
01_handmade_01.txt AC 28 ms 25556 KiB
01_handmade_02.txt AC 1 ms 3488 KiB
01_handmade_03.txt AC 1 ms 3580 KiB
01_handmade_04.txt AC 1 ms 3604 KiB
02_random_00.txt AC 213 ms 41364 KiB
02_random_01.txt AC 48 ms 25368 KiB
02_random_02.txt AC 207 ms 41320 KiB
02_random_03.txt AC 48 ms 25492 KiB
02_random_04.txt AC 232 ms 41708 KiB
02_random_05.txt AC 232 ms 41676 KiB
02_random_06.txt AC 229 ms 41656 KiB
02_random_07.txt AC 228 ms 41624 KiB
02_random_08.txt AC 232 ms 41704 KiB
02_random_09.txt AC 230 ms 41604 KiB
02_random_10.txt AC 229 ms 41644 KiB
02_random_11.txt AC 228 ms 41692 KiB
02_random_12.txt AC 238 ms 41624 KiB
02_random_13.txt AC 240 ms 41852 KiB
02_random_14.txt AC 210 ms 40892 KiB
02_random_15.txt AC 216 ms 41320 KiB
02_random_16.txt AC 209 ms 40848 KiB
02_random_17.txt AC 210 ms 40808 KiB
02_random_18.txt AC 211 ms 40924 KiB