#include "elephants.h"
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt")
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
const int N=150050,inf=1e9;
const int koren=400;
int K;
int n,a[N+50],b[N+50],L,res,nq,dp[410][1500],poslednji[600][1500];
int A[410][1500],sajz[1500];
void Calcblok(int i){
if(sajz[i]==0) return;
for(int j=sajz[i]-1,k=sajz[i]-1;j>=0;j--){
while(k>=1 && A[i][j]+L<A[i][k-1]) k--;
if(A[i][j]+L>=A[i][sajz[i]-1]){
dp[i][j]=1;
poslednji[i][j]=j;
}
else{
dp[i][j]=1+dp[i][k];
poslednji[i][j]=poslednji[i][k];
}
}
}
void Erase(int x){
for(int i=0;i<=K;i++){
if(sajz[i]==0) continue;
if(A[i][0]<=x && x<=A[i][sajz[i]-1]){
int ind=sajz[i];
for(int j=0;j<sajz[i];j++) if(A[i][j]==x) ind=j;
while(ind+1<sajz[i]){swap(A[i][ind],A[i][ind+1]);ind++;}
sajz[i]--;
Calcblok(i);
break;
}
}
}
void Insert(int x){
for(int i=0;i<=K;i++){
if(i==K || (sajz[i] && x<=A[i][0])){
sajz[i]++;
A[i][sajz[i]-1]=x;
int ind=sajz[i]-1;
while(ind>=1 && A[i][ind]<A[i][ind-1]){swap(A[i][ind],A[i][ind-1]);ind--;}
Calcblok(i);
break;
}
}
}
void Calc(){
int ct=-1;
for(int i=0;i<=K;i++) for(int j=0;j<sajz[i];j++) b[++ct]=A[i][j];
ct=-1;
for(int j=0;j<=K;j++){
sajz[j]=koren;if(j==K) sajz[j]=(n-1)%koren+1;
for(int i=0;i<sajz[j];i++) A[j][i]=b[++ct];
Calcblok(j);
}
}
int Resi(){
int res=0,x=-1;
for(int i=0;i<=K;i++){
if(sajz[i]==0) continue;
if(x<=A[i][sajz[i]-1]){
int ind=0;
for(int j=sajz[i]-1;j>=0;j--) if(A[i][j]>=x) ind=j;
res+=dp[i][ind];
x=A[i][poslednji[i][ind]]+L+1;
}
}
return res;
}
void init(int N1, int L1, int X[]){
n = N1;
for(int i=0;i<n;i++) a[i]=X[i];
for(int i=0;i<n;i++) b[i]=a[i];
sort(b,b+n);
K=(n-1)/koren;
for(int i=0;i<n;i++){
A[i/koren][i%koren]=b[i];
sajz[i/koren]=i%koren+1;
}
L=L1;
//for(int i=0;i<koren+50;i++) A[i].reserve(3*koren+10);
Calc();
//for(int i=0;i<=(n-1)/koren;i++) printf("%i ",sajz[i]);
}
int update(int qind, int y){
Erase(a[qind]);
a[qind]=y;
Insert(a[qind]);
nq++;
if(nq==2*koren-5) {Calc();nq=0;}
return Resi();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Incorrect |
14 ms |
2648 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Incorrect |
14 ms |
2648 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Incorrect |
14 ms |
2648 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |