답안 #841668

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
841668 2023-09-01T19:51:56 Z kwongweng Inspections (NOI23_inspections) C++17
100 / 100
1370 ms 249816 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define fi first
#define se second

const int mxnode = 2e7+1,N = 2e5+1;
vi L(N), R(N), val(mxnode,-1);
vector<ll> s(N),  sm(mxnode);
vector<pair<ll,int>> S;
int q;

void update(int v, int tl, int tr, int l, int r, ll Val){
    if (tl==l && tr==r){
        sm[v] += Val; return;
    }
    if (l>r) return;
    int tm = (tl+tr)/2;
    update(2*v,tl,tm,l,min(r,tm), Val);
    update(2*v+1,tm+1,tr,max(l,tm+1),r,Val);
}

ll get(int v, int tl, int tr, int pos){
    if (tl==tr) return sm[v];
    int tm = (tl+tr)/2;
    if (pos <= tm) return sm[v] + get(2*v,tl,tm,pos);
    return sm[v] + get(2*v+1,tm+1,tr,pos);
}

void upd(int v, int tl, int tr, int l, int r, int ind){
    if (tl != tr && val[v] != -1){
        val[2*v]=val[2*v+1]=val[v];
    }
    if (l>r) return;
    if (tl==l && tr==r && (tl==tr || val[v] != -1)){
        if (val[v] != -1){
            ll num = s[ind-1] + (l-L[ind]) - s[val[v]-1] - (l-L[val[v]]);
            //cout<<val[v]<<" "<<ind<<" "<<num<<" "<<r-l+1<<"\n";
            int pos = lower_bound(S.begin(), S.end(), make_pair(num,0)) - S.begin();
            //cout<<pos<<" "<<num<<"\n";
            update(1,0,q,0,pos-1,r-l+1); 
        }
        val[v] = ind;
        return;
    }
    int tm = (tl+tr)/2;
    upd(2*v,tl,tm,l,min(r,tm),ind);
    upd(2*v+1,tm+1,tr,max(l,tm+1),r,ind);
    if (val[2*v] == val[2*v+1] && val[2*v] != -1) val[v]=val[2*v];
    else val[v]=-1;
}


