#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
refs:
edi
*/
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
const int B = 455;
#include "elephants.h"
int n,L;
vector<int> a;
set<pii> st;
vector<pii> blocks[N/B+5];
vector<int> block_num, cams, mx_point;
void upd_block(int b){
if(blocks[b].empty()) return;
auto &curr = blocks[b];
int siz = sz(curr);
int ptr = siz-1;
rev(i,siz-1,0){
while(curr[ptr].ff-curr[i].ff > L){
ptr--;
}
int j = curr[i].ss;
if(ptr+1 == siz){
cams[j] = 1;
mx_point[j] = curr[i].ff+L;
}
else{
int k = curr[ptr+1].ss;
cams[j] = cams[k]+1;
mx_point[j] = mx_point[k];
}
}
}
void build(){
int ind = 0;
rep(i,n/B+1){
blocks[i].clear();
}
for(auto [x,i] : st){
blocks[ind/B].pb({x,i});
block_num[i] = ind/B;
ind++;
}
rep(b,n/B+1){
upd_block(b);
}
}
void init(int n_, int L_, int X[])
{
n = n_;
L = L_;
a = block_num = cams = mx_point = vector<int>(n);
rep(i,n) a[i] = X[i];
rep(i,n) st.insert({a[i],i});
build();
}
int upds = 0;
int update(int i, int v)
{
upds++;
if(upds%B == 0){
build();
}
int b = block_num[i];
{
auto &curr = blocks[b];
pii px = {a[i],i};
curr.erase(find(all(curr),px));
upd_block(b);
}
st.erase({a[i],i});
a[i] = v;
st.insert({a[i],i});
auto it = st.find({a[i],i});
if(next(it) != st.end()){
b = block_num[next(it)->ss];
}
else if(it != st.begin()){
b = block_num[prev(it)->ss];
}
else{
b = 0;
}
block_num[i] = b;
{
auto &curr = blocks[b];
pii px = {a[i],i};
curr.insert(upper_bound(all(curr),px),px);
upd_block(b);
}
int mx_reach = -1;
int ans = 0;
rep(b,n/B+1){
auto &curr = blocks[b];
pii px = {mx_reach+1,-1};
auto it = upper_bound(all(curr),px);
if(it == curr.end()){
conts;
}
int j = it->second;
ans += cams[j];
mx_reach = mx_point[j];
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6600 KB |
Output is correct |
7 |
Correct |
173 ms |
10576 KB |
Output is correct |
8 |
Correct |
196 ms |
11156 KB |
Output is correct |
9 |
Correct |
273 ms |
13436 KB |
Output is correct |
10 |
Correct |
284 ms |
13160 KB |
Output is correct |
11 |
Correct |
259 ms |
13412 KB |
Output is correct |
12 |
Correct |
519 ms |
13412 KB |
Output is correct |
13 |
Correct |
270 ms |
13260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6600 KB |
Output is correct |
7 |
Correct |
173 ms |
10576 KB |
Output is correct |
8 |
Correct |
196 ms |
11156 KB |
Output is correct |
9 |
Correct |
273 ms |
13436 KB |
Output is correct |
10 |
Correct |
284 ms |
13160 KB |
Output is correct |
11 |
Correct |
259 ms |
13412 KB |
Output is correct |
12 |
Correct |
519 ms |
13412 KB |
Output is correct |
13 |
Correct |
270 ms |
13260 KB |
Output is correct |
14 |
Correct |
288 ms |
11388 KB |
Output is correct |
15 |
Correct |
292 ms |
11600 KB |
Output is correct |
16 |
Correct |
846 ms |
13668 KB |
Output is correct |
17 |
Correct |
919 ms |
15132 KB |
Output is correct |
18 |
Correct |
972 ms |
15136 KB |
Output is correct |
19 |
Correct |
398 ms |
15364 KB |
Output is correct |
20 |
Correct |
880 ms |
15132 KB |
Output is correct |
21 |
Correct |
930 ms |
15188 KB |
Output is correct |
22 |
Correct |
444 ms |
15104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6600 KB |
Output is correct |
7 |
Correct |
173 ms |
10576 KB |
Output is correct |
8 |
Correct |
196 ms |
11156 KB |
Output is correct |
9 |
Correct |
273 ms |
13436 KB |
Output is correct |
10 |
Correct |
284 ms |
13160 KB |
Output is correct |
11 |
Correct |
259 ms |
13412 KB |
Output is correct |
12 |
Correct |
519 ms |
13412 KB |
Output is correct |
13 |
Correct |
270 ms |
13260 KB |
Output is correct |
14 |
Correct |
288 ms |
11388 KB |
Output is correct |
15 |
Correct |
292 ms |
11600 KB |
Output is correct |
16 |
Correct |
846 ms |
13668 KB |
Output is correct |
17 |
Correct |
919 ms |
15132 KB |
Output is correct |
18 |
Correct |
972 ms |
15136 KB |
Output is correct |
19 |
Correct |
398 ms |
15364 KB |
Output is correct |
20 |
Correct |
880 ms |
15132 KB |
Output is correct |
21 |
Correct |
930 ms |
15188 KB |
Output is correct |
22 |
Correct |
444 ms |
15104 KB |
Output is correct |
23 |
Correct |
1910 ms |
26460 KB |
Output is correct |
24 |
Correct |
2210 ms |
26452 KB |
Output is correct |
25 |
Correct |
1620 ms |
26508 KB |
Output is correct |
26 |
Correct |
1719 ms |
23656 KB |
Output is correct |
27 |
Correct |
2068 ms |
23652 KB |
Output is correct |
28 |
Correct |
845 ms |
13236 KB |
Output is correct |
29 |
Correct |
818 ms |
13260 KB |
Output is correct |
30 |
Correct |
822 ms |
13424 KB |
Output is correct |
31 |
Correct |
825 ms |
13256 KB |
Output is correct |
32 |
Correct |
1612 ms |
23636 KB |
Output is correct |
33 |
Correct |
1688 ms |
23648 KB |
Output is correct |
34 |
Correct |
1757 ms |
23652 KB |
Output is correct |
35 |
Correct |
1642 ms |
23648 KB |
Output is correct |
36 |
Correct |
1657 ms |
23888 KB |
Output is correct |
37 |
Correct |
2920 ms |
25056 KB |
Output is correct |
38 |
Correct |
1672 ms |
23656 KB |
Output is correct |
39 |
Correct |
1718 ms |
23648 KB |
Output is correct |
40 |
Correct |
1828 ms |
23648 KB |
Output is correct |
41 |
Correct |
3285 ms |
23668 KB |
Output is correct |
42 |
Correct |
3438 ms |
23660 KB |
Output is correct |