Submission #887113

# Submission time Handle Problem Language Result Execution time Memory
887113 2023-12-13T19:35:30 Z amirhoseinfar1385 Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
1851 ms 51648 KB
#include "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;

int n,q;
int kaf=(1<<20);
struct segment{
	struct node{
		int maxa,lazy;
		node(){
			maxa=lazy=0;
		}
	};
	node seg[(1<<21)];
	void calc(int i){
		if(i>=kaf){
			seg[i].maxa+=seg[i].lazy;
			seg[i].lazy=0;
			return ;
		}
		seg[i].maxa=max(seg[(i<<1)].maxa+seg[(i<<1)].lazy,seg[(i<<1)^1].maxa+seg[(i<<1)^1].lazy);
	}
	void shift(int i){
		if(i>=kaf){
			calc(i);
			return ;
		}
		seg[(i<<1)].lazy+=seg[i].lazy;
		seg[(i<<1)^1].lazy+=seg[i].lazy;
		seg[i].lazy=0;
		return ;
	}
	void upd(int i,int l,int r,int tl,int tr,int w){
		if(l>r||l>tr||r<tl||tl>tr){
			return ;
		}
		if(l>=tl&&r<=tr){
			seg[i].lazy+=w;
			shift(i);
			calc(i);
			return ;
		}
		int m=(l+r)>>1;
		shift(i);
		upd((i<<1),l,m,tl,tr,w);
		upd((i<<1)^1,m+1,r,tl,tr,w);
		calc(i);
	}
}seg;


