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 "teams.h"
#include <bits/stdc++.h>
using namespace std;
const int nax = 5e5 + 3;
struct BIT {
int b[nax] = {0};
int query(int p) {
int ret = 0;
while(p>0) {
ret += b[p];
p -= p&-p;
}
return ret;
}
int query(int l, int r) {
int ret = query(r);
if(l>1) ret -= query(l-1);
return ret;
}
void update(int p, int val) {
while(p<nax) {
b[p] += val;
p += p&-p;
}
}
} both, one;
vector<int>mst[nax * 4];
int n;
vector<int>atob[nax];
void build(int l, int r, int v) {
if(l==r) {
mst[v] = atob[l];
return;
}
int mid = (l+r)/2;
build(l, mid, v*2);
build(mid+1, r, v*2+1);
mst[v].resize(r-l+1);
merge(mst[v*2].begin(), mst[v*2].end(), mst[v*2+1].begin(), mst[v*2+1].end(),
mst[v].begin());
}
int query(int l, int r, int L, int R, int v) {
if(l>=L && r<=R) {
int ret = upper_bound(mst[v].begin(), mst[v].end(), R) -
lower_bound(mst[v].begin(), mst[v].end(), L);
return ret;
}
if(l>R || r<L) return 0;
int mid = (l+r)/2;
return query(l, mid, L, R, v*2) + query(mid+1, r, L, R, v*2+1);
}
void init(int N, int A[], int B[]) {
n = N;
for(int i=0; i<N; ++i) {
both.update(A[i], 1);
both.update(B[i]+1, -1);
one.update(B[i], 1);
}
for(int i=0; i<n; ++i) {
atob[A[i]].push_back(B[i]);
}
for(int i=1; i<=n; ++i) {
sort(atob[i].begin(), atob[i].end());
}
build(1, n, 1);
}
int can(int M, int K[]) {
sort(K, K+M);
int need[M];
for(int i=0; i<M; ++i) {
need[i] = K[i];
}
for(int i=0; i<M; ++i) {
if(both.query(K[i])<need[i]) return 0;
if(i==M-1) break;
if(K[i]==K[i+1]) {
need[i+1] += need[i];
continue;
}
int ends_in_between = one.query(K[i], K[i+1]-1);
if(K[i]+1!=K[i+1]) {
ends_in_between -= query(1, n, K[i]+1, K[i+1]-1, 1);
}
if(need[i]>ends_in_between) {
need[i+1] += need[i] - ends_in_between;
}
}
return 1;
}
Compilation message (stderr)
teams.cpp: In function 'int query(int, int, int, int, int)':
teams.cpp:51:58: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
51 | int ret = upper_bound(mst[v].begin(), mst[v].end(), R) -
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
52 | lower_bound(mst[v].begin(), mst[v].end(), L);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |