Submission #970961

# Submission time Handle Problem Language Result Execution time Memory
970961 2024-04-27T16:04:17 Z CSQ31 Inspections (NOI23_inspections) C++17
100 / 100
281 ms 30152 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
//x - l_i + p_{i-1} - p_j + r_j - x
//(p_{i-1} - l_i+1) + (r_j - p_j) > s is the condition
//only r_j - p_j is important
struct range
{
    ll l,r,val = -1e18;
    range(){}
    range(ll _l,ll _r,ll _val){
        l = _l;
        r = _r;
        val = _val;
    }
    friend bool operator<(const range &a,const range &b){
        return b.r > a.r;
    }

};
set<range>s;
int main()
{
    owo
    int n,m,q;
    cin>>n>>m>>q;
    vector<PII>p(m),qs;
    vector<ll>pref(m,0);
    for(int i=0;i<m;i++){
        cin>>p[i].fi>>p[i].se;
        pref[i] = p[i].se - p[i].fi+1;
        if(i)pref[i]+=pref[i-1];
    }
    for(int i=0;i<q;i++){
        ll x;
        cin>>x;
        qs.pb({x,i});
    }
    sort(all(qs));
    vector<ll>ans(q,0);
    s.insert(range(1,n,-1e18));

    for(int i=0;i<m;i++){
        ll l0 = p[i].fi;
        ll r0 = p[i].se;
        vector<range>add;
        add.pb(range(l0,r0,r0 - pref[i]));
        while(true){
            auto it = s.ub(range(0,l0-1,0)); //first guy with r >= l0
            if(it == s.end())break;
            if(it->l > r0)break;
            if(it->l < l0)add.pb(range(it->l,l0-1,it->val));
            if(it->r > r0)add.pb(range(r0+1,it->r,it->val));

            ll inter = min(r0,it->r) - max(l0,it->l)+1;
            ll gap = (i?pref[i-1]:0) - l0 + it->val + 1;
            //cout<<"gap "<<inter<<" "<<gap<<'\n';
            int idx = lb(all(qs),make_pair(gap,0LL)) - qs.begin()-1;
            if(idx>=0)ans[idx] += inter;
            s.erase(it);
        }
        for(auto x:add)s.insert(x);
        /*
        cout<<"at "<<i<<'\n';
        for(auto x:s){
            cout<<x.l<<" "<<x.r<<" "<<x.val<<'\n';
        }*/
    }
    for(int i=q-2;i>=0;i--)ans[i]+=ans[i+1];
    vector<ll>fin(q);
    for(int i=0;i<q;i++)fin[qs[i].se] = ans[i];
    for(int i=0;i<q;i++)cout<<fin[i]<<" ";
    cout<<'\n';




}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 43 ms 7108 KB Output is correct
14 Correct 42 ms 7472 KB Output is correct
15 Correct 45 ms 7352 KB Output is correct
16 Correct 44 ms 7860 KB Output is correct
17 Correct 47 ms 8312 KB Output is correct
18 Correct 42 ms 7880 KB Output is correct
19 Correct 44 ms 7624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 43 ms 7840 KB Output is correct
4 Correct 53 ms 7900 KB Output is correct
5 Correct 136 ms 12996 KB Output is correct
6 Correct 100 ms 14012 KB Output is correct
7 Correct 90 ms 14020 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 43 ms 7108 KB Output is correct
14 Correct 42 ms 7472 KB Output is correct
15 Correct 45 ms 7352 KB Output is correct
16 Correct 44 ms 7860 KB Output is correct
17 Correct 47 ms 8312 KB Output is correct
18 Correct 42 ms 7880 KB Output is correct
19 Correct 44 ms 7624 KB Output is correct
20 Correct 44 ms 8372 KB Output is correct
21 Correct 42 ms 8116 KB Output is correct
22 Correct 43 ms 9144 KB Output is correct
23 Correct 45 ms 7620 KB Output is correct
24 Correct 42 ms 7300 KB Output is correct
25 Correct 46 ms 7704 KB Output is correct
26 Correct 44 ms 8364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 43 ms 7108 KB Output is correct
14 Correct 42 ms 7472 KB Output is correct
15 Correct 45 ms 7352 KB Output is correct
16 Correct 44 ms 7860 KB Output is correct
17 Correct 47 ms 8312 KB Output is correct
18 Correct 42 ms 7880 KB Output is correct
19 Correct 44 ms 7624 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 43 ms 7840 KB Output is correct
23 Correct 53 ms 7900 KB Output is correct
24 Correct 136 ms 12996 KB Output is correct
25 Correct 100 ms 14012 KB Output is correct
26 Correct 90 ms 14020 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 44 ms 8372 KB Output is correct
30 Correct 42 ms 8116 KB Output is correct
31 Correct 43 ms 9144 KB Output is correct
32 Correct 45 ms 7620 KB Output is correct
33 Correct 42 ms 7300 KB Output is correct
34 Correct 46 ms 7704 KB Output is correct
35 Correct 44 ms 8364 KB Output is correct
36 Correct 223 ms 17896 KB Output is correct
37 Correct 226 ms 16992 KB Output is correct
38 Correct 165 ms 16920 KB Output is correct
39 Correct 127 ms 17352 KB Output is correct
40 Correct 187 ms 16772 KB Output is correct
41 Correct 209 ms 21956 KB Output is correct
42 Correct 196 ms 23116 KB Output is correct
43 Correct 237 ms 30152 KB Output is correct
44 Correct 237 ms 29352 KB Output is correct
45 Correct 207 ms 16704 KB Output is correct
46 Correct 281 ms 18372 KB Output is correct
47 Correct 217 ms 18504 KB Output is correct
48 Correct 161 ms 17168 KB Output is correct