Submission #893322

# Submission time Handle Problem Language Result Execution time Memory
893322 2023-12-27T01:56:09 Z fdnfksd Inspections (NOI23_inspections) C++14
0 / 100
1075 ms 1048576 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#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<int>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;
            }
        }
        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 Runtime error 990 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 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 Runtime error 990 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Runtime error 1075 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 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 Runtime error 990 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 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 Runtime error 990 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -