#include <bits/stdc++.h>
#define ar array
#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
vector<pll> qus;
int bin_search(ll p) {
int l=0, r=qus.size()-1, ans=-1;
while(l <= r) {
int mid = (l + r) / 2;
if(qus[mid].first <= p) ans = mid, l = mid + 1;
else r = mid - 1;
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, m, q; cin >> n >> m >> q;
ll day = 1;
vector<int> L(m), R(m);
for(int i=0; i<m; i++) cin >> L[i] >> R[i];
for(int i=0; i<q; i++) {
ll x; cin >> x;
qus.push_back({ x, i });
}
sort(qus.begin(), qus.end());
vector<ll> ans(q);
set<array<ll, 3> > s;
for(int i=0; i<m; i++) {
vector<array<ll, 3> > to_rem, to_add;
// cout << i << ": " << '\n';
// for(auto &[l, r, x] : s) cout << l << " " << r << " " << x << '\n';
// cout << '\n';
//brute force prvo
for(auto &[l, r, x] : s) {
if(L[i] <= l && r <= R[i]) {
int p = bin_search(day + l - L[i] - x - 1);
if(p > -1) ans[p] += r - l + 1;
to_rem.push_back({ l, r, x });
} else if(l < L[i] && R[i] < r) {
int p = bin_search(day - (x + L[i] - l) - 1);
if(p > -1) ans[p] += R[i] - L[i] + 1;
to_rem.push_back({ l, r, x });
to_add.push_back({ l, L[i]-1, x });
to_add.push_back({ R[i]+1, r, R[i] + 1 - l + x});
} else if(l < L[i] && L[i] <= r && r <= R[i]) {
int p = bin_search(day - (x + L[i] - l) - 1);
if(p > -1) ans[p] += r - L[i] + 1;
to_rem.push_back({ l, r, x });
to_add.push_back({ l, L[i]-1, x });
} else if(L[i] <= l && l <= R[i] && R[i] < r) {
int p = bin_search(day + l - L[i] - x - 1);
if(p > -1) ans[p] += R[i] - l + 1;
to_rem.push_back({ l, r, x });
to_add.push_back({ R[i]+1, r, R[i] + 1 - l + x });
}
}
to_add.push_back({ L[i], R[i], day });
// cout << "REM" << '\n';
// for(auto &[l, r, x] : to_rem) cout << l << " " << r << " " << x << '\n';
// cout << '\n';
// cout << "ADD\n";
// for(auto &[l, r, x] : to_add) cout << l << " " << r << " " << x << '\n';
// cout << '\n';
for(auto &x : to_rem) s.erase(x);
for(auto &x : to_add) s.insert(x);
day += R[i] - L[i] + 1;
}
for(int i=q-2; i>=0; i--) ans[i] += ans[i+1];
for(int i=0; i<q; i++) qus[i].first = ans[i];
sort(qus.begin(), qus.end(), [&](pll a, pll b) { return a.second < b.second; });
for(auto x : qus) cout << x.first << " ";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
356 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
356 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
59 ms |
7068 KB |
Output is correct |
14 |
Correct |
51 ms |
6876 KB |
Output is correct |
15 |
Correct |
51 ms |
6844 KB |
Output is correct |
16 |
Correct |
61 ms |
7352 KB |
Output is correct |
17 |
Correct |
51 ms |
6844 KB |
Output is correct |
18 |
Correct |
52 ms |
7104 KB |
Output is correct |
19 |
Correct |
54 ms |
7096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
55 ms |
7016 KB |
Output is correct |
4 |
Correct |
54 ms |
7608 KB |
Output is correct |
5 |
Correct |
157 ms |
13040 KB |
Output is correct |
6 |
Correct |
127 ms |
12876 KB |
Output is correct |
7 |
Correct |
111 ms |
11712 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
356 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
59 ms |
7068 KB |
Output is correct |
14 |
Correct |
51 ms |
6876 KB |
Output is correct |
15 |
Correct |
51 ms |
6844 KB |
Output is correct |
16 |
Correct |
61 ms |
7352 KB |
Output is correct |
17 |
Correct |
51 ms |
6844 KB |
Output is correct |
18 |
Correct |
52 ms |
7104 KB |
Output is correct |
19 |
Correct |
54 ms |
7096 KB |
Output is correct |
20 |
Correct |
55 ms |
8108 KB |
Output is correct |
21 |
Correct |
53 ms |
7396 KB |
Output is correct |
22 |
Correct |
53 ms |
8124 KB |
Output is correct |
23 |
Correct |
74 ms |
7356 KB |
Output is correct |
24 |
Correct |
61 ms |
6924 KB |
Output is correct |
25 |
Correct |
53 ms |
7612 KB |
Output is correct |
26 |
Correct |
60 ms |
8196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
356 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
59 ms |
7068 KB |
Output is correct |
14 |
Correct |
51 ms |
6876 KB |
Output is correct |
15 |
Correct |
51 ms |
6844 KB |
Output is correct |
16 |
Correct |
61 ms |
7352 KB |
Output is correct |
17 |
Correct |
51 ms |
6844 KB |
Output is correct |
18 |
Correct |
52 ms |
7104 KB |
Output is correct |
19 |
Correct |
54 ms |
7096 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
55 ms |
7016 KB |
Output is correct |
23 |
Correct |
54 ms |
7608 KB |
Output is correct |
24 |
Correct |
157 ms |
13040 KB |
Output is correct |
25 |
Correct |
127 ms |
12876 KB |
Output is correct |
26 |
Correct |
111 ms |
11712 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
55 ms |
8108 KB |
Output is correct |
30 |
Correct |
53 ms |
7396 KB |
Output is correct |
31 |
Correct |
53 ms |
8124 KB |
Output is correct |
32 |
Correct |
74 ms |
7356 KB |
Output is correct |
33 |
Correct |
61 ms |
6924 KB |
Output is correct |
34 |
Correct |
53 ms |
7612 KB |
Output is correct |
35 |
Correct |
60 ms |
8196 KB |
Output is correct |
36 |
Correct |
277 ms |
13768 KB |
Output is correct |
37 |
Correct |
249 ms |
13904 KB |
Output is correct |
38 |
Correct |
205 ms |
13508 KB |
Output is correct |
39 |
Execution timed out |
2081 ms |
12188 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |