답안 #748035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748035 2023-05-25T10:26:16 Z Dan4Life 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second

const int mxN = (int)1.5e5+10;
const int INF = (int)1e9+10;
const int B = 300;
const int nmB = INF/B+2;

unordered_map<int,set<int>> pos; //sz = nmB
int n, L, p[mxN/B];
unordered_map<int,int> b;
unordered_map<int,set<array<int,3>>> block;

void reUpd(int ind){
    block[ind].clear();
    auto itr = end(pos[ind]);
    while(itr!=begin(pos[ind])){
        itr--;
        auto itr2 = block[ind].lower_bound({*itr+L+1,-1,-1});
        if(itr2!=block[ind].end()){
            auto obj = *itr2;
            block[ind].insert({*itr,1+obj[1],obj[2]});
        }
        else block[ind].insert({*itr,1,*itr+L+1});
    }
}

void ins(int x){
    b[x]++; if(b[x]!=1) return;
    int ind = x/B; pos[ind].insert(x); reUpd(ind);
}

void del(int x){
    b[x]--; if(b[x]) return;
    int ind = x/B; pos[ind].erase(x); reUpd(ind);
}

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

int update(int i, int y)
{
    del(p[i]); p[i]=y; ins(y);
    int ans = 0, cur = 0;
    for(int i = 0; i < nmB; i++){
        auto itr = block[i].lower_bound({cur,-1,-1});
        if(itr!=block[i].end()) ans+=(*itr)[1], cur = (*itr)[2];
    }
    return ans;
}












#define MAX_N 1000000
#define MAX_M 1000000
static int N,LL,M;
static int X[MAX_N];
static int ii[MAX_M];
static int yy[MAX_M];
static int sol[MAX_M];
inline void my_assert(int e) {if (!e) abort();}
void read_input()
{
  int i;
  my_assert(3==scanf("%d %d %d",&N,&LL,&M));
  for(i=0; i<N; i++)
    my_assert(1==scanf("%d",&X[i]));
  for(i=0; i<M; i++)
    my_assert(3==scanf("%d %d %d",&ii[i],&yy[i],&sol[i]));
}

int main()
{
  int i, ans;

  read_input();
  init(N,LL,X);
  for(i=0; i<M; i++) {
    ans = update(ii[i],yy[i]);
    if(ans==sol[i])continue;
      printf("Incorrect.  In %d-th move, answered %d (%d expected).\n",
	     i+1, ans, sol[i]);
    return 0;
  }
  printf("Correct.\n");
  return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccds15Fn.o: in function `read_input()':
grader.cpp:(.text+0x0): multiple definition of `read_input()'; /tmp/cccDtrvp.o:elephants.cpp:(.text+0x3a0): first defined here
/usr/bin/ld: /tmp/ccds15Fn.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cccDtrvp.o:elephants.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status