Submission #971316

# Submission time Handle Problem Language Result Execution time Memory
971316 2024-04-28T11:11:04 Z THXuan Inspections (NOI23_inspections) C++14
0 / 100
11 ms 26460 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define INF 1e9
using namespace std;
typedef long long ll;

const int MAXN = 123456, MAXNN = 2e5+ 1;
ll t[64 * MAXN], lazy[64 * MAXN], lf[64 * MAXN], rg[64 * MAXN], p[200005];
vector<ll>tt[4 * MAXNN];
vector<pair<ll,ll>>v(200005);
ll node_count = 1;

ll create_node() {
    node_count++;
    return node_count;
}

void pushdown(ll v, ll l, ll r) {
    ll tm = (l + r) / 2;
    if (lf[v] == 0) lf[v] = create_node();
    if (rg[v] == 0) rg[v] = create_node();
    if (lazy[v] > 0) {
        lazy[lf[v]] += lazy[v];
        lazy[rg[v]] += lazy[v];
        t[lf[v]] += lazy[v] * (tm - l + 1);
        t[rg[v]] += lazy[v] * (r - tm);
        lazy[v] = 0;
    }
}
void upd(ll v, ll l, ll r, ll tl, ll tr, ll val) {
    if (l > r)return;
    if (l == tl && r == tr) {
        lazy[v] += val;
        t[v] += val * 1LL * (r - l + 1);
        return;
    }
    pushdown(v, tl, tr);
    ll tm = (tl + tr) / 2;
    if (r <= tm) {
        if (lf[v] == 0) lf[v] = create_node();
        upd(lf[v], l, r, tl, tm, val);
    }
    else if (l >= tm + 1) {
        if (rg[v] == 0) rg[v] = create_node();
        upd(rg[v], l, r, tm + 1, tr, val);
    }
    else {
        if (lf[v] == 0) lf[v] = create_node();
        if (rg[v] == 0) rg[v] = create_node();
        upd(lf[v], l, tm, tl, tm, val);
        upd(rg[v], tm + 1, r, tm + 1, tr, val);
    }
    t[v] = t[lf[v]] + t[rg[v]] + lazy[v] * (tr - tl + 1);
}
ll query(ll v, ll tl, ll tr, ll l, ll r) {
    if (l > r)return 0;
    if (l == tl && r == tr)return t[v];
    pushdown(v, tl, tr);
    ll tm = (tl + tr) / 2;
    if (r <= tm)return query(lf[v], tl, tm, l, r);
    else if (l > tm)return query(rg[v], tm + 1, tr, l, r);
    else {
        ll left = query(lf[v], tl, tm, l, tm);
        ll right = query(rg[v], tm + 1, tr, tm + 1, r);
        return left + right;
    }
}

ll get_dist(ll block_a, ll block_b, ll a, ll b) {
    ll mid = 0;
    if (block_a != block_b) {
        mid = p[block_b - 1] - p[block_a];
    }
    ll ans = mid + (v[block_a].second - a) + 1 + (b - v[block_b].first) + 1;
    return ans;
}

// record the segment
/*
it doesn't need qeury
no need to push down if did operation on node
do operation if it contains 2 value on the node 
*/

void pushdown1(ll v, ll l, ll r) {
    if (tt[v].size() != 0) {
        if (tt[v * 2].size() == 0) tt[v * 2].push_back(tt[v].back());
        else {
            ll val = get_dist(tt[2 * v].back(), tt[v].back(), l, l);
            //cout << val << " " << l << "\n";
            upd(1, 0, val - 2, 0, 1e12, (r - l) + 1);
            tt[v * 2].pop_back();
            tt[v * 2].push_back(tt[v].back());
        }
        if (tt[v * 2 + 1].size() == 0) tt[v * 2 + 1].push_back(tt[v].back());
        else {
            ll val = get_dist(tt[2 * v + 1].back(), tt[v].back(), l, l);
            //cout << val << " " << l << "\n";
            upd(1, 0, val - 2, 0, 1e12, (r - l) + 1);
            tt[v * 2 + 1].pop_back();
            tt[v * 2 + 1].push_back(tt[v].back());
        }
        tt[v].pop_back();
    }
}

void update(ll v, ll l, ll r, ll tl, ll tr, ll val) {
    if (l == tl && r == tr) {
        if (tt[v].size() == 0) {
            tt[v].push_back(val);
            return;
        }
        else {
            ll value = get_dist(tt[v].back(), val, tl, tl);
            upd(1, 0, value - 2, 0, 1e12, (tr - tl) + 1);
            tt[v].pop_back();
            tt[v].push_back(val);
            return;
        }
    }
    pushdown1(v, tl, tr);
    ll mid = (tl + tr) / 2;
    if (r <= mid)update(2 * v, l, r, tl, mid, val);
    else if (l >= mid + 1)update(2 * v + 1, l, r, mid + 1, tr, val);
    else {
        update(2 * v, l, mid, tl, mid, val);
        update(2 * v + 1, mid + 1, r, mid + 1, tr, val);
    }
}

void solve()
{
	ll n, m, q; cin >> n >> m >> q;
	for (int i = 1; i <= m; i++) {
        cin >> v[i].first >> v[i].second;
        p[i] = p[i - 1] + (v[i].second - v[i].first) + 1;
	}
    for (int i = 1; i <= m; i++) {
        update(1, v[i].first, v[i].second, 1, n, i);
    }
    /*upd(1, 0, 1e12, 0, 1e12, 1);
    cout << query(1, 0, 1e12, 0, 1e12) << '\n';*/
    for (int i = 1; i <= q; i++) {
        ll ask; cin >> ask;
        cout << query(1, 0, 1e12, ask, ask) << " ";
    }
    
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;// cin>>t;
	while (t--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 26204 KB Output is correct
2 Correct 7 ms 26204 KB Output is correct
3 Incorrect 7 ms 26204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 26204 KB Output is correct
2 Correct 7 ms 26204 KB Output is correct
3 Incorrect 7 ms 26204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 26356 KB Output is correct
2 Incorrect 10 ms 26460 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 26204 KB Output is correct
2 Correct 7 ms 26204 KB Output is correct
3 Incorrect 7 ms 26204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 26204 KB Output is correct
2 Correct 7 ms 26204 KB Output is correct
3 Incorrect 7 ms 26204 KB Output isn't correct
4 Halted 0 ms 0 KB -