int main(){
    int n, m; cin>>n>>m>>q;
    
    FOR(i,1,m+1){
        cin>>L[i]>>R[i];
    }
    //cout<<ndcnt<<"\n";
    FOR(i,0,q){
        ll val; cin>>val;
        S.pb({val,i});
    }
    sort(S.begin(), S.end());
    FOR(i,1,m+1){
        upd(1,1,n,L[i],R[i],i);
        s[i]=s[i-1]+(R[i]-L[i]+1);
    }
    vector<ll> ans(q);
    FOR(i,0,q){
        ans[S[i].se] = get(1,0,q,i);
    }
    FOR(i,0,q) cout<<ans[i]<<" ";
    cout<< "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 238604 KB Output is correct
2 Correct 29 ms 238244 KB Output is correct
3 Correct 28 ms 238172 KB Output is correct
4 Correct 28 ms 238388 KB Output is correct
5 Correct 27 ms 238428 KB Output is correct
6 Correct 28 ms 238428 KB Output is correct
7 Correct 28 ms 238428 KB Output is correct
8 Correct 27 ms 238404 KB Output is correct
9 Correct 27 ms 238428 KB Output is correct
10 Correct 27 ms 238320 KB Output is correct
11 Correct 31 ms 238380 KB Output is correct
12 Correct 28 ms 238296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 238604 KB Output is correct
2 Correct 29 ms 238244 KB Output is correct
3 Correct 28 ms 238172 KB Output is correct
4 Correct 28 ms 238388 KB Output is correct
5 Correct 27 ms 238428 KB Output is correct
6 Correct 28 ms 238428 KB Output is correct
7 Correct 28 ms 238428 KB Output is correct
8 Correct 27 ms 238404 KB Output is correct
9 Correct 27 ms 238428 KB Output is correct
10 Correct 27 ms 238320 KB Output is correct
11 Correct 31 ms 238380 KB Output is correct
12 Correct 28 ms 238296 KB Output is correct
13 Correct 116 ms 245292 KB Output is correct
14 Correct 113 ms 245700 KB Output is correct
15 Correct 115 ms 245700 KB Output is correct
16 Correct 116 ms 245716 KB Output is correct
17 Correct 112 ms 244928 KB Output is correct
18 Correct 111 ms 244928 KB Output is correct
19 Correct 114 ms 245180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 238172 KB Output is correct
2 Correct 27 ms 238284 KB Output is correct
3 Correct 111 ms 244992 KB Output is correct
4 Correct 124 ms 246420 KB Output is correct
5 Correct 849 ms 248172 KB Output is correct
6 Correct 397 ms 247476 KB Output is correct
7 Correct 513 ms 247404 KB Output is correct
8 Correct 28 ms 238164 KB Output is correct
9 Correct 27 ms 238168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 238604 KB Output is correct
2 Correct 29 ms 238244 KB Output is correct
3 Correct 28 ms 238172 KB Output is correct
4 Correct 28 ms 238388 KB Output is correct
5 Correct 27 ms 238428 KB Output is correct
6 Correct 28 ms 238428 KB Output is correct
7 Correct 28 ms 238428 KB Output is correct
8 Correct 27 ms 238404 KB Output is correct
9 Correct 27 ms 238428 KB Output is correct
10 Correct 27 ms 238320 KB Output is correct
11 Correct 31 ms 238380 KB Output is correct
12 Correct 28 ms 238296 KB Output is correct
13 Correct 116 ms 245292 KB Output is correct
14 Correct 113 ms 245700 KB Output is correct
15 Correct 115 ms 245700 KB Output is correct
16 Correct 116 ms 245716 KB Output is correct
17 Correct 112 ms 244928 KB Output is correct
18 Correct 111 ms 244928 KB Output is correct
19 Correct 114 ms 245180 KB Output is correct
20 Correct 123 ms 246588 KB Output is correct
21 Correct 118 ms 245436 KB Output is correct
22 Correct 121 ms 246460 KB Output is correct
23 Correct 116 ms 244996 KB Output is correct
24 Correct 108 ms 245348 KB Output is correct
25 Correct 137 ms 245744 KB Output is correct
26 Correct 117 ms 246700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 238604 KB Output is correct
2 Correct 29 ms 238244 KB Output is correct
3 Correct 28 ms 238172 KB Output is correct
4 Correct 28 ms 238388 KB Output is correct
5 Correct 27 ms 238428 KB Output is correct
6 Correct 28 ms 238428 KB Output is correct
7 Correct 28 ms 238428 KB Output is correct
8 Correct 27 ms 238404 KB Output is correct
9 Correct 27 ms 238428 KB Output is correct
10 Correct 27 ms 238320 KB Output is correct
11 Correct 31 ms 238380 KB Output is correct
12 Correct 28 ms 238296 KB Output is correct
13 Correct 116 ms 245292 KB Output is correct
14 Correct 113 ms 245700 KB Output is correct
15 Correct 115 ms 245700 KB Output is correct
16 Correct 116 ms 245716 KB Output is correct
17 Correct 112 ms 244928 KB Output is correct
18 Correct 111 ms 244928 KB Output is correct
19 Correct 114 ms 245180 KB Output is correct
20 Correct 27 ms 238172 KB Output is correct
21 Correct 27 ms 238284 KB Output is correct
22 Correct 111 ms 244992 KB Output is correct
23 Correct 124 ms 246420 KB Output is correct
24 Correct 849 ms 248172 KB Output is correct
25 Correct 397 ms 247476 KB Output is correct
26 Correct 513 ms 247404 KB Output is correct
27 Correct 28 ms 238164 KB Output is correct
28 Correct 27 ms 238168 KB Output is correct
29 Correct 123 ms 246588 KB Output is correct
30 Correct 118 ms 245436 KB Output is correct
31 Correct 121 ms 246460 KB Output is correct
32 Correct 116 ms 244996 KB Output is correct
33 Correct 108 ms 245348 KB Output is correct
34 Correct 137 ms 245744 KB Output is correct
35 Correct 117 ms 246700 KB Output is correct
36 Correct 1325 ms 249368 KB Output is correct
37 Correct 1370 ms 249436 KB Output is correct
38 Correct 568 ms 248512 KB Output is correct
39 Correct 420 ms 247872 KB Output is correct
40 Correct 896 ms 248252 KB Output is correct
41 Correct 434 ms 249280 KB Output is correct
42 Correct 392 ms 248516 KB Output is correct
43 Correct 601 ms 248988 KB Output is correct
44 Correct 351 ms 248764 KB Output is correct
45 Correct 1000 ms 247996 KB Output is correct
46 Correct 528 ms 248104 KB Output is correct
47 Correct 305 ms 248512 KB Output is correct
48 Correct 1145 ms 249816 KB Output is correct