Submission #1024513

#TimeUsernameProblemLanguageResultExecution timeMemory
1024513WongYiKaiExamination (JOI19_examination)C++14
22 / 100
3068 ms115500 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll maxn = 100000;

void build(ll tl, ll tr, ll v, multiset<ll> t[]){
    multiset<ll> temp;
    if (tl==tr){
        t[v] = temp;
    }
    else{
        t[v] = temp;
        ll tm = (tl+tr)>>1;
        build(tl,tm,v*2,t);
        build(tm+1,tr,v*2+1,t);
    }
}

ll query(ll v, ll tl, ll tr, ll l, ll r,multiset<ll> t[], ll c){
    if (tr<l||tl>r) return 0;
    if (tl>=l&&tr<=r){
        return t[v].size()-distance(t[v].begin(),t[v].lower_bound(c));
    }
    ll tm = (tl+tr)>>1;
    return query(v*2,tl,tm,l,r,t,c)+query(v*2+1,tm+1,tr,l,r,t,c);
}

void update(ll v, ll tl, ll tr, ll l, ll x, multiset<ll> t[]){
    t[v].insert(x);
    ll tm = (tl+tr)>>1;
    if (l<=tm) {
        if (tl==tr) return;
        else update(v*2,tl,tm,l,x,t);
    }
    else update(v*2+1,tm+1,tr,l,x,t);
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


    ll n;
    cin >> n;
    ll q;
    cin >> q;
    vector<pair<ll,pair<ll,ll>>> aa;
    for (int i=0;i<n;i++){
        ll s,t;
        cin >> s >> t;
        aa.push_back({s,{t,s+t}});
    }
    sort(aa.begin(),aa.end());
    multiset<ll> t[n*4];
    build(0,n-1,1,t);
    priority_queue<pair<pair<ll,ll>,pair<ll,ll>>> pq;
    for (int i=0;i<aa.size();i++){
        pq.push({{aa[i].second.first,i},{aa[i].first,aa[i].second.second}});
    }
    vector<pair<pair<ll,ll>,pair<ll,ll>>> aaa;
    ll cont = 0;
    ll ans[q+5];
    ll q2 = q;
    while (q--){
        ll x,y,z;
        cin >> x >> y >> z;
        aaa.push_back({{y,cont},{x,z}});
        cont++;
    }
    sort(aaa.begin(),aaa.end());
    for (int i=aaa.size()-1;i>=0;i--){
        ll x = aaa[i].second.first;
        ll z = aaa[i].second.second;
        ll y = aaa[i].first.first;
        pair<ll,pair<ll,ll>> temp = {x,{-1,-1}};
        ll ind = lower_bound(aa.begin(),aa.end(),temp)-aa.begin();
        while (!pq.empty() && pq.top().first.first >= y){
            update(1,0,n-1,pq.top().first.second,pq.top().second.second,t);
            pq.pop();
        }
        ans[aaa[i].first.second] = query(1,0,n-1,ind,n-1,t,z);
    }
    for (int i=0;i<q2;i++){
        cout << ans[i] << "\n";
    }
}

Compilation message (stderr)

examination.cpp: In function 'int main()':
examination.cpp:57:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for (int i=0;i<aa.size();i++){
      |                  ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...