Submission #415591

# Submission time Handle Problem Language Result Execution time Memory
415591 2021-06-01T09:08:38 Z CSQ31 Dancing Elephants (IOI11_elephants) C++14
26 / 100
52 ms 2352 KB
#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(a) a.begin(),a.end()
#define sz(a) (int)(a.size())
#define ub upper_bound
typedef long long int ll;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
typedef pair<int,int> pii;
ll n,l;
VII bucket,reach,cnt;
vector<ll>x,comp;
ll blk = 500,num;
ll find(ll cur,ll val){
	ll l = 0,r = sz(bucket[cur])-1;
	while(r>=l){
		ll mid = (l+r)/2;
		if(x[bucket[cur][mid]] <= val)l = mid+1;
		else r = mid-1;
	}
	return l;
}
void build1(vector<ll>a,ll cur){
	if(cur == sz(bucket)){
		bucket.pb(a);
		reach.pb(a);
		cnt.pb(a);
	}else bucket[cur] = reach[cur] = cnt[cur] = a;
	ll last = bucket[cur].back();
	for(ll i=sz(a)-1;i>=0;i--){
		ll v = bucket[cur][i];
		comp[v] = cur;
		if(x[v]+l >= x[last]){
			reach[cur][i] = x[v]+l;
			cnt[cur][i] = 1;
		}else{
			ll p = find(cur,x[v]+l);
			reach[cur][i] = reach[cur][p];
			cnt[cur][i] = cnt[cur][p]+1;
			
		}
	}
}
void build2(){
	bucket.clear();
	cnt.clear();
	reach.clear();
	vector<pii>a;
	for(ll i=0;i<n;i++)a.pb({x[i],i});
	sort(all(a));
	for(ll i=0,j=0;i<n;i+=blk,j++){
		vector<ll>b;
		for(ll k=i;k<min(n,i+blk);k++)b.pb(a[k].second);
		build1(b,j);
	}
}
void init(int N, int L, int X[])
{
  n = N;
  l = L;
  x.resize(n);
  comp.resize(n);
  for(ll i=0;i<n;i++)x[i] = X[i];
  build2();
}

int update(int i, int y)
{
	if(num == blk-1)build2();
	else{
		num%=blk;
		ll c = comp[i];
		vector<ll>a;
		for(ll x:bucket[c]){
			if(x != i)a.pb(x);
		}
		build1(a,c);
		x[i] = y;
		for(ll i=0;i<sz(bucket);i++){
			if(y <= x[bucket[i].back()]){
				c = i;
				break;
			}
		}
		a = bucket[c];
		a.pb(i);
		sort(all(a),[&](const ll &i,const ll &j){return x[i] < x[j];});
		build1(a,c); 
	}
		ll ans = cnt[0][0];
		ll cur = reach[0][0];
		for(ll i=1;i<sz(bucket);i++){
			if(cur >= x[bucket[i].back()])continue;
			ll idx = find(i,cur);
			cur = reach[i][idx];
			ans+=cnt[i][idx];
		}
  //for(ll i=0;i<n;i++)cout<<x[bucket[0][i]]<<" "<<reach[0][i]<<" "<<cnt[0][i]<<'\n';
   num++;
   return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 52 ms 2352 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 52 ms 2352 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 52 ms 2352 KB Output isn't correct
8 Halted 0 ms 0 KB -