제출 #135034

#제출 시각아이디문제언어결과실행 시간메모리
135034evpipis팀들 (IOI15_teams)C++11
0 / 100
1439 ms356284 KiB
#include "teams.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
const int len = 5e5+5;
vector<int> stud[len];
int team[len], n;

struct node{
    int sum;
    node *left, *right;

    node(int s = 0, node *l = NULL, node *r = NULL){
        sum = s;
        left = l;
        right = r;
    }
};

typedef node* pnode;
pnode null = new node(), root[len];

pnode update(pnode t, int l, int r, int i){
    if (l == r)
        return new node(t->sum+1, null, null);

    int mid = (l+r)/2;
    if (i <= mid)
        return new node(t->sum+1, update(t->left, l, mid, i), t->right);
    return new node(t->sum+1, t->left, update(t->right, mid+1, r, i));
}

int ask(pnode t, int l, int r, int i, int j){
    if (r < i || j < l || i > j)
        return 0;
    if (i <= l && r <= j)
        return t->sum;

    int mid = (l+r)/2;
    return ask(t->left, l, mid, i, j) + ask(t->right, mid+1, r, i, j);
}

void init(int N, int A[], int B[]){
    n = N;
    for (int i = 0; i < n; i++)
        stud[A[i]].pb(B[i]);

    root[0] = null->left = null->right = null;
    for (int i = 1; i <= n; i++){
        root[i] = root[i-1];
        for (int j = 0; j < stud[i].size(); j++)
            root[i] = update(root[i], 1, n, stud[i][j]);
    }
}

int can(int m, int K[]){
    for (int i = 0; i < m; i++)
        team[i] = K[i];
    team[m] = n+1;

    sort(team, team+m);

    int cnt = 0, ans = 1;
    for (int i = 0; i < m; i++){
        int pos1 = team[i], pos2 = team[i+1];
        int a = ask(root[pos1], 1, n, pos1, pos2-1);
        int b = ask(root[pos1], 1, n, pos2, n);

        cnt += pos1;
        if (cnt > a+b)
            ans = 0;
        else
            cnt = max(0, cnt-a);
    }

	return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:52:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < stud[i].size(); j++)
                         ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...