#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define pii pair<int, int>
#define ppi pair<pii, int>
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define f first
#define s second
#define pb push_back
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
const ll maxn = 1e6+5;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;
int n, m, q;
vector<pii> tag(3*maxn); // lazy tag to modify suffix
multiset<ppi> st;
int tagptr = 0;
multiset<ppi> ::iterator rep(multiset<ppi> ::iterator it, int L, int R, int v){
ppi cur = (*it);
int l = cur.f.f;
int r = cur.f.s;
//cout<<l<<' '<<r<<' '<<L<<' '<<R<<' '<<cur.s<<' '<<v<<endl;
if (r < L || l > R) return next(it);
if (l < L && r > R){
tag[tagptr++] = {v-(cur.s+L-l)-1, R-L+1};
st.insert({{l, L-1}, cur.s});
st.insert({{R+1, r}, cur.s+R+1-l});
return st.erase(it);
}
if (l < L){
//cout<<"toad"<<endl;
tag[tagptr++] = {v-(cur.s+L-l)-1, r-L+1};
st.insert({{l, L-1}, cur.s});
return st.erase(it);
}
if (r > R){
tag[tagptr++] = {v-(cur.s-(l-L))-1, R-l+1};
st.insert({{R+1, r}, cur.s+R+1-l});
return st.erase(it);
}
tag[tagptr++] = {v-(cur.s-(l-L))-1, r-l+1};
return st.erase(it);
}
signed main(){
IOS();
cin>>n>>m>>q;
int cval = 0;
REP(i, m){
int L, R; cin>>L>>R;
if (SZ(st) > 0){
auto tt = st.lower_bound({{L+1, 0}, 0});
if (tt != st.begin()){
tt = prev(tt);
}
while(tt != st.end() && (*tt).f.f <= R){
tt = rep(tt, L, R, cval);
}
}
st.insert({{L, R}, cval});
cval += R-L+1;
}
sort(tag.begin(), tag.begin()+tagptr, greater<pii> ());
vector<pii> quer(q);
REP(i, q){
cin>>quer[i].f;
quer[i].s = i;
}
vector<int> ans(q);
sort(ALL(quer), greater<pii> ());
int ptr = 0, woo = 0;
REP(i, q){
while(ptr < tagptr && tag[ptr].f >= quer[i].f){
woo += tag[ptr].s;
ptr++;
}
ans[quer[i].s] = woo;
}
REP(i, q) cout<<ans[i]<<' ';
cout<<endl;
}
/*
5 3 7
1 3
3 5
2 3
bruh 4 minutes debug
stop copy and pasting code!
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
47192 KB |
Output is correct |
2 |
Correct |
7 ms |
47196 KB |
Output is correct |
3 |
Correct |
7 ms |
47196 KB |
Output is correct |
4 |
Correct |
8 ms |
47196 KB |
Output is correct |
5 |
Correct |
9 ms |
47248 KB |
Output is correct |
6 |
Correct |
9 ms |
47196 KB |
Output is correct |
7 |
Correct |
9 ms |
47196 KB |
Output is correct |
8 |
Correct |
8 ms |
47196 KB |
Output is correct |
9 |
Correct |
8 ms |
47196 KB |
Output is correct |
10 |
Correct |
10 ms |
47212 KB |
Output is correct |
11 |
Correct |
8 ms |
47196 KB |
Output is correct |
12 |
Correct |
8 ms |
47204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
47192 KB |
Output is correct |
2 |
Correct |
7 ms |
47196 KB |
Output is correct |
3 |
Correct |
7 ms |
47196 KB |
Output is correct |
4 |
Correct |
8 ms |
47196 KB |
Output is correct |
5 |
Correct |
9 ms |
47248 KB |
Output is correct |
6 |
Correct |
9 ms |
47196 KB |
Output is correct |
7 |
Correct |
9 ms |
47196 KB |
Output is correct |
8 |
Correct |
8 ms |
47196 KB |
Output is correct |
9 |
Correct |
8 ms |
47196 KB |
Output is correct |
10 |
Correct |
10 ms |
47212 KB |
Output is correct |
11 |
Correct |
8 ms |
47196 KB |
Output is correct |
12 |
Correct |
8 ms |
47204 KB |
Output is correct |
13 |
Correct |
49 ms |
52348 KB |
Output is correct |
14 |
Correct |
45 ms |
52308 KB |
Output is correct |
15 |
Correct |
47 ms |
52308 KB |
Output is correct |
16 |
Correct |
49 ms |
52732 KB |
Output is correct |
17 |
Correct |
47 ms |
52488 KB |
Output is correct |
18 |
Correct |
47 ms |
52560 KB |
Output is correct |
19 |
Correct |
50 ms |
53224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
47196 KB |
Output is correct |
2 |
Correct |
9 ms |
47312 KB |
Output is correct |
3 |
Correct |
48 ms |
52360 KB |
Output is correct |
4 |
Correct |
51 ms |
52560 KB |
Output is correct |
5 |
Correct |
133 ms |
53844 KB |
Output is correct |
6 |
Correct |
129 ms |
52304 KB |
Output is correct |
7 |
Correct |
102 ms |
54328 KB |
Output is correct |
8 |
Correct |
8 ms |
47192 KB |
Output is correct |
9 |
Correct |
7 ms |
47196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
47192 KB |
Output is correct |
2 |
Correct |
7 ms |
47196 KB |
Output is correct |
3 |
Correct |
7 ms |
47196 KB |
Output is correct |
4 |
Correct |
8 ms |
47196 KB |
Output is correct |
5 |
Correct |
9 ms |
47248 KB |
Output is correct |
6 |
Correct |
9 ms |
47196 KB |
Output is correct |
7 |
Correct |
9 ms |
47196 KB |
Output is correct |
8 |
Correct |
8 ms |
47196 KB |
Output is correct |
9 |
Correct |
8 ms |
47196 KB |
Output is correct |
10 |
Correct |
10 ms |
47212 KB |
Output is correct |
11 |
Correct |
8 ms |
47196 KB |
Output is correct |
12 |
Correct |
8 ms |
47204 KB |
Output is correct |
13 |
Correct |
49 ms |
52348 KB |
Output is correct |
14 |
Correct |
45 ms |
52308 KB |
Output is correct |
15 |
Correct |
47 ms |
52308 KB |
Output is correct |
16 |
Correct |
49 ms |
52732 KB |
Output is correct |
17 |
Correct |
47 ms |
52488 KB |
Output is correct |
18 |
Correct |
47 ms |
52560 KB |
Output is correct |
19 |
Correct |
50 ms |
53224 KB |
Output is correct |
20 |
Correct |
49 ms |
53588 KB |
Output is correct |
21 |
Correct |
48 ms |
53076 KB |
Output is correct |
22 |
Correct |
48 ms |
53764 KB |
Output is correct |
23 |
Correct |
48 ms |
53072 KB |
Output is correct |
24 |
Correct |
47 ms |
52564 KB |
Output is correct |
25 |
Correct |
50 ms |
52816 KB |
Output is correct |
26 |
Correct |
50 ms |
53840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
47192 KB |
Output is correct |
2 |
Correct |
7 ms |
47196 KB |
Output is correct |
3 |
Correct |
7 ms |
47196 KB |
Output is correct |
4 |
Correct |
8 ms |
47196 KB |
Output is correct |
5 |
Correct |
9 ms |
47248 KB |
Output is correct |
6 |
Correct |
9 ms |
47196 KB |
Output is correct |
7 |
Correct |
9 ms |
47196 KB |
Output is correct |
8 |
Correct |
8 ms |
47196 KB |
Output is correct |
9 |
Correct |
8 ms |
47196 KB |
Output is correct |
10 |
Correct |
10 ms |
47212 KB |
Output is correct |
11 |
Correct |
8 ms |
47196 KB |
Output is correct |
12 |
Correct |
8 ms |
47204 KB |
Output is correct |
13 |
Correct |
49 ms |
52348 KB |
Output is correct |
14 |
Correct |
45 ms |
52308 KB |
Output is correct |
15 |
Correct |
47 ms |
52308 KB |
Output is correct |
16 |
Correct |
49 ms |
52732 KB |
Output is correct |
17 |
Correct |
47 ms |
52488 KB |
Output is correct |
18 |
Correct |
47 ms |
52560 KB |
Output is correct |
19 |
Correct |
50 ms |
53224 KB |
Output is correct |
20 |
Correct |
8 ms |
47196 KB |
Output is correct |
21 |
Correct |
9 ms |
47312 KB |
Output is correct |
22 |
Correct |
48 ms |
52360 KB |
Output is correct |
23 |
Correct |
51 ms |
52560 KB |
Output is correct |
24 |
Correct |
133 ms |
53844 KB |
Output is correct |
25 |
Correct |
129 ms |
52304 KB |
Output is correct |
26 |
Correct |
102 ms |
54328 KB |
Output is correct |
27 |
Correct |
8 ms |
47192 KB |
Output is correct |
28 |
Correct |
7 ms |
47196 KB |
Output is correct |
29 |
Correct |
49 ms |
53588 KB |
Output is correct |
30 |
Correct |
48 ms |
53076 KB |
Output is correct |
31 |
Correct |
48 ms |
53764 KB |
Output is correct |
32 |
Correct |
48 ms |
53072 KB |
Output is correct |
33 |
Correct |
47 ms |
52564 KB |
Output is correct |
34 |
Correct |
50 ms |
52816 KB |
Output is correct |
35 |
Correct |
50 ms |
53840 KB |
Output is correct |
36 |
Correct |
181 ms |
54096 KB |
Output is correct |
37 |
Correct |
185 ms |
53844 KB |
Output is correct |
38 |
Correct |
187 ms |
52304 KB |
Output is correct |
39 |
Correct |
132 ms |
53332 KB |
Output is correct |
40 |
Correct |
208 ms |
52564 KB |
Output is correct |
41 |
Correct |
228 ms |
57680 KB |
Output is correct |
42 |
Correct |
222 ms |
58520 KB |
Output is correct |
43 |
Correct |
250 ms |
65904 KB |
Output is correct |
44 |
Correct |
250 ms |
64796 KB |
Output is correct |
45 |
Correct |
199 ms |
52816 KB |
Output is correct |
46 |
Correct |
233 ms |
55120 KB |
Output is correct |
47 |
Correct |
235 ms |
54292 KB |
Output is correct |
48 |
Correct |
178 ms |
53304 KB |
Output is correct |