Submission #145589

# Submission time Handle Problem Language Result Execution time Memory
145589 2019-08-20T13:04:04 Z bharat2002 Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
4807 ms 161224 KB
/*input
8
1 1 1 1 1 1 2 1
*/
#include<bits/stdc++.h>
using namespace std;
const int N=1e6 + 1099;
const int mod=1e9 + 7;
#define pii pair<int, int>
#define f first
#define s second 
#define mp make_pair
int n;map<int, int> conv; 
multiset<int> positions[N];
class tree
{
	int tree[4*N], lazy[4*N], ql, qr, val;
	void prop(int i, int l, int r)
	{
		tree[i]+=lazy[i];
		if(l!=r)
		{
			lazy[2*i]+=lazy[i];lazy[2*i+1]+=lazy[i];
		}
		lazy[i]=0;
	}
	void update(int i=1, int l=1, int r=N-1)
	{
		prop(i, l, r);
		if(l>qr||r<ql) return;
		if(l>=ql&&r<=qr)
		{
			lazy[i]+=val;prop(i, l, r);
			return;
		}
		int mid=(l+r)>>1;update(2*i, l, mid);update(2*i+1, mid+1, r);tree[i]=max(tree[2*i], tree[2*i+1]);
	}
	public:
	void remove(int ind, int el)
	{
		int prevmax=(*positions[el].rbegin());
		positions[el].erase(ind);
		if(!positions[el].empty()) prevmax=(*positions[el].rbegin()) - prevmax;
		else prevmax*=-1;
		ql=qr=el;val=prevmax;
		if(val!=0) update();
		ql=el+1;qr=N-1;val=+1;
		if(!positions[el].empty()) ql--;
		update();
	}
	void add(int ind, int el)
	{
		int prevmax=0;
		if(!positions[el].empty()) prevmax=(*positions[el].rbegin());
		positions[el].insert(ind);
		prevmax=(*positions[el].rbegin() - prevmax);
		ql=qr=el;val=prevmax;
		if(val!=0) update();
		ql=el+1;qr=N-1;val=-1;
		if(positions[el].size()>1) ql--;
		update();
	}
	int qry()
	{
		return tree[1];
	}
};
tree Segtree;
vector<int> countScans(vector<int> arr, vector<int> pos, vector<int> nval)
{
	n=arr.size();int q=pos.size();vector<int> ans;
	conv.clear();
	for(auto i:arr) conv[i]=0;
	for(auto i:nval) conv[i]=0;
	int curv=1;
	for(auto &i:conv) i.s=curv++;
	for(int i=0;i<n;i++) {arr[i]=conv[arr[i]];Segtree.add(i, arr[i]);}
	for(auto &i:nval) i=conv[i];
	//cout<<Segtree.qry()<<endl;
	for(int i=0;i<q;i++)
	{
		Segtree.remove(pos[i], arr[pos[i]]);
		Segtree.add(pos[i], nval[i]);arr[pos[i]]=nval[i];
		ans.push_back(Segtree.qry());
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 47 ms 47736 KB Output is correct
2 Correct 49 ms 47608 KB Output is correct
3 Correct 53 ms 47864 KB Output is correct
4 Correct 53 ms 47980 KB Output is correct
5 Correct 54 ms 47864 KB Output is correct
6 Correct 53 ms 47864 KB Output is correct
7 Correct 53 ms 47964 KB Output is correct
8 Correct 53 ms 47992 KB Output is correct
9 Correct 54 ms 47992 KB Output is correct
10 Correct 53 ms 47896 KB Output is correct
11 Correct 53 ms 47868 KB Output is correct
12 Correct 53 ms 47864 KB Output is correct
13 Correct 53 ms 47864 KB Output is correct
14 Correct 52 ms 47864 KB Output is correct
15 Correct 52 ms 47864 KB Output is correct
16 Correct 52 ms 47836 KB Output is correct
17 Correct 52 ms 47864 KB Output is correct
18 Correct 53 ms 47864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 47736 KB Output is correct
2 Correct 49 ms 47608 KB Output is correct
3 Correct 53 ms 47864 KB Output is correct
4 Correct 53 ms 47980 KB Output is correct
5 Correct 54 ms 47864 KB Output is correct
6 Correct 53 ms 47864 KB Output is correct
7 Correct 53 ms 47964 KB Output is correct
8 Correct 53 ms 47992 KB Output is correct
9 Correct 54 ms 47992 KB Output is correct
10 Correct 53 ms 47896 KB Output is correct
11 Correct 53 ms 47868 KB Output is correct
12 Correct 53 ms 47864 KB Output is correct
13 Correct 53 ms 47864 KB Output is correct
14 Correct 52 ms 47864 KB Output is correct
15 Correct 52 ms 47864 KB Output is correct
16 Correct 52 ms 47836 KB Output is correct
17 Correct 52 ms 47864 KB Output is correct
18 Correct 53 ms 47864 KB Output is correct
19 Correct 75 ms 49060 KB Output is correct
20 Correct 81 ms 49400 KB Output is correct
21 Correct 77 ms 49272 KB Output is correct
22 Correct 80 ms 49400 KB Output is correct
23 Correct 89 ms 49144 KB Output is correct
24 Correct 77 ms 49144 KB Output is correct
25 Correct 77 ms 49144 KB Output is correct
26 Correct 79 ms 49160 KB Output is correct
27 Correct 75 ms 49016 KB Output is correct
28 Correct 87 ms 49144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 49148 KB Output is correct
2 Correct 135 ms 50552 KB Output is correct
3 Correct 211 ms 51904 KB Output is correct
4 Correct 199 ms 51960 KB Output is correct
5 Correct 190 ms 51932 KB Output is correct
6 Correct 190 ms 51960 KB Output is correct
7 Correct 185 ms 51960 KB Output is correct
8 Correct 189 ms 52088 KB Output is correct
9 Correct 202 ms 52048 KB Output is correct
10 Correct 176 ms 52088 KB Output is correct
11 Correct 181 ms 51960 KB Output is correct
12 Correct 189 ms 51988 KB Output is correct
13 Correct 183 ms 52088 KB Output is correct
14 Correct 172 ms 52088 KB Output is correct
15 Correct 173 ms 52004 KB Output is correct
16 Correct 172 ms 52216 KB Output is correct
17 Correct 165 ms 52088 KB Output is correct
18 Correct 166 ms 52004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 47736 KB Output is correct
2 Correct 49 ms 47608 KB Output is correct
3 Correct 53 ms 47864 KB Output is correct
4 Correct 53 ms 47980 KB Output is correct
5 Correct 54 ms 47864 KB Output is correct
6 Correct 53 ms 47864 KB Output is correct
7 Correct 53 ms 47964 KB Output is correct
8 Correct 53 ms 47992 KB Output is correct
9 Correct 54 ms 47992 KB Output is correct
10 Correct 53 ms 47896 KB Output is correct
11 Correct 53 ms 47868 KB Output is correct
12 Correct 53 ms 47864 KB Output is correct
13 Correct 53 ms 47864 KB Output is correct
14 Correct 52 ms 47864 KB Output is correct
15 Correct 52 ms 47864 KB Output is correct
16 Correct 52 ms 47836 KB Output is correct
17 Correct 52 ms 47864 KB Output is correct
18 Correct 53 ms 47864 KB Output is correct
19 Correct 75 ms 49060 KB Output is correct
20 Correct 81 ms 49400 KB Output is correct
21 Correct 77 ms 49272 KB Output is correct
22 Correct 80 ms 49400 KB Output is correct
23 Correct 89 ms 49144 KB Output is correct
24 Correct 77 ms 49144 KB Output is correct
25 Correct 77 ms 49144 KB Output is correct
26 Correct 79 ms 49160 KB Output is correct
27 Correct 75 ms 49016 KB Output is correct
28 Correct 87 ms 49144 KB Output is correct
29 Correct 81 ms 49148 KB Output is correct
30 Correct 135 ms 50552 KB Output is correct
31 Correct 211 ms 51904 KB Output is correct
32 Correct 199 ms 51960 KB Output is correct
33 Correct 190 ms 51932 KB Output is correct
34 Correct 190 ms 51960 KB Output is correct
35 Correct 185 ms 51960 KB Output is correct
36 Correct 189 ms 52088 KB Output is correct
37 Correct 202 ms 52048 KB Output is correct
38 Correct 176 ms 52088 KB Output is correct
39 Correct 181 ms 51960 KB Output is correct
40 Correct 189 ms 51988 KB Output is correct
41 Correct 183 ms 52088 KB Output is correct
42 Correct 172 ms 52088 KB Output is correct
43 Correct 173 ms 52004 KB Output is correct
44 Correct 172 ms 52216 KB Output is correct
45 Correct 165 ms 52088 KB Output is correct
46 Correct 166 ms 52004 KB Output is correct
47 Correct 1224 ms 82128 KB Output is correct
48 Correct 4310 ms 150132 KB Output is correct
49 Correct 4807 ms 161132 KB Output is correct
50 Correct 4657 ms 161184 KB Output is correct
51 Correct 4650 ms 161040 KB Output is correct
52 Correct 4734 ms 161148 KB Output is correct
53 Correct 4637 ms 161056 KB Output is correct
54 Correct 4145 ms 161224 KB Output is correct
55 Correct 4747 ms 161104 KB Output is correct
56 Correct 4112 ms 161012 KB Output is correct
57 Correct 4466 ms 161168 KB Output is correct
58 Correct 4202 ms 161000 KB Output is correct
59 Correct 3827 ms 151968 KB Output is correct
60 Correct 3892 ms 152012 KB Output is correct
61 Correct 3797 ms 152084 KB Output is correct
62 Correct 3624 ms 148036 KB Output is correct
63 Correct 3607 ms 147896 KB Output is correct
64 Correct 3712 ms 147968 KB Output is correct
65 Correct 3423 ms 143992 KB Output is correct
66 Correct 3330 ms 143812 KB Output is correct
67 Correct 3598 ms 143864 KB Output is correct