This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 500005
#define pii pair<int, int>
#define ff first
#define ss second
#include "teams.h"
struct segtree{
vector<int> seg[4*maxn];
void build(int cur, int l, int r, vector<pii> a) {
if (r <= l || a.size() == 0) return;
if (r - l == 1) {
for (auto p:a) seg[cur].push_back(p.ss);
sort(seg[cur].begin(), seg[cur].end());
return;
}
int m = (l + r) / 2;
vector<pii> lef, rig;
for (auto p:a) {
if (p.ff < m)lef.push_back(p);
else rig.push_back(p);
}
build(cur*2, l, m, lef), build(cur*2+1, m, r, rig);
int ls = seg[cur*2].size(), rs = seg[cur*2+1].size();
vector<int> &le = seg[cur*2], &ri = seg[cur*2+1];
int ind = 0;
for (int i = 0;i < ls;i++) {
while (ind < rs && ri[ind] < le[i]) seg[cur].push_back(ri[ind++]);
seg[cur].push_back(le[i]);
}
while (ind < rs) seg[cur].push_back(ri[ind++]);
}
int query(int cur, int l, int r, int ql, int qr) {
//number of segments covering [ql, qr]
if (r <= l || l > ql) return 0;
if (r-1 <= ql) {
return seg[cur].end() - lower_bound(seg[cur].begin(), seg[cur].end(), qr);
}
int m = (l + r) / 2;
return query(cur*2, l, m, ql, qr) + query(cur*2+1, m, r, ql, qr);
}
} tr;
int v[maxn];
int n;
void init(int N, int A[], int B[]) {
n = N;
vector<pii> a(n);
for (int i = 0;i < n;i++) {
a[i] = {A[i], B[i]};
v[A[i]]++;
v[B[i] + 1]--;
}
tr.build(1, 1, N+1, a);
for (int i = 1;i <= n;i++) v[i] += v[i-1]; //number of segments covering i
pary(v, v + n + 1);
}
int can(int m, int num[]) {
sort(num, num + m);
vector<int> p(m, 0), c(m, 0);
for (int i = 0;i < m;i++) {
c[i] = num[i] + (i ? c[i-1] : 0);
if (c[i] > n) return 0;
}
pary(num, num + m);
for (int i = 0;i < m;i++) {
if (i == 0) p[i] = v[num[i]];
else {
p[i] = v[num[i]] - tr.query(1, 1, n+1, num[i-1], num[i]);
p[i] += p[i-1];
}
}
pary(p.begin(), p.end());
pary(c.begin(), c.end());
for (int i = 0;i < m;i++) {
for (int j = i;j < m;j++) {
if (c[j] - (i ? c[i-1] : 0) > v[num[i]] + p[j] - p[i]) return 0;
}
}
/*
int ma = 0;
for (int i = 0;i < m;i++) {
if (p[i] - c[i] < ma || c[i] - (i ? c[i-1] : 0) > v[num[i]]) return 0;
ma = max(ma, p[i] - (i ? c[i-1] : 0) - v[num[i]]);
}
*/
return 1;
}
/*
4
2 3 1 1
3 4 4 4
1
4
*/
Compilation message (stderr)
teams.cpp: In member function 'void segtree::build(int, int, int, std::vector<std::pair<int, int> >)':
teams.cpp:38:27: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
38 | int ls = seg[cur*2].size(), rs = seg[cur*2+1].size();
| ~~~~~~~~~~~~~~~^~
teams.cpp:38:53: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
38 | int ls = seg[cur*2].size(), rs = seg[cur*2+1].size();
| ~~~~~~~~~~~~~~~~~^~
teams.cpp: In member function 'int segtree::query(int, int, int, int, int)':
teams.cpp:51:26: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
51 | return seg[cur].end() - lower_bound(seg[cur].begin(), seg[cur].end(), qr);
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:13:19: warning: statement has no effect [-Wunused-value]
13 | #define pary(...) 0
| ^
teams.cpp:70:2: note: in expansion of macro 'pary'
70 | pary(v, v + n + 1);
| ^~~~
teams.cpp: In function 'int can(int, int*)':
teams.cpp:13:19: warning: statement has no effect [-Wunused-value]
13 | #define pary(...) 0
| ^
teams.cpp:81:2: note: in expansion of macro 'pary'
81 | pary(num, num + m);
| ^~~~
teams.cpp:13:19: warning: statement has no effect [-Wunused-value]
13 | #define pary(...) 0
| ^
teams.cpp:89:2: note: in expansion of macro 'pary'
89 | pary(p.begin(), p.end());
| ^~~~
teams.cpp:13:19: warning: statement has no effect [-Wunused-value]
13 | #define pary(...) 0
| ^
teams.cpp:90:2: note: in expansion of macro 'pary'
90 | pary(c.begin(), c.end());
| ^~~~
# | 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... |