제출 #1327377

#제출 시각아이디문제언어결과실행 시간메모리
1327377retardeInspections (NOI23_inspections)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(), (x).end()

typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;

const int mod = 1e9 + 7;
const int inf = INTMAX_MAX;
const bool tc = false;

struct SparseSegtree {
    struct Node {
        int sum = 0;
        int lazy = 0;
        Node* l = nullptr;
        Node* r = nullptr;
    };

    const int LO = 0;
    const int HI = (int)1e12 + 10;

    Node* root;

    SparseSegtree() { root = new Node(); }

    inline void apply(Node* n, int s, int e, int add) {
        n->sum += add * (e - s + 1);
        n->lazy += add;
    }

    inline void push(Node* n, int s, int e) {
        if (!n || n->lazy == 0 || s == e) return;
        int m = (s + e) >> 1;

        if (!n->l) n->l = new Node();
        if (!n->r) n->r = new Node();

        apply(n->l, s, m, n->lazy);
        apply(n->r, m + 1, e, n->lazy);
        n->lazy = 0;
    }

    void range_add(Node* n, int s, int e, int l, int r, int val) {
        if (!n || r < s || e < l) return;

        if (l <= s && e <= r) {
            apply(n, s, e, val);
            return;
        }

        push(n, s, e);
        int m = (s + e) >> 1;

        if (!n->l) n->l = new Node();
        if (!n->r) n->r = new Node();

        range_add(n->l, s, m, l, r, val);
        range_add(n->r, m + 1, e, l, r, val);

        n->sum = (n->l ? n->l->sum : 0) + (n->r ? n->r->sum : 0);
    }

    int range_sum(Node* n, int s, int e, int l, int r) {
        if (!n || r < s || e < l) return 0;

        if (l <= s && e <= r) return n->sum;

        push(n, s, e);
        int m = (s + e) >> 1;

        return range_sum(n->l, s, m, l, r)
             + range_sum(n->r, m + 1, e, l, r);
    }

    inline void add(int l, int r, int val) {
        if (l > r) return;
        l = max(l, LO);
        r = min(r, HI);
        if (l > r) return;
        range_add(root, LO, HI, l, r, val);
    }

    inline int sum(int l, int r) {
        if (l > r) return 0;
        l = max(l, LO);
        r = min(r, HI);
        if (l > r) return 0;
        return range_sum(root, LO, HI, l, r);
    }
};

struct Segtree {
    int n, sz, H;
    vector<int> sum, lazy, cnt;
    vector<char> has;

    Segtree(int _n) : n(_n) {
        sz = 1;
        while (sz < n) sz <<= 1;
        H = 0;
        while ((1LL << H) < sz) H++;

        sum.assign(2 * sz, 0);
        lazy.assign(2 * sz, 0);
        has.assign(2 * sz, 0);
        cnt.assign(2 * sz, 0);

        for (int i = 0; i < sz; i++) {
            int real = (i < n);
            cnt[sz + i] = real;
            sum[sz + i] = real ? 1 : 0;
        }
        for (int i = sz - 1; i >= 1; i--) {
            cnt[i] = cnt[i << 1] + cnt[i << 1 | 1];
            sum[i] = sum[i << 1] + sum[i << 1 | 1];
        }
    }

    inline void apply(int p, int v) {
        sum[p] = v * cnt[p];
        lazy[p] = v;
        has[p] = 1;
    }

    inline void push(int p) {
        if (!has[p] || p >= sz) return;
        apply(p << 1, lazy[p]);
        apply(p << 1 | 1, lazy[p]);
        has[p] = 0;
    }

    inline void pull(int p) {
        sum[p] = sum[p << 1] + sum[p << 1 | 1];
    }

    inline void push_path(int p) {
        for (int h = H; h >= 1; h--) push(p >> h);
    }

    inline void pull_path(int p) {
        for (int h = 1; h <= H; h++) pull(p >> h);
    }

    void range_set(int l, int r, int v) {
        if (l > r) return;
        l = max<int>(l, 0);
        r = min<int>(r, n - 1);
        if (l > r) return;

        int L = l + sz;
        int R = r + sz + 1;

        push_path(L);
        push_path(R - 1);

        int l0 = L, r0 = R;

        while (L < R) {
            if (L & 1) apply(L++, v);
            if (R & 1) apply(--R, v);
            L >>= 1;
            R >>= 1;
        }

        pull_path(l0);
        pull_path(r0 - 1);
    }

    int range_sum(int l, int r) {
        if (l > r) return 0;
        l = max<int>(l, 0);
        r = min<int>(r, n - 1);
        if (l > r) return 0;

        int L = l + sz;
        int R = r + sz + 1;

        push_path(L);
        push_path(R - 1);

        int res = 0;
        while (L < R) {
            if (L & 1) res += sum[L++];
            if (R & 1) res += sum[--R];
            L >>= 1;
            R >>= 1;
        }
        return res;
    }

    int range_sum(pii q) {
        return range_sum(q.fi, q.se);
    }
};

inline void solve() {
    int n, m, q; cin >> n >> m >> q;
    vector<pii> pairs(m); for (int i = 0; i < m; i++) {
        cin >> pairs[i].fi >> pairs[i].se;
        pairs[i].fi--; pairs[i].se--;
    }

    SparseSegtree sparse;
    Segtree uni(n);
    for (int r = m - 1; r >= 0; r--) {
        uni.range_set(0, n - 1, 0);
        uni.range_set(pairs[r].fi, pairs[r].se, 1);
        int gapsum = 0;
        for (int l = r - 1; l >= 0; l--) {
            int intersection = uni.range_sum(pairs[l]);
            int bonus = pairs[l].se - pairs[r].fi;

            // cout << l + 1 << '\n';
            // cout << pairs[l].fi + 1 << " " << pairs[l].se + 1 << '\n';
            // cout << r + 1 << '\n';
            // cout << pairs[r].fi + 1 << " " << pairs[r].se + 1 << '\n';

            // add intersection at (gapsum + bonus)
            sparse.add(gapsum + bonus, gapsum + bonus, intersection);
            gapsum += pairs[l].se - pairs[l].fi + 1;
            uni.range_set(pairs[l].fi, pairs[l].se, 0);
            // cout << '\n';
        }
    }
    
    int tot = sparse.sum(0, 1e12 + 4);

    while (q--) {
        int x; cin >> x;
        cout << tot - sparse.sum(0, x - 1) << ' ';
    }
    cout << '\n';
}

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

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

    int t = 1;
    if (tc) {
        cin >> t;
    }

    while (t--) {
        solve();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:258:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  258 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:259:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  259 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...