#include "elephants.h"
#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
const int MAX = 2e6 + 15;
int n, l, pos[MAX], X[] = {10, 15, 17, 20};
vector<int> x;
void init(int n_, int l_, int x_[]){
n = n_, l = l_;
x.resize(n);
for(int i = 0; i < n; i++)
x[i] = x_[i], pos[i] = x[i];
}
vector<int> Merge(vector<int>& x, vector<int>& y, vector<int>& z){
vector<int> aux(sz(x) + sz(y)), ret(sz(x) + sz(y) + sz(z));
merge(all(x), all(y), aux.begin());
merge(all(aux), all(z), ret.begin());
return ret;
}
int update(int i, int y){
vector<int> a, b, c;
int id = 0;
while(x[id] < pos[i]) id++;
for(int j = 0; j < id; j++)
a.push_back(x[j]);
for(int j = id + 1; j < n; j++)
b.push_back(x[j]);
c.push_back(y);
vector<int> aux = Merge(a, b, c);
swap(aux, x);
int ans = 0, r = -1;
for(int j = 0; j < n; j++)
if(x[j] > r) ans++, r = x[j] + l;
pos[i] = y;
return ans;
}
/*int main(){
init(4, 10, X);
cout << update(2, 16) << '\n';
cout << update(1, 25) << '\n';
cout << update(3, 35) << '\n';
cout << update(0, 38) << '\n';
cout << update(2, 0) << '\n';
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
2944 ms |
1360 KB |
Output is correct |
8 |
Correct |
4178 ms |
1608 KB |
Output is correct |
9 |
Execution timed out |
9058 ms |
2984 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
2944 ms |
1360 KB |
Output is correct |
8 |
Correct |
4178 ms |
1608 KB |
Output is correct |
9 |
Execution timed out |
9058 ms |
2984 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
2944 ms |
1360 KB |
Output is correct |
8 |
Correct |
4178 ms |
1608 KB |
Output is correct |
9 |
Execution timed out |
9058 ms |
2984 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |