#include "elephants.h"
#include<bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
int n, l;
vector<int> pocz;
vector<vector<int> > V;
vector<vector<int> > gdzie, ile;
vector<int> pos;
const int K=500;
void init(int N, int L, int X[])
{
n = N;
l=L;
pos.resize(n);
for(int i=0; i<n; i++){
pos[i]=X[i];
}
}
int cnt=0;
int find(int x){
return max(0, (int)(upper_bound(pocz.begin(), pocz.end(), x)-pocz.begin()-1));
}
void build(int x){
//cout<<x<<"a\n";
if(!V[x].size())return;
//sort(V[x].begin(), V[x].end());
pocz[x]=V[x][0];
gdzie[x].resize(V[x].size());
ile[x].resize(V[x].size());
int t=V[x].size();
for(int i=V[x].size()-1; i>=0; i--){
while(V[x][t-1]>V[x][i]+l)t--;
if(t==V[x].size()){
ile[x][i]=1;
gdzie[x][i]=V[x][i]+l;
}
else{
ile[x][i]=ile[x][t]+1;
gdzie[x][i]=gdzie[x][t];
}
//cout<<i<<" "<<V[x][i]<<" "<<t<<" "<<gdzie[x][i]<<" "<<ile[x][i]<<"\n";
}
}
void usun(int k, int x){
vector<int> V2;
for(int i=0; i<V[k].size(); i++){
if(V[k][i]==x){
x=-1;
continue;
}
V2.pb(V[k][i]);
}
V[k]=V2;
build(k);
}
void dodaj(int k, int x){
vector<int> V2;
bool b=0;
for(int i=0; i<V[k].size(); i++){
if(!b && V[k][i]>x){
V2.pb(x);
b=1;
}
V2.pb(V[k][i]);
}
if(!b){
V2.pb(x);
}
V[k]=V2;
build(k);
}
int query(){
/*for(int i=0; i<V.size(); i++){
cout<<pocz[i]<<"\n";
for(int j=0; j<V[i].size(); j++){
cout<<V[i][j]<<" "<<ile[i][j]<<" "<<gdzie[i][j]<<"\n";
}
}*/
int ans=0;
int akt=-1;
for(int i=0; i<V.size(); i++){
if(!V[i].size() || akt>=V[i].back())continue;
else{
int j=upper_bound(V[i].begin(), V[i].end(), akt)-V[i].begin();
ans+=ile[i][j];
akt=gdzie[i][j];
}
}
return ans;
}
int update(int i, int y)
{
if(cnt%K==0){
V.resize((n+K-1)/K);
gdzie.resize((n+K-1)/K);
ile.resize((n+K-1)/K);
pocz.resize((n+K-1)/K);
vector<int> pos2=pos;
sort(pos2.begin(), pos2.end());
for(int i=0; i<V.size(); i++)V[i].clear();
for(int i=0; i<n; i++){
V[i/K].pb(pos2[i]);
}
for(int i=0; i<V.size(); i++)build(i);
}
/*cout<<V.size()<<"\n";
for(int i=0; i<V.size(); i++){
cout<<pocz[i]<<" "<<V[i].size()<<"\n";
}*/
int t=find(pos[i]);
//cout<<t<<"\n";
usun(t, pos[i]);
pos[i]=y;
t=find(pos[i]);
//cout<<t<<"\n";
dodaj(t, pos[i]);
cnt++;
return query();
}
Compilation message
elephants.cpp: In function 'void build(int)':
elephants.cpp:39:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if(t==V[x].size()){
| ~^~~~~~~~~~~~~
elephants.cpp: In function 'void usun(int, int)':
elephants.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i=0; i<V[k].size(); i++){
| ~^~~~~~~~~~~~
elephants.cpp: In function 'void dodaj(int, int)':
elephants.cpp:65:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i=0; i<V[k].size(); i++){
| ~^~~~~~~~~~~~
elephants.cpp: In function 'int query()':
elephants.cpp:87:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for(int i=0; i<V.size(); i++){
| ~^~~~~~~~~
elephants.cpp: In function 'int update(int, int)':
elephants.cpp:106:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for(int i=0; i<V.size(); i++)V[i].clear();
| ~^~~~~~~~~
elephants.cpp:110:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | for(int i=0; i<V.size(); i++)build(i);
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
296 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 |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
467 ms |
1424 KB |
Output is correct |
8 |
Correct |
505 ms |
1604 KB |
Output is correct |
9 |
Correct |
568 ms |
2340 KB |
Output is correct |
10 |
Correct |
673 ms |
2172 KB |
Output is correct |
11 |
Correct |
681 ms |
2176 KB |
Output is correct |
12 |
Correct |
1065 ms |
2688 KB |
Output is correct |
13 |
Correct |
678 ms |
2252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
467 ms |
1424 KB |
Output is correct |
8 |
Correct |
505 ms |
1604 KB |
Output is correct |
9 |
Correct |
568 ms |
2340 KB |
Output is correct |
10 |
Correct |
673 ms |
2172 KB |
Output is correct |
11 |
Correct |
681 ms |
2176 KB |
Output is correct |
12 |
Correct |
1065 ms |
2688 KB |
Output is correct |
13 |
Correct |
678 ms |
2252 KB |
Output is correct |
14 |
Correct |
657 ms |
1884 KB |
Output is correct |
15 |
Correct |
754 ms |
2080 KB |
Output is correct |
16 |
Correct |
1656 ms |
2816 KB |
Output is correct |
17 |
Correct |
1830 ms |
3520 KB |
Output is correct |
18 |
Correct |
1930 ms |
3636 KB |
Output is correct |
19 |
Correct |
1130 ms |
2884 KB |
Output is correct |
20 |
Correct |
1817 ms |
3624 KB |
Output is correct |
21 |
Correct |
1763 ms |
3536 KB |
Output is correct |
22 |
Correct |
1136 ms |
2892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
467 ms |
1424 KB |
Output is correct |
8 |
Correct |
505 ms |
1604 KB |
Output is correct |
9 |
Correct |
568 ms |
2340 KB |
Output is correct |
10 |
Correct |
673 ms |
2172 KB |
Output is correct |
11 |
Correct |
681 ms |
2176 KB |
Output is correct |
12 |
Correct |
1065 ms |
2688 KB |
Output is correct |
13 |
Correct |
678 ms |
2252 KB |
Output is correct |
14 |
Correct |
657 ms |
1884 KB |
Output is correct |
15 |
Correct |
754 ms |
2080 KB |
Output is correct |
16 |
Correct |
1656 ms |
2816 KB |
Output is correct |
17 |
Correct |
1830 ms |
3520 KB |
Output is correct |
18 |
Correct |
1930 ms |
3636 KB |
Output is correct |
19 |
Correct |
1130 ms |
2884 KB |
Output is correct |
20 |
Correct |
1817 ms |
3624 KB |
Output is correct |
21 |
Correct |
1763 ms |
3536 KB |
Output is correct |
22 |
Correct |
1136 ms |
2892 KB |
Output is correct |
23 |
Correct |
3618 ms |
6828 KB |
Output is correct |
24 |
Correct |
3972 ms |
6784 KB |
Output is correct |
25 |
Correct |
2823 ms |
6412 KB |
Output is correct |
26 |
Correct |
4324 ms |
6008 KB |
Output is correct |
27 |
Correct |
4633 ms |
5880 KB |
Output is correct |
28 |
Correct |
1940 ms |
2364 KB |
Output is correct |
29 |
Correct |
1897 ms |
2504 KB |
Output is correct |
30 |
Correct |
1922 ms |
2360 KB |
Output is correct |
31 |
Correct |
1894 ms |
2536 KB |
Output is correct |
32 |
Correct |
3861 ms |
5796 KB |
Output is correct |
33 |
Correct |
3958 ms |
5772 KB |
Output is correct |
34 |
Correct |
4086 ms |
5764 KB |
Output is correct |
35 |
Correct |
3372 ms |
5940 KB |
Output is correct |
36 |
Correct |
2301 ms |
5772 KB |
Output is correct |
37 |
Correct |
5812 ms |
7564 KB |
Output is correct |
38 |
Correct |
4144 ms |
5732 KB |
Output is correct |
39 |
Correct |
3993 ms |
5768 KB |
Output is correct |
40 |
Correct |
4352 ms |
5752 KB |
Output is correct |
41 |
Correct |
6287 ms |
6852 KB |
Output is correct |
42 |
Correct |
6350 ms |
6912 KB |
Output is correct |