#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int SQ = 400;
int n, l;
int currentUpdate = 0;
vector<vi> difX;
vector<vii> dp;
vi a, b;
void updateComp(int c) {
int m = difX[c].size();
dp[c].clear();
dp[c].resize(m);
int ub=m-1;
REV(lb,0,m) {
while(difX[c][ub] - difX[c][lb] > l) ub--;
if(ub == m-1) {
dp[c][lb] = {1,difX[c][lb]+l};
} else {
dp[c][lb] = dp[c][ub+1];
dp[c][lb].fi++;
}
}
}
void updateAll() {
difX.clear();
b = a;
sort(all(b));
int cc = -1;
RE(i,n) {
if(i%SQ == 0) cc++, difX.pb({}), dp.pb({});
difX[cc].pb(b[i]);
}
RE(i,cc+1) updateComp(i);
}
int getCurrent() {
int m = difX.size();
int lastX = -1;
int res = 0;
RE(i,m) {
int j = upper_bound(all(difX[i]),lastX) - difX[i].begin();
if(j == difX[i].size()) continue;
res += dp[i][j].fi;
lastX = dp[i][j].se;
}
return res;
}
void removeX(int x) {
int m = difX.size();
RE(i,m) {
if(difX[i][0] <= x && x <= difX[i].back()) {
difX[i].erase(find(all(difX[i]), x));
updateComp(i);
break;
}
}
}
void insertX(int x) {
int m = difX.size();
REV(i,0,m) {
if(i == 0 || x >= difX[i-1].back()) {
difX[i].insert(upper_bound(all(difX[i]),x), x);
updateComp(i);
break;
}
}
}
void init(int N, int L, int X[]) {
n = N; l = L;
RE(i,n) a.pb(X[i]);
}
int update(int i, int y) {
removeX(a[i]);
a[i] = y;
insertX(a[i]);
if(currentUpdate % (SQ-1) == 0) updateAll();
currentUpdate++;
return getCurrent();
}
Compilation message
elephants.cpp: In function 'int getCurrent()':
elephants.cpp:75:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | if(j == difX[i].size()) continue;
| ~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
260 ms |
1392 KB |
Output is correct |
8 |
Correct |
297 ms |
1828 KB |
Output is correct |
9 |
Correct |
467 ms |
2656 KB |
Output is correct |
10 |
Correct |
631 ms |
2848 KB |
Output is correct |
11 |
Correct |
612 ms |
2620 KB |
Output is correct |
12 |
Correct |
974 ms |
2792 KB |
Output is correct |
13 |
Correct |
588 ms |
2700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
260 ms |
1392 KB |
Output is correct |
8 |
Correct |
297 ms |
1828 KB |
Output is correct |
9 |
Correct |
467 ms |
2656 KB |
Output is correct |
10 |
Correct |
631 ms |
2848 KB |
Output is correct |
11 |
Correct |
612 ms |
2620 KB |
Output is correct |
12 |
Correct |
974 ms |
2792 KB |
Output is correct |
13 |
Correct |
588 ms |
2700 KB |
Output is correct |
14 |
Correct |
425 ms |
1940 KB |
Output is correct |
15 |
Correct |
491 ms |
2452 KB |
Output is correct |
16 |
Correct |
1487 ms |
3528 KB |
Output is correct |
17 |
Correct |
1758 ms |
4240 KB |
Output is correct |
18 |
Correct |
1880 ms |
4260 KB |
Output is correct |
19 |
Correct |
1124 ms |
3964 KB |
Output is correct |
20 |
Correct |
1801 ms |
4148 KB |
Output is correct |
21 |
Correct |
1770 ms |
4256 KB |
Output is correct |
22 |
Correct |
1136 ms |
4064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
260 ms |
1392 KB |
Output is correct |
8 |
Correct |
297 ms |
1828 KB |
Output is correct |
9 |
Correct |
467 ms |
2656 KB |
Output is correct |
10 |
Correct |
631 ms |
2848 KB |
Output is correct |
11 |
Correct |
612 ms |
2620 KB |
Output is correct |
12 |
Correct |
974 ms |
2792 KB |
Output is correct |
13 |
Correct |
588 ms |
2700 KB |
Output is correct |
14 |
Correct |
425 ms |
1940 KB |
Output is correct |
15 |
Correct |
491 ms |
2452 KB |
Output is correct |
16 |
Correct |
1487 ms |
3528 KB |
Output is correct |
17 |
Correct |
1758 ms |
4240 KB |
Output is correct |
18 |
Correct |
1880 ms |
4260 KB |
Output is correct |
19 |
Correct |
1124 ms |
3964 KB |
Output is correct |
20 |
Correct |
1801 ms |
4148 KB |
Output is correct |
21 |
Correct |
1770 ms |
4256 KB |
Output is correct |
22 |
Correct |
1136 ms |
4064 KB |
Output is correct |
23 |
Correct |
4062 ms |
12720 KB |
Output is correct |
24 |
Correct |
4436 ms |
12644 KB |
Output is correct |
25 |
Correct |
3476 ms |
12680 KB |
Output is correct |
26 |
Correct |
5042 ms |
12604 KB |
Output is correct |
27 |
Correct |
5546 ms |
12812 KB |
Output is correct |
28 |
Correct |
1119 ms |
2560 KB |
Output is correct |
29 |
Correct |
1104 ms |
2788 KB |
Output is correct |
30 |
Correct |
1140 ms |
2604 KB |
Output is correct |
31 |
Correct |
1118 ms |
2628 KB |
Output is correct |
32 |
Correct |
4557 ms |
12672 KB |
Output is correct |
33 |
Correct |
4679 ms |
12636 KB |
Output is correct |
34 |
Correct |
4591 ms |
12700 KB |
Output is correct |
35 |
Correct |
3783 ms |
12696 KB |
Output is correct |
36 |
Correct |
2413 ms |
12612 KB |
Output is correct |
37 |
Correct |
6709 ms |
12888 KB |
Output is correct |
38 |
Correct |
4562 ms |
12636 KB |
Output is correct |
39 |
Correct |
4784 ms |
12600 KB |
Output is correct |
40 |
Correct |
4735 ms |
12820 KB |
Output is correct |
41 |
Correct |
7280 ms |
12844 KB |
Output is correct |
42 |
Correct |
7252 ms |
13056 KB |
Output is correct |