이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Power Of Ninja Go
#include <bits/stdc++.h>
#ifdef atom
#include "grader.cpp"
#else
#include "teams.h"
#endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vii vector< ii >
#define pb push_back
const int maxn = 5e5+5;
int n;
int a[maxn], b[maxn];
vii vec;
void init(int N, int A[], int B[])
{
srand(time(NULL));
n = N;
for(int i = 0; i< N; i++) a[i] = A[i], b[i] = B[i];
for(int i = 0; i< N; i++) vec.pb(ii(a[i], b[i]));
sort(vec.begin(), vec.end());
}
struct node
{
int v, prio, cnt;
node *left, *right;
node(int _v)
{
v = _v;
prio = (rand()<<16)^rand();
left = right = NULL;
up();
}
void up()
{
cnt = 1+(left?left->cnt:0)+(right?right->cnt:0);
}
};
node* merge(node *L, node *R)
{
if(!L or !R) return L?L:R;
if(L->prio > R->prio)
{
L->right = merge(L->right, R);
L->up(); return L;
}
else
{
R->left = merge(L, R->left);
R->up(); return R;
}
}
void splitKey(node *cur, node* &L, node* &R, int key)
{
L = R = NULL;
if(!cur) return;
if(cur->v<= key)
{
L = cur;
splitKey(cur->right, cur->right, R, key);
}
else
{
R = cur;
splitKey(cur->left, L, cur->left, key);
}
cur->up();
}
void splitCnt(node *cur, node* &L, node* &R, int key)
{
L = R = NULL;
if(!cur) return;
int yo = 1+(cur->left?cur->left->cnt:0);
if(yo<= key)
{
L = cur;
splitCnt(cur->right, cur->right, R, key-yo);
}
else
{
R = cur;
splitCnt(cur->left, L, cur->left, key);
}
cur->up();
}
node *root;
void add(int x)
{
if(!root)
{
root = new node(x);
return;
}
node *temp = NULL;
splitKey(root, root, temp, x);
root = merge(root, new node(x));
root = merge(root, temp);
}
int ask(int x, int num)
{
node *temp;
if(!root) return -1;
if(root->cnt< num) return -1;
splitKey(root, root, temp, x-1);
if(!temp) return -1;
if((temp->cnt)< num) return -1;
node *rubbish;
splitCnt(temp, rubbish, temp, num);
root = merge(root, temp);
return 1;
}
int can(int M, int K[])
{
int sum = 0;
for(int i = 0; i< M; i++) sum += K[i];
if(sum> n) return 0;
sort(K, K+M);
int ptr = 0;
root = NULL;
for(int i = 0; i< M; i++)
{
int here = K[i];
while(ptr< n && vec[ptr].X<= here) add(vec[ptr++].Y);
//printf("size isss s%d\n", root->cnt);
if(ask(here, here) == -1) return 0;
}
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:21:18: warning: conversion to 'unsigned int' from 'time_t {aka long int}' may alter its value [-Wconversion]
srand(time(NULL));
^
# | 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... |