Submission #893332

# Submission time Handle Problem Language Result Execution time Memory
893332 2023-12-27T02:10:13 Z karrigan Inspections (NOI23_inspections) C++14
100 / 100
268 ms 26688 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 6488 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 6616 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 6648 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 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 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 6616 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 6648 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 4444 KB Output is correct
13 Correct 40 ms 8568 KB Output is correct
14 Correct 37 ms 8540 KB Output is correct
15 Correct 39 ms 8528 KB Output is correct
16 Correct 40 ms 9044 KB Output is correct
17 Correct 39 ms 8532 KB Output is correct
18 Correct 40 ms 8528 KB Output is correct
19 Correct 39 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 40 ms 8572 KB Output is correct
4 Correct 42 ms 8784 KB Output is correct
5 Correct 134 ms 9808 KB Output is correct
6 Correct 105 ms 8624 KB Output is correct
7 Correct 92 ms 10576 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 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 6616 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 6648 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 4444 KB Output is correct
13 Correct 40 ms 8568 KB Output is correct
14 Correct 37 ms 8540 KB Output is correct
15 Correct 39 ms 8528 KB Output is correct
16 Correct 40 ms 9044 KB Output is correct
17 Correct 39 ms 8532 KB Output is correct
18 Correct 40 ms 8528 KB Output is correct
19 Correct 39 ms 9052 KB Output is correct
20 Correct 42 ms 9896 KB Output is correct
21 Correct 39 ms 9124 KB Output is correct
22 Correct 39 ms 9896 KB Output is correct
23 Correct 38 ms 9128 KB Output is correct
24 Correct 38 ms 8796 KB Output is correct
25 Correct 42 ms 8796 KB Output is correct
26 Correct 40 ms 9916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 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 6616 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 6648 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 4444 KB Output is correct
13 Correct 40 ms 8568 KB Output is correct
14 Correct 37 ms 8540 KB Output is correct
15 Correct 39 ms 8528 KB Output is correct
16 Correct 40 ms 9044 KB Output is correct
17 Correct 39 ms 8532 KB Output is correct
18 Correct 40 ms 8528 KB Output is correct
19 Correct 39 ms 9052 KB Output is correct
20 Correct 1 ms 6488 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 40 ms 8572 KB Output is correct
23 Correct 42 ms 8784 KB Output is correct
24 Correct 134 ms 9808 KB Output is correct
25 Correct 105 ms 8624 KB Output is correct
26 Correct 92 ms 10576 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 42 ms 9896 KB Output is correct
30 Correct 39 ms 9124 KB Output is correct
31 Correct 39 ms 9896 KB Output is correct
32 Correct 38 ms 9128 KB Output is correct
33 Correct 38 ms 8796 KB Output is correct
34 Correct 42 ms 8796 KB Output is correct
35 Correct 40 ms 9916 KB Output is correct
36 Correct 207 ms 10064 KB Output is correct
37 Correct 195 ms 9812 KB Output is correct
38 Correct 150 ms 8784 KB Output is correct
39 Correct 158 ms 9556 KB Output is correct
40 Correct 170 ms 8664 KB Output is correct
41 Correct 239 ms 15540 KB Output is correct
42 Correct 226 ms 16244 KB Output is correct
43 Correct 242 ms 26688 KB Output is correct
44 Correct 245 ms 25172 KB Output is correct
45 Correct 193 ms 8788 KB Output is correct
46 Correct 268 ms 11436 KB Output is correct
47 Correct 202 ms 10320 KB Output is correct
48 Correct 163 ms 9388 KB Output is correct