답안 #197096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197096 2020-01-18T15:34:45 Z stefdasca 코끼리 (Dancing Elephants) (IOI11_elephants) C++14
컴파일 오류
0 ms 0 KB
#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;

int bucket_size = 550;
int n, l, *x, updatecount, bc, r[300];
map<int, int> mp;
vector<int> v[300];
vector<array<int, 2>> w[300];

void init(int N, int L, int X[])
{
    n=N, l=L, x=X;
    for(int i=0; i<n; ++i)
        ++mp[x[i]];
}

void bb(int i)
{
    w[i] = vector<array<int, 2>>(v[i].size());
    for(int j1=(int)v[i].size()-1, j2=v[i].size(); ~j1; --j1)
    {
        while(v[i][j2-1] > v[i][j1]+l)
            --j2;
        if(j2 < v[i].size())
            w[i][j1] = array<int, 2> {w[i][j2][0]+1, w[i][j2][1]};
        else
            w[i][j1] = array<int, 2> {1, v[i][j1]+l};
    }
}
void bld()
{
    bc=0;
    for(pair<int, int> p : mp)
    {
        if(!bc || v[bc-1].size() >= bucket_size)
            ++bc, v[bc].clear();
        v[bc-1].push_back(p.first);
    }
    for(int i = 0; i < bc; ++i)
    {
        if(i+1 < bc)
            r[i] = v[i+1][0]-1:
        else
            r[i] = 1e9;
        bb(i);
    }
}

void upd(int x, bool a)
{
    int c = -1;
    while(x > r[++c]);
    int p=lower_bound(v[c].begin(), v[c].end(), x)-v[c].begin();
    if(a)
        v[c].insert(v[c].begin()+p, x);
    else
        v[c].erase(v[c].begin()+p);
    bb(c);
}

int update(int i, int y)
{
    ++updatecount;
    if(updatecount % bucket_size ==0)
        bld();
    --mp[x[i]];
    if(!mp[x[i]])
    {
        upd(x[i], 0);
        mp.erase(x[i]);
    }
    if(!mp[y])
        upd(y, 1);
    ++mp[y];
    x[i]=y;
    int a=0;
    for(int i=0, c=-1; i<bc; ++i)
    {
        int p=upper_bound(v[i].begin(), v[i].end(), c)-v[i].begin();
        if(p<v[i].size())
        {
            a+=w[i][p][0];
            c=w[i][p][1];
        }
    }
    return a;
}

Compilation message

elephants.cpp: In function 'void bb(int)':
elephants.cpp:25:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(j2 < v[i].size())
            ~~~^~~~~~~~~~~~~
elephants.cpp: In function 'void bld()':
elephants.cpp:36:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(!bc || v[bc-1].size() >= bucket_size)
                   ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
elephants.cpp:43:31: error: expected ';' before ':' token
             r[i] = v[i+1][0]-1:
                               ^
elephants.cpp: In function 'int update(int, int)':
elephants.cpp:81:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(p<v[i].size())
            ~^~~~~~~~~~~~