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"
#pragma GCC optimize("O3")
#pragma target("avx2,bvx")
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(),x.end()
using ll = long long;
#define pi pair<int,int>
#define f first
#define s second
const int K=2e7;
struct sgt {
int l=0,r=0,s=0;
};
sgt t[K];
const int sz=1<<19;
int nxt=1;
int add(int v, int l, int r, int i, int x) {
if (r-l==1) {
t[nxt].s=t[v].s+x;
return nxt++;
}
int m=(l+r)>>1;
if (i<m) {
if (t[v].l==0) t[v].l=nxt++;
int n = add(t[v].l,l,m,i,x);
t[nxt].l=n, t[nxt].r=t[v].r, t[nxt].s=t[v].s+x;
return nxt++;
} else {
if (t[v].r==0) t[v].r=nxt++;
int n = add(t[v].r,m,r,i,x);
t[nxt].l=t[v].l, t[nxt].r=n, t[nxt].s=t[v].s+x;
return nxt++;
}
}
int add(int v, int i, int x) {
return add(v,0,sz,i,x);
}
int sum(int v, int l, int r, int lx, int rx) {
if (lx<=l && r<=rx) return t[v].s;
int m=(l+r)>>1;
int lq = t[v].l ? ( (lx>=m)?0:sum(t[v].l,l,m,lx,rx) ) : 0;
int rq = t[v].r ? ( (rx<=m)?0:sum(t[v].r,m,r,lx,rx) ) : 0;
return lq+rq;
}
int sum(int v, int l, int r) {
if (l>=r) return 0;
return sum(v,0,sz,l,r);
}
int st[(int)5e5+55];
pi a[(int)5e5];
int n;
void init(int _n, int f[], int s[]) {
n=_n;
forn(i,n) a[i]={f[i],s[i]};
vector<vector<int>> v(n+1);
forn(i,n) v[a[i].s].pb(i);
st[n+1]=0;
for(int i=n;i>0;--i) {
st[i]=st[i+1];
for(auto&x:v[i]) {
auto t=add(st[i],a[x].f,1);
st[i]=t;
}
}
}
int can(int m, int k[]) {
vector<int> v(m);
forn(i,m) v[i]=k[i];
sort(all(v));
int s=0; forn(i,m) s+=k[i];
if (s>n) return 0;
vector<pi> z;
forn(i,m) {
if (!z.size()) {
z.pb({v[i],1}); continue;
}
if (v[i]==z.back().f) z.back().s++;
else z.pb({v[i],1});
}
int t=z.size();
vector<int> dp(t+1,-1e9);
dp[0]=0;
forn(i,t) {
forn(j,i+1) {
if (dp[j]<=dp[i+1]) continue;
int cnt;
if (j==0) {
cnt=sum(st[z[i].f],0,z[i].f+1);
} else {
cnt=sum(st[z[i].f],z[j-1].f+1,z[i].f+1);
}
dp[i+1]=max(dp[i+1],dp[j]-cnt);
}
dp[i+1]+=z[i].f*z[i].s;
if (dp[i+1]>0) return 0;
}
return 1;
}
Compilation message (stderr)
teams.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
3 | #pragma target("avx2,bvx")
|
teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:69:12: warning: declaration of 't' shadows a global declaration [-Wshadow]
69 | auto t=add(st[i],a[x].f,1);
| ^
teams.cpp:18:5: note: shadowed declaration is here
18 | sgt t[K];
| ^
teams.cpp: In function 'int can(int, int*)':
teams.cpp:90:7: warning: declaration of 't' shadows a global declaration [-Wshadow]
90 | int t=z.size();
| ^
teams.cpp:18:5: note: shadowed declaration is here
18 | sgt t[K];
| ^
teams.cpp:90:15: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
90 | int t=z.size();
| ~~~~~~^~
# | 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... |