#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair <int, int>
#define fi first
#define se second
#define mp make_pair
const int NM = 2e5;
int n, m, q;
vector <int> upd_add[NM+5], upd_rmv[NM+5];
multiset <int> S;
pii qry[NM+5];
int A[NM+5], D[NM+5], cur[NM+5];
vector <int> record;
int ans[NM+5];
void update(int x, int val){
x--;
if (x < qry[1].fi) return;
int lo = 2, hi = q, res = 1;
while (lo <= hi){
int mid = (lo+hi)/2;
if (qry[mid].fi <= x){
res = mid;
lo = mid+1;
}
else hi = mid-1;
}
record.push_back(res);
cur[res] += val;
}
void add(int val){
S.insert(val);
set <int>::iterator x = S.end(), y = S.find(val), z = S.end();
if (y != S.begin()) x = y, x--;
if (y != (--S.end())) z = y, z++;
if (x != S.end()) update(val - (*x), 1);
if (z != S.end()) update((*z) - val, 1);
if (x != S.end() && z != S.end()) update((*z) - (*x), -1);
}
void remove(int val){
set <int>::iterator x = S.end(), y = S.find(val), z = S.end();
if (y != S.begin()) x = y, x--;
if (y != (--S.end())) z = y, z++;
if (x != S.end()) update(val - (*x), -1);
if (z != S.end()) update((*z) - val, -1);
if (x != S.end() && z != S.end()) update((*z) - (*x), 1);
S.erase(val);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> q;
int cnt = 0;
for (int i = 1; i <= m; i++){
int l, r; cin >> l >> r;
upd_add[l].push_back(cnt-l);
upd_rmv[r+1].push_back(cnt-l);
cnt += r-l+1;
}
for (int i = 1; i <= q; i++){
cin >> qry[i].fi;
qry[i].se = i;
}
sort(qry+1, qry+1+q);
for (int t = 1; t <= n; t++){
record.clear();
for (int val : upd_add[t]) add(val);
for (int val : upd_rmv[t]) remove(val);
for (int p : record){
if (cur[p] == 0) continue;
A[p] += cur[p];
D[p] -= (t-1)*cur[p];
cur[p] = 0;
}
}
for (int i = q; i >= 1; i--){
A[i] = n*A[i]+D[i];
A[i] += A[i+1];
ans[qry[i].se] = A[i];
}
for (int i = 1; i <= q; i++) cout << ans[i] << ' ';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |