Submission #919893

# Submission time Handle Problem Language Result Execution time Memory
919893 2024-02-01T19:59:53 Z Lobo Dancing Elephants (IOI11_elephants) C++17
26 / 100
9000 ms 12584 KB
#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
const int maxn = 7e4+10;
const int lg = 20;
const int B = 187;
int n,s;
set<int> espx;
set<pair<pair<int,int>,int>> pts, newpts;
vector<int> x;
int d[maxn][lg+1];

void init(int N, int L, int X[])
{
    n = N;
    s = L;
    for(int i = 0; i < n; i++) {
    	pts.insert(mp(mp(X[i],i),0));
    	x.pb(X[i]);
    }
}
int cntq = 0;
int update(int iq, int xq)
{
	if(cntq == 0) {
		vector<pair<pair<int,int>,int>> rem,add;
		for(auto X : pts) {
			if(X.sc == 1) {
				rem.pb(X);
				add.pb(mp(X.fr,0));
			}
		}
		espx.clear();
		for(auto X : rem) pts.erase(X);
		for(auto X : add) pts.insert(X);

		for(int i = 0; i < n; i++) {
			d[i][0] = x[i]+s;
		}

		for(int b = 1; b <= lg; b++) {
			for(int i = 0; i < n; i++) {
				auto it = pts.upper_bound(mp(mp(d[i][b-1],n+1),n+1));
				if(it == pts.end()) {
					d[i][b] = d[i][b-1]+(1<<(b-1))*s;
				}
				else {
					d[i][b] = d[it->fr.sc][b-1];
				}
			}
		}
	}

	pts.erase(mp(mp(x[iq],iq),0));
	pts.erase(mp(mp(x[iq],iq),1));
	espx.insert(x[iq]);
	// pts.insert(mp(mp(x[iq],iq),-1));
	x[iq] = xq;
	pts.insert(mp(mp(x[iq],iq),1));

	int pos = -1;
	int ans = 0;
	while(true) {
		auto it = pts.upper_bound(mp(mp(pos,n+1),n+1));
		if(it == pts.end()) break;
		int i = it->fr.sc;
		pos = x[i];
		int nxt = *espx.upper_bound(pos);

		// if(it->sc == 0) {
		// 	for(int b = lg; b >= 0; b--) {
		// 		if(d[i][b] < nxt) {
		// 			pos = d[i][b];
		// 			ans+= (1<<b);
		// 			it = pts.upper_bound(mp(mp(pos,n+1),n+1));
		// 			if(it == pts.end()) {
		// 				i = -1;
		// 				break;
		// 			}
		// 			i = it->fr.sc;
		// 		}
		// 	}
		// }

		if(i != -1) {
			pos = pos+s;
			ans+= 1;
		}
	}
	cntq = (cntq+1)%B;
  	return ans;
}

Compilation message

elephants.cpp: In function 'int update(int, int)':
elephants.cpp:72:7: warning: unused variable 'nxt' [-Wunused-variable]
   72 |   int nxt = *espx.upper_bound(pos);
      |       ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 1 ms 8536 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 1 ms 8536 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 1 ms 8536 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Execution timed out 9042 ms 12584 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 1 ms 8536 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Execution timed out 9042 ms 12584 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 1 ms 8536 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Execution timed out 9042 ms 12584 KB Time limit exceeded
8 Halted 0 ms 0 KB -