Submission #1005934

#TimeUsernameProblemLanguageResultExecution timeMemory
1005934irmuunMeetings (IOI18_meetings)C++17
17 / 100
69 ms9012 KiB
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

struct segtree{
    ll n;
    vector<ll>d;
    vector<ll>u;
    segtree(ll n):n(n){
        d.resize(4*n);
        build(1,0,n-1);
    }
    void build(ll node,ll l,ll r){
        if(l==r){
            d[node]=0;
            return;
        }
        ll mid=(l+r)/2;
        build(node*2,l,mid);
        build(node*2+1,mid+1,r);
    }
    ll query(ll node,ll l,ll r,ll L,ll R){
        if(l > R || r < L || L > R){
            return 0;
        }
        if(L <= l && r <= R){
            return d[node];
        }
        ll mid=(l+r)/2;
        return max(query(node*2,l,mid,L,R),query(node*2+1,mid+1,r,L,R));
    }
    void update(ll node,ll l,ll r,ll k,ll val){
        if(l>k || r<k)return;
        if(l==r){
            d[node]=val;
            return;
        }
        ll mid=(l+r)/2;
        update(node*2,l,mid,k,val);
        update(node*2+1,mid+1,r,k,val);
        d[node]=max(d[node*2],d[node*2+1]);
    }
};

vector<ll>minimum_costs(vector<int>H,vector<int>L,vector<int>R){
    int n=H.size(),m=L.size();
    vector<ll>ans(m,1e18);
    vector<int>p;
    for(int i=0;i<n;i++){
        if(H[i]==2){
            p.pb(i);
        }
    }
    segtree sg(n);
    for(int i=1;i<p.size();i++){
        sg.update(1,0,n-1,i-1,p[i]-p[i-1]-1);
    }
    for(int j=0;j<m;j++){
        if(p.empty()){
            ans[j]=R[j]-L[j]+1;
            continue;
        }
        int l=lower_bound(all(p),L[j])-p.begin();
        if(l==p.size()||p[l]>R[j]){
            ans[j]=R[j]-L[j]+1;
            continue;
        }
        int r=lower_bound(all(p),R[j]+1)-p.begin();
        r--;
        int mx=sg.query(1,0,n-1,l,r-1);
        mx=max(mx,p[l]-L[j]);
        mx=max(mx,R[j]-p[r]);
        ans[j]=2*(R[j]-L[j]+1)-mx;
    }
    return ans;
}

Compilation message (stderr)

meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i=1;i<p.size();i++){
      |                 ~^~~~~~~~~
meetings.cpp:71:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         if(l==p.size()||p[l]>R[j]){
      |            ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...