#include "elephants.h"
#include<bits/stdc++.h>
using namespace std;
const int maxN = 150000;
int n, l;
int positionsCameras[maxN];
int positions[maxN];
int posPerNumber[maxN];
void init(int N, int L, int X[])
{
n = N;
l = L;
for(int i = 0; i < N; ++i) {
positions[i] = X[i];
posPerNumber[i] = X[i];
}
}
int find(int rep){
int hi = n-1;
int lo = 0;
while(lo <= hi){
int mid = lo + (hi - lo)/2;
if(positions[mid] == rep) return mid;
if(positions[mid] < rep) lo = mid+1;
else hi = mid-1;
}
return 0;
}
int update(int i, int y)
{
int replace = posPerNumber[i];
posPerNumber[i] = y;
int pos = find(replace);
positions[pos] = y;
while(pos && positions[pos] < positions[pos-1]) {
swap(positions[pos], positions[pos-1]);
pos--;
}
while(pos < (n-1) && positions[pos] > positions[pos+1]) {
swap(positions[pos], positions[pos+1]);
pos++;
}
int numCameras = 0;
int right = -1;
for(int j = 0; j < n; ++j){
if(right < positions[j]){
numCameras++;
right = positions[j] + l;
}
}
return numCameras;
}
/*
int main(){
int N, L, Q, i, y;
cin >> N >> L;
int X[N];
for(int i = 0; i < N; ++i) cin >> X[i];
init(N, L, X);
cin >> Q;
while(Q--){
cin >> i >> y;
cout << update(i, y) << endl;
}
return 0;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1082 ms |
1824 KB |
Output is correct |
8 |
Correct |
1980 ms |
1880 KB |
Output is correct |
9 |
Correct |
1442 ms |
2264 KB |
Output is correct |
10 |
Correct |
3162 ms |
2284 KB |
Output is correct |
11 |
Correct |
3331 ms |
2260 KB |
Output is correct |
12 |
Correct |
5719 ms |
2264 KB |
Output is correct |
13 |
Correct |
3279 ms |
2264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1082 ms |
1824 KB |
Output is correct |
8 |
Correct |
1980 ms |
1880 KB |
Output is correct |
9 |
Correct |
1442 ms |
2264 KB |
Output is correct |
10 |
Correct |
3162 ms |
2284 KB |
Output is correct |
11 |
Correct |
3331 ms |
2260 KB |
Output is correct |
12 |
Correct |
5719 ms |
2264 KB |
Output is correct |
13 |
Correct |
3279 ms |
2264 KB |
Output is correct |
14 |
Correct |
1133 ms |
2120 KB |
Output is correct |
15 |
Correct |
4353 ms |
2188 KB |
Output is correct |
16 |
Execution timed out |
9018 ms |
2468 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1082 ms |
1824 KB |
Output is correct |
8 |
Correct |
1980 ms |
1880 KB |
Output is correct |
9 |
Correct |
1442 ms |
2264 KB |
Output is correct |
10 |
Correct |
3162 ms |
2284 KB |
Output is correct |
11 |
Correct |
3331 ms |
2260 KB |
Output is correct |
12 |
Correct |
5719 ms |
2264 KB |
Output is correct |
13 |
Correct |
3279 ms |
2264 KB |
Output is correct |
14 |
Correct |
1133 ms |
2120 KB |
Output is correct |
15 |
Correct |
4353 ms |
2188 KB |
Output is correct |
16 |
Execution timed out |
9018 ms |
2468 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |