#include <bits/stdc++.h>
#include "bubblesort2.h"
#include <ext/pb_ds/assoc_container.hpp>
#define vi vector<int>
#define ve vector
#define ll long long
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define onbit __builtin_popcount
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
using namespace std;
using namespace __gnu_pbds;
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll MOD = 1e9+7;
const int nax = 5e5+5;
const int MAX_VAL = 1e6;
double PI=3.14159265359;
int arx[8]={1,1,0,-1,-1,-1, 0, 1};
int ary[8]={0,1,1, 1, 0,-1,-1,-1};
/*typedef complex<int> Point;
#define X real()
#define Y imag()*/
/*void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}*/
vector<pair<ll,int>> tab(nax);
vi segtree;
vi upd;
int res;
void build(int n)
{
res=1;
while (res<n)res*=2;
segtree.assign(res*2,0);
upd.assign(res*2,0);
}
void update(int left,int right,int value,int pos,int l,int r)
{
if (l>=left&&r<=right){
upd[pos]+=value;
segtree[pos]+=value;
return;
}
if (r<=left||l>=right) return;
int mid=(l+r)/2;
update(left,right,value,pos*2+1,l,mid);
update(left,right,value,pos*2+2,mid,r);
segtree[pos] = max(segtree[pos*2+1],segtree[pos*2+2])+upd[pos];
}
std::vector<int> countScans(std::vector<int> A, std::vector<int> X, std::vector<int> V){
int n,q;
n=A.size();
q=X.size();
vi nabba;
vi check(n+q);
map<int,int> ind;
for (int i = 0; i < n; ++i)
{
check[i]=A[i];
}
for (int i = 0; i < q; ++i)
{
check[i+n]=V[i];
}
sort(check.begin(),check.end());
int cur=0;
for (int i = 0; i < check.size(); ++i)
{
if (i==0) {
ind[check[i]]=cur;
cur++;
}
else{
if (check[i]==check[i-1]) {
continue;
}
ind[check[i]]=cur;
cur++;
}
}
build(cur);
map<int,set<int>> pos;
for (int i = 0; i < n; ++i)
{
pos[ind[A[i]]].insert(i);
//cout << ind[A[i]]<<endl;
update(ind[A[i]],cur,-1,0,0,res);
}
for (int i = 0; i < cur; ++i)
{
if ((int)pos[i].size()>0){
update(i,i+1,*pos[i].rbegin()+1,0,0,res);
}
}
for (int i = 0; i < q; ++i)
{
int x=X[i];
int nw=V[i];
int lst=A[x];
A[x]=nw;
lst=ind[lst];
nw=ind[nw];
int lstpos=*pos[lst].rbegin();
pos[lst].erase(x);
if ((int)pos[lst].size()>0) update(lst,lst+1,(*pos[lst].rbegin()-lstpos),0,0,res);
else update(lst,lst+1,-lstpos-1,0,0,res);
update(lst,cur,1,0,0,res);
if ((int)pos[nw].size()==0){
pos[nw].insert(x);
update(nw,nw+1,x+1,0,0,res);
}else{
lstpos=*pos[nw].rbegin();
pos[nw].insert(x);
update(nw,nw+1,(*pos[nw].rbegin()-lstpos),0,0,res);
}
update(nw,cur,-1,0,0,res);
nabba.pb(segtree[0]);
//cout << segtree[0]<<endl;
}
return nabba;
}
/*int readInt(){
int i;
if(scanf("%d",&i)!=1){
fprintf(stderr,"Error while reading input\n");
exit(1);
}
return i;
}
/*int main(){
optimise;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//setIO("cowland");
}*/
/*int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int N,Q;
N=readInt();
Q=readInt();
std::vector<int> A(N);
for(int i=0;i<N;i++)
A[i]=readInt();
std::vector<int> X(Q),V(Q);
for(int j=0;j<Q;j++){
X[j]=readInt();
V[j]=readInt();
}
std::vector<int> res=countScans(A,X,V);
for(int j=0;j<int(res.size());j++)
printf("%d\n",res[j]);
}*/
Compilation message
bubblesort2.cpp:144:1: warning: "/*" within comment [-Wcomment]
144 | /*int main(){
|
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:81:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for (int i = 0; i < check.size(); ++i)
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8276 KB |
Output is correct |
2 |
Correct |
9 ms |
8404 KB |
Output is correct |
3 |
Correct |
12 ms |
8988 KB |
Output is correct |
4 |
Correct |
10 ms |
8924 KB |
Output is correct |
5 |
Correct |
10 ms |
8920 KB |
Output is correct |
6 |
Correct |
9 ms |
8884 KB |
Output is correct |
7 |
Correct |
11 ms |
8916 KB |
Output is correct |
8 |
Correct |
10 ms |
8916 KB |
Output is correct |
9 |
Correct |
12 ms |
8916 KB |
Output is correct |
10 |
Correct |
11 ms |
8792 KB |
Output is correct |
11 |
Correct |
10 ms |
8788 KB |
Output is correct |
12 |
Correct |
11 ms |
8828 KB |
Output is correct |
13 |
Correct |
10 ms |
8788 KB |
Output is correct |
14 |
Correct |
10 ms |
8792 KB |
Output is correct |
15 |
Correct |
12 ms |
8868 KB |
Output is correct |
16 |
Correct |
9 ms |
8788 KB |
Output is correct |
17 |
Correct |
10 ms |
8788 KB |
Output is correct |
18 |
Correct |
10 ms |
8796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8276 KB |
Output is correct |
2 |
Correct |
9 ms |
8404 KB |
Output is correct |
3 |
Correct |
12 ms |
8988 KB |
Output is correct |
4 |
Correct |
10 ms |
8924 KB |
Output is correct |
5 |
Correct |
10 ms |
8920 KB |
Output is correct |
6 |
Correct |
9 ms |
8884 KB |
Output is correct |
7 |
Correct |
11 ms |
8916 KB |
Output is correct |
8 |
Correct |
10 ms |
8916 KB |
Output is correct |
9 |
Correct |
12 ms |
8916 KB |
Output is correct |
10 |
Correct |
11 ms |
8792 KB |
Output is correct |
11 |
Correct |
10 ms |
8788 KB |
Output is correct |
12 |
Correct |
11 ms |
8828 KB |
Output is correct |
13 |
Correct |
10 ms |
8788 KB |
Output is correct |
14 |
Correct |
10 ms |
8792 KB |
Output is correct |
15 |
Correct |
12 ms |
8868 KB |
Output is correct |
16 |
Correct |
9 ms |
8788 KB |
Output is correct |
17 |
Correct |
10 ms |
8788 KB |
Output is correct |
18 |
Correct |
10 ms |
8796 KB |
Output is correct |
19 |
Correct |
34 ms |
11140 KB |
Output is correct |
20 |
Correct |
37 ms |
11524 KB |
Output is correct |
21 |
Correct |
39 ms |
11528 KB |
Output is correct |
22 |
Correct |
36 ms |
11476 KB |
Output is correct |
23 |
Correct |
34 ms |
11192 KB |
Output is correct |
24 |
Correct |
35 ms |
11212 KB |
Output is correct |
25 |
Correct |
32 ms |
11040 KB |
Output is correct |
26 |
Correct |
31 ms |
11084 KB |
Output is correct |
27 |
Correct |
31 ms |
10956 KB |
Output is correct |
28 |
Correct |
33 ms |
10920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
9868 KB |
Output is correct |
2 |
Correct |
62 ms |
11432 KB |
Output is correct |
3 |
Correct |
105 ms |
12684 KB |
Output is correct |
4 |
Correct |
106 ms |
12696 KB |
Output is correct |
5 |
Correct |
115 ms |
12700 KB |
Output is correct |
6 |
Correct |
100 ms |
12688 KB |
Output is correct |
7 |
Correct |
91 ms |
12640 KB |
Output is correct |
8 |
Correct |
97 ms |
12644 KB |
Output is correct |
9 |
Correct |
94 ms |
12676 KB |
Output is correct |
10 |
Correct |
74 ms |
12656 KB |
Output is correct |
11 |
Correct |
72 ms |
12624 KB |
Output is correct |
12 |
Correct |
76 ms |
12584 KB |
Output is correct |
13 |
Correct |
73 ms |
12644 KB |
Output is correct |
14 |
Correct |
75 ms |
12640 KB |
Output is correct |
15 |
Correct |
74 ms |
12688 KB |
Output is correct |
16 |
Correct |
70 ms |
12672 KB |
Output is correct |
17 |
Correct |
71 ms |
12620 KB |
Output is correct |
18 |
Correct |
78 ms |
12856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8276 KB |
Output is correct |
2 |
Correct |
9 ms |
8404 KB |
Output is correct |
3 |
Correct |
12 ms |
8988 KB |
Output is correct |
4 |
Correct |
10 ms |
8924 KB |
Output is correct |
5 |
Correct |
10 ms |
8920 KB |
Output is correct |
6 |
Correct |
9 ms |
8884 KB |
Output is correct |
7 |
Correct |
11 ms |
8916 KB |
Output is correct |
8 |
Correct |
10 ms |
8916 KB |
Output is correct |
9 |
Correct |
12 ms |
8916 KB |
Output is correct |
10 |
Correct |
11 ms |
8792 KB |
Output is correct |
11 |
Correct |
10 ms |
8788 KB |
Output is correct |
12 |
Correct |
11 ms |
8828 KB |
Output is correct |
13 |
Correct |
10 ms |
8788 KB |
Output is correct |
14 |
Correct |
10 ms |
8792 KB |
Output is correct |
15 |
Correct |
12 ms |
8868 KB |
Output is correct |
16 |
Correct |
9 ms |
8788 KB |
Output is correct |
17 |
Correct |
10 ms |
8788 KB |
Output is correct |
18 |
Correct |
10 ms |
8796 KB |
Output is correct |
19 |
Correct |
34 ms |
11140 KB |
Output is correct |
20 |
Correct |
37 ms |
11524 KB |
Output is correct |
21 |
Correct |
39 ms |
11528 KB |
Output is correct |
22 |
Correct |
36 ms |
11476 KB |
Output is correct |
23 |
Correct |
34 ms |
11192 KB |
Output is correct |
24 |
Correct |
35 ms |
11212 KB |
Output is correct |
25 |
Correct |
32 ms |
11040 KB |
Output is correct |
26 |
Correct |
31 ms |
11084 KB |
Output is correct |
27 |
Correct |
31 ms |
10956 KB |
Output is correct |
28 |
Correct |
33 ms |
10920 KB |
Output is correct |
29 |
Correct |
20 ms |
9868 KB |
Output is correct |
30 |
Correct |
62 ms |
11432 KB |
Output is correct |
31 |
Correct |
105 ms |
12684 KB |
Output is correct |
32 |
Correct |
106 ms |
12696 KB |
Output is correct |
33 |
Correct |
115 ms |
12700 KB |
Output is correct |
34 |
Correct |
100 ms |
12688 KB |
Output is correct |
35 |
Correct |
91 ms |
12640 KB |
Output is correct |
36 |
Correct |
97 ms |
12644 KB |
Output is correct |
37 |
Correct |
94 ms |
12676 KB |
Output is correct |
38 |
Correct |
74 ms |
12656 KB |
Output is correct |
39 |
Correct |
72 ms |
12624 KB |
Output is correct |
40 |
Correct |
76 ms |
12584 KB |
Output is correct |
41 |
Correct |
73 ms |
12644 KB |
Output is correct |
42 |
Correct |
75 ms |
12640 KB |
Output is correct |
43 |
Correct |
74 ms |
12688 KB |
Output is correct |
44 |
Correct |
70 ms |
12672 KB |
Output is correct |
45 |
Correct |
71 ms |
12620 KB |
Output is correct |
46 |
Correct |
78 ms |
12856 KB |
Output is correct |
47 |
Correct |
1429 ms |
72184 KB |
Output is correct |
48 |
Correct |
5541 ms |
201656 KB |
Output is correct |
49 |
Correct |
6101 ms |
219624 KB |
Output is correct |
50 |
Correct |
6106 ms |
219508 KB |
Output is correct |
51 |
Correct |
6198 ms |
219480 KB |
Output is correct |
52 |
Correct |
5924 ms |
219588 KB |
Output is correct |
53 |
Correct |
6200 ms |
219904 KB |
Output is correct |
54 |
Correct |
5449 ms |
219652 KB |
Output is correct |
55 |
Correct |
5914 ms |
219408 KB |
Output is correct |
56 |
Correct |
5604 ms |
219724 KB |
Output is correct |
57 |
Correct |
5871 ms |
219612 KB |
Output is correct |
58 |
Correct |
5324 ms |
219504 KB |
Output is correct |
59 |
Correct |
4705 ms |
200816 KB |
Output is correct |
60 |
Correct |
4829 ms |
200904 KB |
Output is correct |
61 |
Correct |
4765 ms |
200760 KB |
Output is correct |
62 |
Correct |
4908 ms |
191792 KB |
Output is correct |
63 |
Correct |
4707 ms |
191852 KB |
Output is correct |
64 |
Correct |
4382 ms |
192180 KB |
Output is correct |
65 |
Correct |
4197 ms |
182904 KB |
Output is correct |
66 |
Correct |
4075 ms |
183044 KB |
Output is correct |
67 |
Correct |
4051 ms |
182928 KB |
Output is correct |