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;
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// output
template<class T1, class T2> void OUT(const pair<T1,T2>& x);
template<class T> void OUT(const vector<T>& x);
template<class T> void OUT(const T& x) {cerr << x;}
template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); }
template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(x.fi,' ',x.se);}
template<class T> void OUT(const vector<T>& x) {RE(i,x.size()) OUT(i==0?"":" ",x[i]);}
template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); }
template<class H> void OUTLS(const H& h) {OUTL(h); }
template<class H, class... T> void OUTLS(const H& h, const T&... t) {OUT(h,' '); OUTLS(t...); }
const int N=(1<<19);
const int MX=N*30;
int n;
int seg[MX], pl[MX], pr[MX], nextSeg=1;
void buildSeg(int p=0, int l=0, int r=N-1) {
seg[p] = 0;
pl[p] = -1;
pr[p] = -1;
int m=(l+r)/2;
if(l == r) return;
pl[p] = nextSeg;
buildSeg(nextSeg++, l , m);
pr[p] = nextSeg;
buildSeg(nextSeg++, m+1, r);
}
int setSeg(int i, int v, int p, int l=0, int r=N-1) {
if(i < l || i > r) return p;
if(l == r) {
seg[nextSeg] = v;
pl[nextSeg] = -1;
pr[nextSeg] = -1;
return nextSeg++;
}
int m=(l+r)/2;
int np = nextSeg++;
pl[np] = setSeg(i,v,pl[p],l ,m);
pr[np] = setSeg(i,v,pr[p],m+1,r);
seg[np] = seg[pl[np]] + seg[pr[np]];
return np;
}
int getSeg(int i, int p, int l=0, int r=N-1) {
if(i > r) return 0;
if(i <= l) return seg[p];
int m = (l+r)/2;
return getSeg(i,pl[p],l,m) + getSeg(i,pr[p],m+1,r);
}
int rt[N];
vi a, b;
vi sa;
vi cnt;
void init(int _n, int A[], int B[]) {
n = _n;
RE(i,n) a.pb(A[i]), b.pb(B[i]);
RE(i,n) sa.pb(i);
sort(all(sa),[](int i, int j) {
return a[i] < a[j];
});
int ci=0;
rt[0] = 0; buildSeg();
cnt.assign(n,0);
RE1(i,n) {
rt[i] = rt[i-1];
while(ci < n && a[sa[ci]] <= i) {
cnt[b[sa[ci]]]++;
rt[i] = setSeg(b[sa[ci]], cnt[b[sa[ci]]], rt[i]);
ci++;
}
}
}
int getRegion(int b1, int a2) {
return getSeg(b1,rt[a2]);
}
int dp[MX];
int can(int m, int k[]) {
sort(k,k+m);
if(m >= 900) {
priority_queue<int,vi,greater<int>> pq;
int ci = 0;
RE(i,m) {
while(ci != n && a[sa[ci]] <= k[i])
pq.push(b[sa[ci++]]);
int cnt = 0;
while(!pq.empty() && cnt < k[i]) {
if(pq.top() >= k[i]) cnt++;
pq.pop();
}
if(cnt != k[i])
return 0;
}
return 1;
} else {
RE(i,m) {
int temp = getRegion(k[i],k[i]);
dp[i] = temp;
RE(j,i)
dp[i] = min(dp[i], dp[j] + temp - getRegion(k[i],k[j]));
dp[i] -= k[i];
if(dp[i] < 0)
return 0;
}
return 1;
}
return 0;
}
Compilation message (stderr)
teams.cpp: In function 'int can(int, int*)':
teams.cpp:121:17: warning: declaration of 'cnt' shadows a global declaration [-Wshadow]
121 | int cnt = 0;
| ^~~
teams.cpp:84:4: note: shadowed declaration is here
84 | vi cnt;
| ^~~
# | 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... |