#pragma GCC optimize ("-O3")
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include "elephants.h"
using namespace std;
#define INF 1145141919
#define rep(i, n) for (int i=0; i<(n); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define _1 first
#define _2 second
typedef pair<int, int> P;
int N, L;
int A[150001];
set<P> B;
int fwd[150001];
void init(int n, int l, int X[]) {
N = n, L = l;
B.insert(P(INF, -1));
rep(i, N) B.insert(P(A[i] = X[i], i));
rep(i, N) fwd[i] = i+1;
fwd[N-1] = -1;
}
int update(int i, int y) {
// remove A[i]
auto it = B.find(P(A[i], i));
if (it != B.begin()) {
int prv = (--it)->_2;
fwd[prv] = fwd[i];
it++;
}
B.erase(it);
// insert y
A[i] = y;
auto it2 = B.insert(P(A[i], i))._1;
auto prv(it2);
if (prv != B.begin()) {
prv--;
fwd[prv->_2] = i;
}
it2++;
fwd[i] = (it2)->_2;
//
int head = B.begin()->_2;
int until = A[head]+L, c = 1;
for (int i=head; i!=-1; i=fwd[i]) {
if (A[i] > until) until = A[i]+L, c++;
}
return c;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
18816 KB |
Output is correct |
2 |
Correct |
0 ms |
18816 KB |
Output is correct |
3 |
Correct |
0 ms |
18816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
18816 KB |
Output is correct |
2 |
Correct |
0 ms |
18816 KB |
Output is correct |
3 |
Correct |
0 ms |
18816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3229 ms |
19476 KB |
Output is correct |
2 |
Correct |
4749 ms |
19608 KB |
Output is correct |
3 |
Correct |
7443 ms |
21192 KB |
Output is correct |
4 |
Correct |
7666 ms |
21192 KB |
Output is correct |
5 |
Correct |
7329 ms |
21192 KB |
Output is correct |
6 |
Execution timed out |
9000 ms |
21192 KB |
Execution timed out |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5336 ms |
19608 KB |
Output is correct |
2 |
Execution timed out |
9000 ms |
19872 KB |
Execution timed out |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
9000 ms |
25812 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |