#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<ll,ll>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxn=3e5+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll s[maxn];
pli t[maxn];
ll q;
ll pre[maxn];
void update(ll x,ll v)
{
//x++;
ll cc=upper_bound(s+1,s+q+1,x)-s-1;
pre[cc]+=v;
}
ll giao(ll i,ll j,ll l,ll r)
{
return max(0ll,min(j,r)-max(i,l)+1);
}
ll n,m,x[maxn],y[maxn],r[maxn],tg[maxn],pos[maxn];
void solve()
{
cin >> n >> m >> q;
for(int i=1;i<=m;i++)
{
cin >> x[i] >> y[i];
}
for(int i=1;i<=q;i++)
{
cin >> s[i];
t[i]={s[i],i};
}
sort(s+1,s+q+1);
sort(t+1,t+q+1);
set<ll>s;
ll sum=0;
for(int i=1;i<=m;i++)
{
auto it=s.lower_bound(x[i]);
vector<ll>xoa;
if(i>0) sum+=y[i-1]-x[i-1]+1;
if(it!=s.begin())
{
it--;
ll l=*it;
if(r[l]>=x[i])
{
ll cc=sum - (tg[l]+x[i]-l) -1;
update(cc,giao(x[i],y[i],l,r[l]));
ll luu=r[l];
r[l]=x[i]-1;
if(luu>y[i])
{
s.insert(y[i]+1);
s.insert(x[i]);
r[x[i]]=y[i];
tg[x[i]]=sum;
r[y[i]+1]=luu;
tg[y[i]+1]=tg[l]+(y[i]+1-l);
continue;
}
}
it++;
}
while(it!=s.end()&&(*it)<=y[i])
{
ll l=*it;
ll cc=sum+l-x[i]-tg[l]-1;
update(cc,giao(l,r[l],x[i],y[i]));
xoa.pb(l);
if(r[l]>y[i])
{
s.insert(y[i]+1);
r[y[i]+1]=r[l];
tg[y[i]+1]=tg[l]+(y[i]+1-l);
break;
}
it++;
}
r[x[i]]=y[i];
tg[x[i]]=sum;
for(auto zz:xoa) s.erase(zz);
s.insert(x[i]);
}
for(int i=q;i>=1;i--)
{
pre[i]+=pre[i+1];
pos[t[i].se]=i;
}
for(int i=1;i<=q;i++)
{
cout << pre[pos[i]]<<' ';
}
}
int main()
{
fastio
//freopen("c.INP","r",stdin);
//freopen("c.OUT","w",stdout);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14684 KB |
Output is correct |
4 |
Correct |
2 ms |
14684 KB |
Output is correct |
5 |
Correct |
2 ms |
14812 KB |
Output is correct |
6 |
Correct |
2 ms |
14684 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
2 ms |
14684 KB |
Output is correct |
9 |
Correct |
2 ms |
14684 KB |
Output is correct |
10 |
Correct |
2 ms |
14684 KB |
Output is correct |
11 |
Correct |
2 ms |
14684 KB |
Output is correct |
12 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14684 KB |
Output is correct |
4 |
Correct |
2 ms |
14684 KB |
Output is correct |
5 |
Correct |
2 ms |
14812 KB |
Output is correct |
6 |
Correct |
2 ms |
14684 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
2 ms |
14684 KB |
Output is correct |
9 |
Correct |
2 ms |
14684 KB |
Output is correct |
10 |
Correct |
2 ms |
14684 KB |
Output is correct |
11 |
Correct |
2 ms |
14684 KB |
Output is correct |
12 |
Correct |
2 ms |
14684 KB |
Output is correct |
13 |
Correct |
54 ms |
21472 KB |
Output is correct |
14 |
Correct |
51 ms |
21476 KB |
Output is correct |
15 |
Correct |
53 ms |
21328 KB |
Output is correct |
16 |
Correct |
53 ms |
21844 KB |
Output is correct |
17 |
Correct |
53 ms |
21476 KB |
Output is correct |
18 |
Correct |
53 ms |
21480 KB |
Output is correct |
19 |
Correct |
55 ms |
21988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
53 ms |
21392 KB |
Output is correct |
4 |
Correct |
56 ms |
21588 KB |
Output is correct |
5 |
Correct |
149 ms |
22868 KB |
Output is correct |
6 |
Correct |
116 ms |
21328 KB |
Output is correct |
7 |
Correct |
107 ms |
25448 KB |
Output is correct |
8 |
Correct |
2 ms |
14684 KB |
Output is correct |
9 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14684 KB |
Output is correct |
4 |
Correct |
2 ms |
14684 KB |
Output is correct |
5 |
Correct |
2 ms |
14812 KB |
Output is correct |
6 |
Correct |
2 ms |
14684 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
2 ms |
14684 KB |
Output is correct |
9 |
Correct |
2 ms |
14684 KB |
Output is correct |
10 |
Correct |
2 ms |
14684 KB |
Output is correct |
11 |
Correct |
2 ms |
14684 KB |
Output is correct |
12 |
Correct |
2 ms |
14684 KB |
Output is correct |
13 |
Correct |
54 ms |
21472 KB |
Output is correct |
14 |
Correct |
51 ms |
21476 KB |
Output is correct |
15 |
Correct |
53 ms |
21328 KB |
Output is correct |
16 |
Correct |
53 ms |
21844 KB |
Output is correct |
17 |
Correct |
53 ms |
21476 KB |
Output is correct |
18 |
Correct |
53 ms |
21480 KB |
Output is correct |
19 |
Correct |
55 ms |
21988 KB |
Output is correct |
20 |
Correct |
56 ms |
22608 KB |
Output is correct |
21 |
Correct |
53 ms |
22100 KB |
Output is correct |
22 |
Correct |
56 ms |
22608 KB |
Output is correct |
23 |
Correct |
52 ms |
21840 KB |
Output is correct |
24 |
Correct |
52 ms |
21460 KB |
Output is correct |
25 |
Correct |
56 ms |
21588 KB |
Output is correct |
26 |
Correct |
55 ms |
22868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14684 KB |
Output is correct |
4 |
Correct |
2 ms |
14684 KB |
Output is correct |
5 |
Correct |
2 ms |
14812 KB |
Output is correct |
6 |
Correct |
2 ms |
14684 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
2 ms |
14684 KB |
Output is correct |
9 |
Correct |
2 ms |
14684 KB |
Output is correct |
10 |
Correct |
2 ms |
14684 KB |
Output is correct |
11 |
Correct |
2 ms |
14684 KB |
Output is correct |
12 |
Correct |
2 ms |
14684 KB |
Output is correct |
13 |
Correct |
54 ms |
21472 KB |
Output is correct |
14 |
Correct |
51 ms |
21476 KB |
Output is correct |
15 |
Correct |
53 ms |
21328 KB |
Output is correct |
16 |
Correct |
53 ms |
21844 KB |
Output is correct |
17 |
Correct |
53 ms |
21476 KB |
Output is correct |
18 |
Correct |
53 ms |
21480 KB |
Output is correct |
19 |
Correct |
55 ms |
21988 KB |
Output is correct |
20 |
Correct |
2 ms |
14684 KB |
Output is correct |
21 |
Correct |
2 ms |
14684 KB |
Output is correct |
22 |
Correct |
53 ms |
21392 KB |
Output is correct |
23 |
Correct |
56 ms |
21588 KB |
Output is correct |
24 |
Correct |
149 ms |
22868 KB |
Output is correct |
25 |
Correct |
116 ms |
21328 KB |
Output is correct |
26 |
Correct |
107 ms |
25448 KB |
Output is correct |
27 |
Correct |
2 ms |
14684 KB |
Output is correct |
28 |
Correct |
2 ms |
14684 KB |
Output is correct |
29 |
Correct |
56 ms |
22608 KB |
Output is correct |
30 |
Correct |
53 ms |
22100 KB |
Output is correct |
31 |
Correct |
56 ms |
22608 KB |
Output is correct |
32 |
Correct |
52 ms |
21840 KB |
Output is correct |
33 |
Correct |
52 ms |
21460 KB |
Output is correct |
34 |
Correct |
56 ms |
21588 KB |
Output is correct |
35 |
Correct |
55 ms |
22868 KB |
Output is correct |
36 |
Correct |
210 ms |
26520 KB |
Output is correct |
37 |
Correct |
198 ms |
26708 KB |
Output is correct |
38 |
Correct |
159 ms |
26708 KB |
Output is correct |
39 |
Correct |
151 ms |
26192 KB |
Output is correct |
40 |
Correct |
164 ms |
26308 KB |
Output is correct |
41 |
Correct |
185 ms |
30472 KB |
Output is correct |
42 |
Correct |
170 ms |
32272 KB |
Output is correct |
43 |
Correct |
185 ms |
35992 KB |
Output is correct |
44 |
Correct |
199 ms |
36080 KB |
Output is correct |
45 |
Correct |
200 ms |
25988 KB |
Output is correct |
46 |
Correct |
277 ms |
27724 KB |
Output is correct |
47 |
Correct |
209 ms |
27984 KB |
Output is correct |
48 |
Correct |
165 ms |
26828 KB |
Output is correct |