std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
	n=A.size(),q=X.size();
	vector<pair<int,int>>allind;
	for(int i=0;i<n;i++){
		allind.push_back(make_pair(A[i],i));
	}
	for(int i=0;i<q;i++){
		allind.push_back(make_pair(V[i],X[i]));
	}
	sort(allind.begin(),allind.end());
	allind.resize(unique(allind.begin(),allind.end())-allind.begin());
	int sz=allind.size();
	for(int i=0;i<n;i++){
		int p=lower_bound(allind.begin(),allind.end(),make_pair(A[i],i))-allind.begin();
		seg.upd(1,0,kaf-1,p,p,i);
		seg.upd(1,0,kaf-1,p+1,sz,-1);
	}
	vector<int>res(q);
	for(int i=0;i<q;i++){
		int ind=X[i],val=V[i],p=lower_bound(allind.begin(),allind.end(),make_pair(A[ind],ind))-allind.begin();
		seg.upd(1,0,kaf-1,p,p,-ind);
		seg.upd(1,0,kaf-1,p+1,sz,1);
		A[ind]=val;
		p=lower_bound(allind.begin(),allind.end(),make_pair(val,ind))-allind.begin();
		seg.upd(1,0,kaf-1,p,p,ind);
		seg.upd(1,0,kaf-1,p+1,sz,-1);
		res[i]=seg.seg[1].maxa>0?seg.seg[1].maxa:0;
	}
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 16988 KB Output is correct
2 Correct 6 ms 16732 KB Output is correct
3 Correct 9 ms 16988 KB Output is correct
4 Correct 9 ms 16864 KB Output is correct
5 Correct 9 ms 16988 KB Output is correct
6 Correct 8 ms 16988 KB Output is correct
7 Correct 8 ms 16772 KB Output is correct
8 Correct 8 ms 16988 KB Output is correct
9 Correct 8 ms 16756 KB Output is correct
10 Correct 8 ms 16984 KB Output is correct
11 Correct 9 ms 16984 KB Output is correct
12 Correct 9 ms 16988 KB Output is correct
13 Correct 8 ms 16988 KB Output is correct
14 Correct 9 ms 16988 KB Output is correct
15 Correct 9 ms 16988 KB Output is correct
16 Correct 9 ms 16988 KB Output is correct
17 Correct 8 ms 16988 KB Output is correct
18 Correct 9 ms 16860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 16988 KB Output is correct
2 Correct 6 ms 16732 KB Output is correct
3 Correct 9 ms 16988 KB Output is correct
4 Correct 9 ms 16864 KB Output is correct
5 Correct 9 ms 16988 KB Output is correct
6 Correct 8 ms 16988 KB Output is correct
7 Correct 8 ms 16772 KB Output is correct
8 Correct 8 ms 16988 KB Output is correct
9 Correct 8 ms 16756 KB Output is correct
10 Correct 8 ms 16984 KB Output is correct
11 Correct 9 ms 16984 KB Output is correct
12 Correct 9 ms 16988 KB Output is correct
13 Correct 8 ms 16988 KB Output is correct
14 Correct 9 ms 16988 KB Output is correct
15 Correct 9 ms 16988 KB Output is correct
16 Correct 9 ms 16988 KB Output is correct
17 Correct 8 ms 16988 KB Output is correct
18 Correct 9 ms 16860 KB Output is correct
19 Correct 21 ms 17244 KB Output is correct
20 Correct 25 ms 17496 KB Output is correct
21 Correct 26 ms 17368 KB Output is correct
22 Correct 26 ms 17364 KB Output is correct
23 Correct 24 ms 17244 KB Output is correct
24 Correct 24 ms 17332 KB Output is correct
25 Correct 24 ms 17372 KB Output is correct
26 Correct 23 ms 17328 KB Output is correct
27 Correct 24 ms 17244 KB Output is correct
28 Correct 23 ms 17240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 17500 KB Output is correct
2 Correct 85 ms 18392 KB Output is correct
3 Correct 140 ms 19668 KB Output is correct
4 Correct 138 ms 19588 KB Output is correct
5 Correct 142 ms 19664 KB Output is correct
6 Correct 140 ms 19668 KB Output is correct
7 Correct 147 ms 19664 KB Output is correct
8 Correct 142 ms 19664 KB Output is correct
9 Correct 135 ms 19664 KB Output is correct
10 Correct 138 ms 19660 KB Output is correct
11 Correct 127 ms 19664 KB Output is correct
12 Correct 126 ms 19668 KB Output is correct
13 Correct 126 ms 19664 KB Output is correct
14 Correct 121 ms 19668 KB Output is correct
15 Correct 126 ms 19696 KB Output is correct
16 Correct 139 ms 19780 KB Output is correct
17 Correct 124 ms 19588 KB Output is correct
18 Correct 129 ms 19588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 16988 KB Output is correct
2 Correct 6 ms 16732 KB Output is correct
3 Correct 9 ms 16988 KB Output is correct
4 Correct 9 ms 16864 KB Output is correct
5 Correct 9 ms 16988 KB Output is correct
6 Correct 8 ms 16988 KB Output is correct
7 Correct 8 ms 16772 KB Output is correct
8 Correct 8 ms 16988 KB Output is correct
9 Correct 8 ms 16756 KB Output is correct
10 Correct 8 ms 16984 KB Output is correct
11 Correct 9 ms 16984 KB Output is correct
12 Correct 9 ms 16988 KB Output is correct
13 Correct 8 ms 16988 KB Output is correct
14 Correct 9 ms 16988 KB Output is correct
15 Correct 9 ms 16988 KB Output is correct
16 Correct 9 ms 16988 KB Output is correct
17 Correct 8 ms 16988 KB Output is correct
18 Correct 9 ms 16860 KB Output is correct
19 Correct 21 ms 17244 KB Output is correct
20 Correct 25 ms 17496 KB Output is correct
21 Correct 26 ms 17368 KB Output is correct
22 Correct 26 ms 17364 KB Output is correct
23 Correct 24 ms 17244 KB Output is correct
24 Correct 24 ms 17332 KB Output is correct
25 Correct 24 ms 17372 KB Output is correct
26 Correct 23 ms 17328 KB Output is correct
27 Correct 24 ms 17244 KB Output is correct
28 Correct 23 ms 17240 KB Output is correct
29 Correct 31 ms 17500 KB Output is correct
30 Correct 85 ms 18392 KB Output is correct
31 Correct 140 ms 19668 KB Output is correct
32 Correct 138 ms 19588 KB Output is correct
33 Correct 142 ms 19664 KB Output is correct
34 Correct 140 ms 19668 KB Output is correct
35 Correct 147 ms 19664 KB Output is correct
36 Correct 142 ms 19664 KB Output is correct
37 Correct 135 ms 19664 KB Output is correct
38 Correct 138 ms 19660 KB Output is correct
39 Correct 127 ms 19664 KB Output is correct
40 Correct 126 ms 19668 KB Output is correct
41 Correct 126 ms 19664 KB Output is correct
42 Correct 121 ms 19668 KB Output is correct
43 Correct 126 ms 19696 KB Output is correct
44 Correct 139 ms 19780 KB Output is correct
45 Correct 124 ms 19588 KB Output is correct
46 Correct 129 ms 19588 KB Output is correct
47 Correct 470 ms 29068 KB Output is correct
48 Correct 1716 ms 49088 KB Output is correct
49 Correct 1800 ms 51244 KB Output is correct
50 Correct 1846 ms 51380 KB Output is correct
51 Correct 1834 ms 51492 KB Output is correct
52 Correct 1851 ms 51396 KB Output is correct
53 Correct 1850 ms 51388 KB Output is correct
54 Correct 1726 ms 51648 KB Output is correct
55 Correct 1773 ms 51376 KB Output is correct
56 Correct 1740 ms 51380 KB Output is correct
57 Correct 1765 ms 51420 KB Output is correct
58 Correct 1717 ms 51380 KB Output is correct
59 Correct 1636 ms 49844 KB Output is correct
60 Correct 1489 ms 50524 KB Output is correct
61 Correct 1600 ms 50060 KB Output is correct
62 Correct 1565 ms 49912 KB Output is correct
63 Correct 1586 ms 49924 KB Output is correct
64 Correct 1564 ms 49844 KB Output is correct
65 Correct 1513 ms 50080 KB Output is correct
66 Correct 1513 ms 50284 KB Output is correct
67 Correct 1523 ms 49776 KB Output is correct