This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "teams.h"
using namespace std;
typedef long long ll;
const int N=500000;
int n;
vector<int> tree[4*N];
void update(int idx,int l,int r,int pos,int x)
{
tree[idx].push_back(x);
if(l<r)
{
int m=(l+r)/2;
if(pos<=m) update(2*idx,l,m,pos,x);
else update(2*idx+1,m+1,r,pos,x);
}
}
int query(int idx,int l,int r,int ql,int qr,int lim)
{
if(ql>qr) return 0;
if(l==ql&&r==qr) return (upper_bound(tree[idx].begin(),tree[idx].end(),lim)-tree[idx].begin());
int m=(l+r)/2;
return query(2*idx,l,m,ql,min(qr,m),lim)+query(2*idx+1,m+1,r,max(ql,m+1),qr,lim);
}
void init(int tn,int A[],int B[])
{
n=tn;
vector<array<int,2>> v(n);
for(int i=0;i<n;i++) v[i]={B[i],A[i]};
sort(v.begin(),v.end());
for(auto [b,a]:v) update(1,1,n,a,b);
}
int can(int m,int K[])
{
vector<int> a={0};
for(int i=0;i<m;i++) a.push_back(K[i]);
sort(a.begin(),a.end());
auto f=[&](int l,int r)->int{return query(1,1,n,l,r,r);};
vector<ll> s(m+1,0);
ll mn=0;
bool ok=1;
for(int i=1;i<=m;i++)
{
s[i]=s[i-1]-f(a[i-1]+1,a[i]-1)-a[i];
ll t=-s[i]-a[i]-f(1,a[i]-1);
mn=min(mn,t);
ok&=(n+s[i]-f(a[i]+1,n)+mn>=0);
}
return ok;
}
Compilation message (stderr)
teams.cpp: In function 'int query(int, int, int, int, int, int)':
teams.cpp:25:80: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
25 | if(l==ql&&r==qr) return (upper_bound(tree[idx].begin(),tree[idx].end(),lim)-tree[idx].begin());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |