답안 #938853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938853 2024-03-05T17:01:27 Z pan 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
97 / 100
1699 ms 42752 KB
#include "elephants.h"
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include "bits_stdc++.h"
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
// general
ll range;
vector<ll> x;
unordered_map<ll, ll> m;
// SQRT Data Structure
ll const blksz = 300;
ll blk;
vector<vector<ll> > groups;
vector<vector<pi> > dp;
ll query()
{
	//show(4);
	ll ret = 0;
	ll last = -1;
	for (ll i=0; i<blk; ++i)
	{
		if (groups[i].empty() || groups[i].back()<=last) continue;
		ll ind = ub(groups[i].begin(), groups[i].end(), last)-groups[i].begin();
		ret+=dp[i][ind].f;
		last = dp[i][ind].s;
	}
	return ret;
}
void processblk(ll ind)
{
	//show(3);
	if (groups[ind].empty()) return;
	ll n= groups[ind].size();
	dp[ind].clear();
	dp[ind].resize(n);
	ll r = n-1;
	for (ll l = n-1; l>=0; --l)
	{
		while (groups[ind][r]-groups[ind][l]>range) {r--;}
		if (r==n-1) dp[ind][l] = mp(1, groups[ind][l] + range);
		else  dp[ind][l] = dp[ind][r+1], dp[ind][l].f++;
	}
}
void remove(ll pos)
{
	//show(1);
	ll i;
	for (i=0; i<blk; ++i)
	{
		if (groups[i].empty()) continue;
		if (groups[i][0]<=pos && groups[i].back()>=pos) break;
	}
	groups[i].erase(lb(groups[i].begin(), groups[i].end(), pos));
	processblk(i);
}
void insert(ll pos)
{
	//show(1);
	ll i;
	for (i=0; i<blk; ++i)
	{
		if (groups[i].empty()) continue;
		if (groups[i][0]>=pos) break;
	}
	if (i) i--;
	groups[i].insert(ub(groups[i].begin(), groups[i].end(), pos), pos);
	if (groups[i].size()>=2*blksz)
	{
		vector<ll> neww;
		vector<pi> emp;
		ll half = groups[i].size()/2;
		while (half--) {neww.pb(groups[i].back()); groups[i].pop_back();}
		reverse(neww.begin(), neww.end());
		groups.insert(groups.begin()+i+1, neww);
		dp.insert(dp.begin()+i+1, emp);
		processblk(i);
		processblk(i+1);
		blk++;
	}
	else {processblk(i);}
}

void init(int N, int L, int X[])
{
	sort(X, X+N);
	range = L;
	x.resize(N);
	blk = (N-1)/blksz + 1;
	groups.resize(blk);
	dp.resize(blk);
	for (ll i=0; i<N; ++i) 
	{
		m[X[i]]++;
		if (m[X[i]]==1) groups[i/blksz].pb(X[i]);
	}
	for (ll i=0; i<blk; ++i) processblk(i);
	for (ll i=0; i<N; ++i) x[i] = X[i];
}
int update(int i, int y)
{
	//show("FUCK");
	m[x[i]]--; m[y]++;
	if (m[x[i]]==0) remove(x[i]);
	if (m[y]==1) insert(y);
	x[i] = y;
	return query();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6592 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6592 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 126 ms 12356 KB Output is correct
8 Correct 146 ms 12808 KB Output is correct
9 Correct 190 ms 14468 KB Output is correct
10 Correct 242 ms 18408 KB Output is correct
11 Correct 192 ms 18192 KB Output is correct
12 Correct 314 ms 18116 KB Output is correct
13 Correct 226 ms 18236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6592 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 126 ms 12356 KB Output is correct
8 Correct 146 ms 12808 KB Output is correct
9 Correct 190 ms 14468 KB Output is correct
10 Correct 242 ms 18408 KB Output is correct
11 Correct 192 ms 18192 KB Output is correct
12 Correct 314 ms 18116 KB Output is correct
13 Correct 226 ms 18236 KB Output is correct
14 Correct 129 ms 15204 KB Output is correct
15 Correct 217 ms 15692 KB Output is correct
16 Correct 461 ms 17336 KB Output is correct
17 Correct 505 ms 20676 KB Output is correct
18 Correct 523 ms 21056 KB Output is correct
19 Correct 305 ms 20780 KB Output is correct
20 Correct 569 ms 20736 KB Output is correct
21 Correct 551 ms 21136 KB Output is correct
22 Correct 392 ms 21960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6592 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 126 ms 12356 KB Output is correct
8 Correct 146 ms 12808 KB Output is correct
9 Correct 190 ms 14468 KB Output is correct
10 Correct 242 ms 18408 KB Output is correct
11 Correct 192 ms 18192 KB Output is correct
12 Correct 314 ms 18116 KB Output is correct
13 Correct 226 ms 18236 KB Output is correct
14 Correct 129 ms 15204 KB Output is correct
15 Correct 217 ms 15692 KB Output is correct
16 Correct 461 ms 17336 KB Output is correct
17 Correct 505 ms 20676 KB Output is correct
18 Correct 523 ms 21056 KB Output is correct
19 Correct 305 ms 20780 KB Output is correct
20 Correct 569 ms 20736 KB Output is correct
21 Correct 551 ms 21136 KB Output is correct
22 Correct 392 ms 21960 KB Output is correct
23 Correct 1699 ms 33892 KB Output is correct
24 Correct 1533 ms 33516 KB Output is correct
25 Correct 1296 ms 32968 KB Output is correct
26 Correct 1504 ms 42752 KB Output is correct
27 Correct 1306 ms 39164 KB Output is correct
28 Incorrect 36 ms 15692 KB Output isn't correct
29 Halted 0 ms 0 KB -