답안 #893326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893326 2023-12-27T02:04:08 Z vjudge1 Inspections (NOI23_inspections) C++17
100 / 100
261 ms 31912 KB
#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();
}
# 결과 실행 시간 메모리 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 14684 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
# 결과 실행 시간 메모리 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 14684 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 55 ms 21332 KB Output is correct
14 Correct 51 ms 21332 KB Output is correct
15 Correct 53 ms 21476 KB Output is correct
16 Correct 53 ms 21840 KB Output is correct
17 Correct 52 ms 21476 KB Output is correct
18 Correct 53 ms 21584 KB Output is correct
19 Correct 54 ms 21840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14680 KB Output is correct
3 Correct 53 ms 21584 KB Output is correct
4 Correct 56 ms 21588 KB Output is correct
5 Correct 159 ms 22748 KB Output is correct
6 Correct 115 ms 21328 KB Output is correct
7 Correct 107 ms 23380 KB Output is correct
8 Correct 2 ms 14680 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 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 14684 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 55 ms 21332 KB Output is correct
14 Correct 51 ms 21332 KB Output is correct
15 Correct 53 ms 21476 KB Output is correct
16 Correct 53 ms 21840 KB Output is correct
17 Correct 52 ms 21476 KB Output is correct
18 Correct 53 ms 21584 KB Output is correct
19 Correct 54 ms 21840 KB Output is correct
20 Correct 55 ms 22752 KB Output is correct
21 Correct 53 ms 21988 KB Output is correct
22 Correct 53 ms 22608 KB Output is correct
23 Correct 51 ms 21844 KB Output is correct
24 Correct 52 ms 21584 KB Output is correct
25 Correct 56 ms 21584 KB Output is correct
26 Correct 54 ms 23012 KB Output is correct
# 결과 실행 시간 메모리 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 14684 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 55 ms 21332 KB Output is correct
14 Correct 51 ms 21332 KB Output is correct
15 Correct 53 ms 21476 KB Output is correct
16 Correct 53 ms 21840 KB Output is correct
17 Correct 52 ms 21476 KB Output is correct
18 Correct 53 ms 21584 KB Output is correct
19 Correct 54 ms 21840 KB Output is correct
20 Correct 2 ms 14680 KB Output is correct
21 Correct 2 ms 14680 KB Output is correct
22 Correct 53 ms 21584 KB Output is correct
23 Correct 56 ms 21588 KB Output is correct
24 Correct 159 ms 22748 KB Output is correct
25 Correct 115 ms 21328 KB Output is correct
26 Correct 107 ms 23380 KB Output is correct
27 Correct 2 ms 14680 KB Output is correct
28 Correct 2 ms 14684 KB Output is correct
29 Correct 55 ms 22752 KB Output is correct
30 Correct 53 ms 21988 KB Output is correct
31 Correct 53 ms 22608 KB Output is correct
32 Correct 51 ms 21844 KB Output is correct
33 Correct 52 ms 21584 KB Output is correct
34 Correct 56 ms 21584 KB Output is correct
35 Correct 54 ms 23012 KB Output is correct
36 Correct 209 ms 23120 KB Output is correct
37 Correct 196 ms 22864 KB Output is correct
38 Correct 155 ms 21716 KB Output is correct
39 Correct 150 ms 22356 KB Output is correct
40 Correct 164 ms 21648 KB Output is correct
41 Correct 175 ms 25556 KB Output is correct
42 Correct 167 ms 27148 KB Output is correct
43 Correct 184 ms 31912 KB Output is correct
44 Correct 186 ms 31008 KB Output is correct
45 Correct 203 ms 21840 KB Output is correct
46 Correct 261 ms 23772 KB Output is correct
47 Correct 207 ms 22864 KB Output is correct
48 Correct 163 ms 22220 KB Output is correct