#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
const int mxN = (int)1.5e5+10;
const int INF = (int)1e9+10;
const int B = 200;
int n, L, p[mxN];
unordered_map<int,int> b;
unordered_map<int,set<int>> pos;
map<int,set<array<int,3>>> block;
void reUpd(int ind){
block[ind].clear();
auto itr = end(pos[ind]);
auto stop = begin(pos[ind]);
while(itr!=stop){ itr--;
auto itr2 = block[ind].lower_bound({*itr+L+1,-1,-1});
if(itr2!=block[ind].end())
block[ind].insert({*itr,1+(*itr2)[1],(*itr2)[2]});
else block[ind].insert({*itr,1,*itr+L+1});
}
}
void ins(int x){
b[x]++; if(b[x]!=1) return;
int ind = x/B; pos[ind].insert(x); reUpd(ind);
}
void del(int x){
b[x]--; if(b[x]) return;
int ind = x/B; pos[ind].erase(x); reUpd(ind);
}
void init(int N, int l, int X[])
{
n = N; L = l;
for(int i = 0; i < n; i++)
p[i]=X[i], ins(p[i]);
}
int update(int i, int y)
{
del(p[i]); p[i]=y; ins(y);
int ans = 0, cur = 0;
for(auto [i,bl] : block){
auto itr = bl.lower_bound({cur,-1,-1});
if(itr!=bl.end()) ans+=(*itr)[1], cur = (*itr)[2];
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
7 |
Execution timed out |
9028 ms |
4108 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
7 |
Execution timed out |
9028 ms |
4108 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
7 |
Execution timed out |
9028 ms |
4108 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |