Submission #498633

# Submission time Handle Problem Language Result Execution time Memory
498633 2021-12-25T22:07:06 Z sidon Dancing Elephants (IOI11_elephants) C++17
10 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;
#include "elephants.h"
 
const int MAX_N = 150'000, NB = 500, INF = 2e9;
 
int N, L, X[MAX_N], num[MAX_N], pos[MAX_N], st[NB];
int B;

vector<int> a[NB], b[NB];
 
void recalculate(int j) {
	auto &c = a[j];
 
	st[j] = INF;
	if(empty(c)) return;
	st[j] = b[j][0];
 
	int sz = size(c), pt = sz;
 
	for(int i = sz; --i >= 0 ; ) {
		while(pt && X[c[i]] + L < X[c[pt-1]]) --pt;
 
		num[c[i]] = pt < sz ? num[c[pt]] + 1 : 1;
		pos[c[i]] = pt < sz ? pos[c[pt]] : X[c[i]] + L;
	}
}
 
void reset() {
	int pt = 0;
 
	for(int i = 0; i < NB; i++) {
		for(int &v : a[i]) pos[pt++] = v;
		a[i].clear();
		b[i].clear();
	}
 
	for(int i = 0; i < N; i++) {
		a[i/B].push_back(pos[i]);
		b[i/B].push_back(X[pos[i]]);
	}
 
	for(int i = 0; i < NB; i++)
		recalculate(i);
}
 
void init(int n, int l, int x[]) {
	N = n, L = l, B = (N + NB - 1) / NB;
	for(int i = 0; i < N; i++) {
		X[i] = x[i];
		a[i/B].push_back(i);
	}
	reset();
}
 
int l, p, q_;
 
void locate(int i){
	l = upper_bound(st, st+NB, X[i]) - st - 1;
	if(l < 0) l = 0;
	p = lower_bound(begin(b[l]), end(b[l]), X[i]) - begin(b[l]);
}
 
int update(int i, int y) {
	locate(i);
	while(a[l][p] != i) ++p;
	a[l].erase(begin(a[l]) + p);
	b[l].erase(begin(b[l]) + p);
	recalculate(l);
 
	X[i] = y;
 
	locate(i);
 
	a[l].insert(begin(a[l]) + p, i);
	b[l].insert(begin(b[l]) + p, X[i]);
	recalculate(l);
 
	if(!(++q_ % B)) reset();
 
	int res = 0, cur = -1;
 
	for(int k = 0; k < NB; k++) {
		if(st[k] == INF) break;
		if(empty(b[k]) || cur >= b[k].back()) continue;
 
		int j = upper_bound(begin(b[k]), end(b[k]), cur) - begin(b[k]);
 
		res += num[a[k][j]];
		cur = pos[a[k][j]];
	}
 
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -