제출 #971817

#제출 시각아이디문제언어결과실행 시간메모리
971817THXuanInspections (NOI23_inspections)C++14
29 / 100
2052 ms55120 KiB
#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; ll t[64 * MAXN], lazy[64 * MAXN], lf[64 * MAXN], rg[64 * MAXN], p[200005], visited[200005]; 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; } 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++) { for (int j = v[i].first; j <= v[i].second; j++) { if (visited[j] != 0) { ll val = get_dist(visited[j], i, j, j) - 2; //cout << "now: " << j << " " << 0 << " " << val << "\n"; upd(1, 0, val, 0, 1e12, 1); } visited[j] = i; } } while (q--) { 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 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...