이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "teams.h"
#include <bits/stdc++.h>
using namespace std;
template<class T>
void readi(T &x)
{
T input = 0;
bool negative = false;
char c = ' ';
while (c < '-')
{
c = getchar();
}
if (c == '-')
{
negative = true;
c = getchar();
}
while (c >= '0')
{
input = input * 10 + (c - '0');
c = getchar();
}
if (negative)
{
input = -input;
}
x = input;
}
template<class T>
void printi(T output)
{
if (output == 0)
{
putchar('0');
return;
}
if (output < 0)
{
putchar('-');
output = -output;
}
int aout[20];
int ilen = 0;
while(output)
{
aout[ilen] = ((output % 10));
output /= 10;
ilen++;
}
for (int i = ilen - 1; i >= 0; i--)
{
putchar(aout[i] + '0');
}
return;
}
template<class T>
void ckmin(T &a, T b)
{
a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
a = max(a, b);
}
long long randomize(long long mod)
{
return ((1ll << 30) * rand() + (1ll << 15) * rand() + rand()) % mod;
}
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-20;
#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 500013
long long normalize(long long x, long long mod = INF)
{
return (((x % mod) + mod) % mod);
}
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int N, M;
pii want[MAXN];
int ok[MAXN];
vector<pii> arr;
int tree[MAXN];
int dp[MAXN];
int get(int idx)
{
int sum = 0ll;
for (int e = idx; e > 0; e -= (e & (-e)))
{
sum += tree[e];
}
return sum;
}
void update(int idx, ll val)
{
for (int e = idx; e <= N; e += (e & (-e)))
{
tree[e] += val;
}
return;
}
int T;
struct node
{
node *lchild, *rchild;
int sum;
node()
{
lchild = rchild = nullptr;
sum = 0;
}
};
node *root[MAXN];
int ft[MAXN];
node* initpseg(int L, int R)
{
node *t = new node();
if (L == R)
{
return t;
}
int mid = (L + R) / 2;
t -> lchild = initpseg(L, mid);
t -> rchild = initpseg(mid + 1, R);
return t;
}
node* update(node *w, int L, int R, int x, int v)
{
if (x < L || R < x)
{
return w;
}
node *t = new node();
if (L == R)
{
t -> sum = w -> sum + v;
t -> lchild = t -> rchild = nullptr;
return t;
}
int mid = (L + R) / 2;
t -> lchild = update(w -> lchild, L, mid, x, v);
t -> rchild = update(w -> rchild, mid + 1, R, x, v);
t -> sum = t -> lchild -> sum + t -> rchild -> sum;
return t;
}
int query(node *t, int L, int R, int a, int b)
{
if (b < L || R < a)
{
return 0;
}
if (a <= L && R <= b)
{
return t -> sum;
}
int mid = (L + R) / 2;
return query(t -> lchild, L, mid, a, b) + query(t -> rchild, mid + 1, R, a, b);
}
int rect(int X1, int X2, int Y1, int Y2)
{
return query(root[ft[X2]], 0, N, Y1, Y2) - query(root[ft[X1 - 1]], 0, N, Y1, Y2);
}
void init(int n, int A[], int B[])
{
N = n;
for (int i = 0; i < N; i++)
{
want[i] = MP(A[i], B[i]);
}
sort(want, want + N);
root[0] = initpseg(0, N);
T = 1;
for (int i = 0; i < N; i++)
{
if (i)
{
for (int j = want[i - 1].fi; j < want[i].fi; j++)
{
ft[j] = T - 1;
}
}
else
{
for (int j = 0; j < want[i].fi; j++)
{
ft[j] = T - 1;
}
}
ft[want[i].fi] = T;
// cerr << "update time " << want[i].fi << " value " << want[i].se << endl;
root[T] = update(root[T - 1], 0, N, want[i].se, 1);
T++;
}
for (int j = want[N - 1].fi; j <= N; j++)
{
ft[j] = T - 1;
}
}
int can(int m, int k[])
{
M = m;
sort(k, k + M);
int s = 0;
for (int i = 0; i < M; i++)
{
s += k[i];
}
if (s > N)
{
return 0;
}
arr.clear();
arr.reserve(M);
for (int i = 0; i < M; i++)
{
if (i == 0 || k[i] != k[i - 1])
{
arr.PB(MP(k[i], 1));
}
else
{
arr.back().se++;
}
}
M = arr.size();
for (int i = 0; i < M; i++)
{
dp[i] = INF;
}
for (int i = 0; i < M; i++)
{
int sz = arr[i].fi;
int cur = 0;
// for (int j = 0; j < N; j++)
// {
// if (want[j].fi <= sz && want[j].se >= sz)
// {
// cur++;
// }
// }
cur = rect(1, sz, sz, INF);
//(0, sz); (sz, INF)
dp[i] = cur;
for (int j = 0; j < i; j++)
{
cur = dp[j] + rect(arr[j].fi + 1, sz, sz, INF);
//(arr[j].fi + 1, sz); (sz, INF)
// for (int k = 0; k < N; k++)
// {
// if (arr[j].fi < want[k].fi && want[k].fi <= sz && want[k].se >= sz)
// {
// cur++;
// }
// }
ckmin(dp[i], cur);
}
// cerr << dp[i] << endl;
dp[i] -= arr[i].fi * arr[i].se;
if (dp[i] < 0)
{
return 0;
}
}
//for this subset, if the # of distinct people that can enter at least one of them is less than its sum, its bad
//there are at most sqrtN distinct guys
return 1;
//check if the sum of values in subset of k's is < sum cnt's of those k's
//you need to make a team if
}
컴파일 시 표준 에러 (stderr) 메시지
teams.cpp: In function 'void update(int, ll)':
teams.cpp:125:11: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
tree[e] += val;
~~~~~~~~^~~~~~
teams.cpp: In function 'int can(int, int*)':
teams.cpp:255:14: warning: conversion to 'int' from 'std::vector<std::pair<int, int> >::size_type {aka long unsigned int}' may alter its value [-Wconversion]
M = arr.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... |