Submission #893333

# Submission time Handle Problem Language Result Execution time Memory
893333 2023-12-27T02:10:36 Z vjudge1 Inspections (NOI23_inspections) C++17
100 / 100
260 ms 26564 KB
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define lastbit(i) __builtin_ctz(i)
#define pil pair<int,long long>
const int maxn=2e5+9;
struct line{
int l,r;
long long time;
bool operator < (const line &p)const {
if (l==p.l)return r<p.r;
return l<p.l;
}
};
struct suzy{
long long u;
int id;
bool operator < (const suzy &p)const {
return u<p.u;
}
}b[maxn];
long long pf[maxn];
pii a[maxn];
long long sum[maxn];
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("temp.INP","r",stdin);
    //freopen("temp.OUT","w",stdout);
    int n,m,q;
    cin>>n>>m>>q;
    for1(i,1,m)cin>>a[i].fi>>a[i].se;
    for1(i,1,q){
    b[i].id=i;
    cin>>b[i].u;
    }
    sort(b+1,b+1+q);
    multiset<line>t;
    t.insert({1,n,-1});
    long long ss=0;
    for1(i,1,m){
    line dm={a[i].fi,-1,-1};
    vector<line>tmp;
    while (!t.empty()){
    auto it=t.lower_bound(dm);
    if (it==t.end())break;
    if ((*it).l>a[i].se)break;
    auto vcl=(*it);
    if ((*it).r>a[i].se){
    t.erase(it);
    t.insert({a[i].se+1,vcl.r,vcl.time+(vcl.time!=-1)*(a[i].se-vcl.l+1)});
    tmp.pb({vcl.l,a[i].se,vcl.time});
    }
    else {
    t.erase(it);
    tmp.pb(vcl);
    }
    }
    auto it=t.lower_bound(dm);
    if (!t.empty()&&it!=t.begin()){
    it--;
    auto vcl=(*it);
    if (vcl.r>=a[i].fi){
    if (vcl.r>a[i].se){
    t.erase(it);
    t.insert({vcl.l,a[i].fi-1,vcl.time});
    t.insert({a[i].se+1,vcl.r,vcl.time+(vcl.time!=-1)*(a[i].se-vcl.l+1)});
    tmp.pb({a[i].fi,a[i].se,vcl.time+(vcl.time!=-1)*(a[i].fi-1-vcl.l+1)});
    }
    else {
    //divide to (*it).l a[i].fi-1 a[i].fi (*it).r
    t.erase(it);
    t.insert({vcl.l,a[i].fi-1,vcl.time});
    tmp.pb({a[i].fi,vcl.r,vcl.time+(vcl.time!=-1)*(a[i].fi-1-vcl.l+1)});
    }
    }
    }
    t.insert({a[i].fi,a[i].se,ss});
    long long xx=ss;
    sort(all(tmp));
    for (auto v:tmp){
    //v.time+2 to xx
    long long dis=(xx-(v.time+2)+1);
    int l=1,r=q,ans=-1;
    while (l<=r){
    int mid=(l+r)/2;
    if (b[mid].u<=dis){
    ans=mid;
    l=mid+1;
    }
    else r=mid-1;
    }
    if (v.time==-1)ans=-1;
    if (ans!=-1){
    pf[1]+=(v.r-v.l+1);
    pf[ans+1]-=(v.r-v.l+1);
    }
    xx+=(v.r-v.l+1);
    }
    ss+=(a[i].se-a[i].fi+1);
    }
    //for (auto v:t)cout<<v.l<<" "<<v.r<<" "<<v.time<<'\n';
    for1(i,1,q)pf[i]+=pf[i-1];
    for1(i,1,q)sum[b[i].id]=pf[i];
    for1(i,1,q)cout<<sum[i]<<" ";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 41 ms 8536 KB Output is correct
14 Correct 38 ms 8532 KB Output is correct
15 Correct 40 ms 8532 KB Output is correct
16 Correct 40 ms 9044 KB Output is correct
17 Correct 39 ms 8528 KB Output is correct
18 Correct 40 ms 8532 KB Output is correct
19 Correct 39 ms 9040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6696 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 39 ms 8552 KB Output is correct
4 Correct 42 ms 8788 KB Output is correct
5 Correct 134 ms 9884 KB Output is correct
6 Correct 101 ms 8604 KB Output is correct
7 Correct 99 ms 10576 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 41 ms 8536 KB Output is correct
14 Correct 38 ms 8532 KB Output is correct
15 Correct 40 ms 8532 KB Output is correct
16 Correct 40 ms 9044 KB Output is correct
17 Correct 39 ms 8528 KB Output is correct
18 Correct 40 ms 8532 KB Output is correct
19 Correct 39 ms 9040 KB Output is correct
20 Correct 41 ms 9728 KB Output is correct
21 Correct 39 ms 9044 KB Output is correct
22 Correct 40 ms 9932 KB Output is correct
23 Correct 42 ms 9232 KB Output is correct
24 Correct 39 ms 8788 KB Output is correct
25 Correct 44 ms 8792 KB Output is correct
26 Correct 39 ms 9920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 41 ms 8536 KB Output is correct
14 Correct 38 ms 8532 KB Output is correct
15 Correct 40 ms 8532 KB Output is correct
16 Correct 40 ms 9044 KB Output is correct
17 Correct 39 ms 8528 KB Output is correct
18 Correct 40 ms 8532 KB Output is correct
19 Correct 39 ms 9040 KB Output is correct
20 Correct 2 ms 6696 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 39 ms 8552 KB Output is correct
23 Correct 42 ms 8788 KB Output is correct
24 Correct 134 ms 9884 KB Output is correct
25 Correct 101 ms 8604 KB Output is correct
26 Correct 99 ms 10576 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 41 ms 9728 KB Output is correct
30 Correct 39 ms 9044 KB Output is correct
31 Correct 40 ms 9932 KB Output is correct
32 Correct 42 ms 9232 KB Output is correct
33 Correct 39 ms 8788 KB Output is correct
34 Correct 44 ms 8792 KB Output is correct
35 Correct 39 ms 9920 KB Output is correct
36 Correct 215 ms 10068 KB Output is correct
37 Correct 194 ms 9884 KB Output is correct
38 Correct 148 ms 8616 KB Output is correct
39 Correct 145 ms 9556 KB Output is correct
40 Correct 170 ms 8688 KB Output is correct
41 Correct 234 ms 15364 KB Output is correct
42 Correct 228 ms 16168 KB Output is correct
43 Correct 240 ms 26564 KB Output is correct
44 Correct 235 ms 24772 KB Output is correct
45 Correct 194 ms 9128 KB Output is correct
46 Correct 260 ms 11244 KB Output is correct
47 Correct 197 ms 10444 KB Output is correct
48 Correct 162 ms 9300 KB Output is correct