Submission #192442

# Submission time Handle Problem Language Result Execution time Memory
192442 2020-01-15T06:07:48 Z kdh9949 Dancing Elephants (IOI11_elephants) C++17
100 / 100
2854 ms 12468 KB
#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;

#define b_size (400)

int n, l, m;
int x[150010], v[150010];
int bnum;
int ucnt;

struct Bucket{
  int sz;
  int x[2 * b_size + 1];
  int num[2 * b_size + 1];
  int bound[2 * b_size + 1];
  void calc(){
		int t = sz;
    for(int i = sz - 1; i >= 0; i--){
      while(t > 0 && x[t - 1] > x[i] + l) t--;
			if(t == sz) num[i] = 1, bound[i] = x[i] + l;
      else num[i] = num[t] + 1, bound[i] = bound[t];
    }
  }
  void ins(int y){
    int p = (int)(upper_bound(x, x + sz, y) - x);
    sz++;
    for(int i = sz - 1; i > p; i--) x[i] = x[i - 1];
    x[p] = y;
    calc();
  }
  void del(int y){
    int p = (int)(lower_bound(x, x + sz, y) - x);
    sz--;
    for(int i = p; i < sz; i++) x[i] = x[i + 1];
    calc();
  }

}b[b_size + 1];

void init(int n, int l, int x[]){
  ::n = n;
  ::l = l;
  for(int i = 0; i < n; i++) ::x[i] = x[i];
	for(int i = 0; i < n; i += b_size){
    for(int j = i; j < n && j < i + b_size; j++){
      b[bnum].x[b[bnum].sz++] = x[j];
    }
    b[bnum++].calc();
  }
}

void rebucket(){
  int cnt = 0;
  for(int i = 0; i < bnum; i++){
    for(int j = 0; j < b[i].sz; j++){
      v[cnt++] = b[i].x[j];
    }
  }
  bnum = 0;
  for(int i = 0; i < n; i += b_size){
    b[bnum].sz = 0;
    for(int j = i; j < n && j < i + b_size; j++){
      b[bnum].x[b[bnum].sz++] = v[j];
    }
    b[bnum++].calc();
  }
}

int update(int i, int y){
  int pv = x[i];
  x[i] = y;
  for(int i = 0; i < bnum; i++){
    if(b[i].sz == 0) continue;
    if(b[i].x[0] <= pv && b[i].x[b[i].sz - 1] >= pv){b[i].del(pv); break;}
  }
  for(int i = 0; i < bnum; i++){
    if(b[i].sz == 0) continue;
    if((i == 0 || b[i].x[0] <= y) && (i == bnum - 1 || b[i + 1].x[0] > y)){b[i].ins(y); break;}
  }
  int ret = 0;
  int lst = -1;
  for(int i = 0; i < bnum; i++){
    if(lst >= b[i].x[b[i].sz - 1]) continue;
    if(lst < b[i].x[0]){ret += b[i].num[0]; lst = b[i].bound[0];}
    else{
      int p = (int)(upper_bound(b[i].x, b[i].x + b[i].sz, lst) - b[i].x);
      ret += b[i].num[p]; lst = b[i].bound[p];
    }
  }
  ucnt++;
  if(ucnt % (b_size - 5) == 0) rebucket();
  return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 245 ms 2340 KB Output is correct
8 Correct 260 ms 2680 KB Output is correct
9 Correct 279 ms 4328 KB Output is correct
10 Correct 290 ms 4136 KB Output is correct
11 Correct 276 ms 3940 KB Output is correct
12 Correct 531 ms 4272 KB Output is correct
13 Correct 313 ms 3932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 245 ms 2340 KB Output is correct
8 Correct 260 ms 2680 KB Output is correct
9 Correct 279 ms 4328 KB Output is correct
10 Correct 290 ms 4136 KB Output is correct
11 Correct 276 ms 3940 KB Output is correct
12 Correct 531 ms 4272 KB Output is correct
13 Correct 313 ms 3932 KB Output is correct
14 Correct 249 ms 3392 KB Output is correct
15 Correct 407 ms 3576 KB Output is correct
16 Correct 935 ms 4796 KB Output is correct
17 Correct 905 ms 5728 KB Output is correct
18 Correct 1029 ms 5724 KB Output is correct
19 Correct 576 ms 5872 KB Output is correct
20 Correct 912 ms 5752 KB Output is correct
21 Correct 884 ms 5692 KB Output is correct
22 Correct 607 ms 5292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 245 ms 2340 KB Output is correct
8 Correct 260 ms 2680 KB Output is correct
9 Correct 279 ms 4328 KB Output is correct
10 Correct 290 ms 4136 KB Output is correct
11 Correct 276 ms 3940 KB Output is correct
12 Correct 531 ms 4272 KB Output is correct
13 Correct 313 ms 3932 KB Output is correct
14 Correct 249 ms 3392 KB Output is correct
15 Correct 407 ms 3576 KB Output is correct
16 Correct 935 ms 4796 KB Output is correct
17 Correct 905 ms 5728 KB Output is correct
18 Correct 1029 ms 5724 KB Output is correct
19 Correct 576 ms 5872 KB Output is correct
20 Correct 912 ms 5752 KB Output is correct
21 Correct 884 ms 5692 KB Output is correct
22 Correct 607 ms 5292 KB Output is correct
23 Correct 2288 ms 12444 KB Output is correct
24 Correct 2503 ms 12468 KB Output is correct
25 Correct 1447 ms 12464 KB Output is correct
26 Correct 2344 ms 12412 KB Output is correct
27 Correct 2386 ms 12288 KB Output is correct
28 Correct 1510 ms 5264 KB Output is correct
29 Correct 1427 ms 5248 KB Output is correct
30 Correct 1499 ms 5252 KB Output is correct
31 Correct 1415 ms 5244 KB Output is correct
32 Correct 1870 ms 11892 KB Output is correct
33 Correct 1131 ms 11232 KB Output is correct
34 Correct 1776 ms 12152 KB Output is correct
35 Correct 1077 ms 12408 KB Output is correct
36 Correct 1004 ms 11876 KB Output is correct
37 Correct 1964 ms 12292 KB Output is correct
38 Correct 2409 ms 11148 KB Output is correct
39 Correct 2112 ms 12240 KB Output is correct
40 Correct 2492 ms 11132 KB Output is correct
41 Correct 2833 ms 11872 KB Output is correct
42 Correct 2854 ms 12148 KB Output is correct