Submission #925062

# Submission time Handle Problem Language Result Execution time Memory
925062 2024-02-10T16:01:26 Z ttamx Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
1513 ms 51860 KB
#include "bubblesort2.h"
#include<bits/stdc++.h>

using namespace std;

using pi = pair<int,int>;

struct Segtree{
	int n;
	vector<int> t,lz;
	Segtree(int _n){
		n=_n;
		int s=4<<(31-__builtin_clz(n));
		t.assign(s,0);
		lz.assign(s,0);
	}
	void push(int l,int r,int i){
		t[i]+=lz[i];
		if(l<r){
			lz[i*2]+=lz[i];
			lz[i*2+1]+=lz[i];
		}
		lz[i]=0;
	}
	void update(int l,int r,int i,int x,int y,int v){
		push(l,r,i);
		if(y<l||r<x)return;
		if(x<=l&&r<=y)return lz[i]=v,push(l,r,i);
		int m=(l+r)/2;
		update(l,m,i*2,x,y,v);
		update(m+1,r,i*2+1,x,y,v);
		t[i]=max(t[i*2],t[i*2+1]);
	}
	void update(int x,int y,int v){
		update(0,n-1,1,x,y,v);
	}
};

vector<int> countScans(vector<int> a,vector<int> x,vector<int> v){
	int n=a.size();
	int q=x.size();
	vector<int> ans(q);
	vector<pi> vec;
	for(int i=0;i<n;i++)vec.emplace_back(a[i],i);
	for(int i=0;i<q;i++)vec.emplace_back(v[i],x[i]);
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());
	int m=vec.size();
	for(int i=0;i<n;i++)a[i]=lower_bound(vec.begin(),vec.end(),pi(a[i],i))-vec.begin();
	for(int i=0;i<q;i++)v[i]=lower_bound(vec.begin(),vec.end(),pi(v[i],x[i]))-vec.begin();
	Segtree s(m);
	auto upd=[&](int i,int v){
		s.update(a[i],a[i],i*v);
		s.update(a[i]+1,m,-v);
	};
	for(int i=0;i<n;i++)upd(i,1);
	for(int i=0;i<q;i++){
		upd(x[i],-1);
		a[x[i]]=v[i];
		upd(x[i],1);
		ans[i]=s.t[1];
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 520 KB Output is correct
3 Correct 4 ms 456 KB Output is correct
4 Correct 4 ms 872 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 5 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 4 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 520 KB Output is correct
3 Correct 4 ms 456 KB Output is correct
4 Correct 4 ms 872 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 5 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 4 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
19 Correct 16 ms 1116 KB Output is correct
20 Correct 14 ms 860 KB Output is correct
21 Correct 14 ms 860 KB Output is correct
22 Correct 16 ms 856 KB Output is correct
23 Correct 17 ms 1048 KB Output is correct
24 Correct 13 ms 860 KB Output is correct
25 Correct 14 ms 1060 KB Output is correct
26 Correct 13 ms 860 KB Output is correct
27 Correct 13 ms 860 KB Output is correct
28 Correct 13 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1504 KB Output is correct
2 Correct 68 ms 2904 KB Output is correct
3 Correct 109 ms 4768 KB Output is correct
4 Correct 112 ms 4772 KB Output is correct
5 Correct 108 ms 4560 KB Output is correct
6 Correct 109 ms 4556 KB Output is correct
7 Correct 106 ms 4772 KB Output is correct
8 Correct 108 ms 4724 KB Output is correct
9 Correct 123 ms 4772 KB Output is correct
10 Correct 87 ms 3476 KB Output is correct
11 Correct 88 ms 3528 KB Output is correct
12 Correct 90 ms 3608 KB Output is correct
13 Correct 87 ms 3536 KB Output is correct
14 Correct 85 ms 3496 KB Output is correct
15 Correct 85 ms 3536 KB Output is correct
16 Correct 85 ms 3536 KB Output is correct
17 Correct 84 ms 3524 KB Output is correct
18 Correct 84 ms 3524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 520 KB Output is correct
3 Correct 4 ms 456 KB Output is correct
4 Correct 4 ms 872 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 5 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 4 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
19 Correct 16 ms 1116 KB Output is correct
20 Correct 14 ms 860 KB Output is correct
21 Correct 14 ms 860 KB Output is correct
22 Correct 16 ms 856 KB Output is correct
23 Correct 17 ms 1048 KB Output is correct
24 Correct 13 ms 860 KB Output is correct
25 Correct 14 ms 1060 KB Output is correct
26 Correct 13 ms 860 KB Output is correct
27 Correct 13 ms 860 KB Output is correct
28 Correct 13 ms 1112 KB Output is correct
29 Correct 21 ms 1504 KB Output is correct
30 Correct 68 ms 2904 KB Output is correct
31 Correct 109 ms 4768 KB Output is correct
32 Correct 112 ms 4772 KB Output is correct
33 Correct 108 ms 4560 KB Output is correct
34 Correct 109 ms 4556 KB Output is correct
35 Correct 106 ms 4772 KB Output is correct
36 Correct 108 ms 4724 KB Output is correct
37 Correct 123 ms 4772 KB Output is correct
38 Correct 87 ms 3476 KB Output is correct
39 Correct 88 ms 3528 KB Output is correct
40 Correct 90 ms 3608 KB Output is correct
41 Correct 87 ms 3536 KB Output is correct
42 Correct 85 ms 3496 KB Output is correct
43 Correct 85 ms 3536 KB Output is correct
44 Correct 85 ms 3536 KB Output is correct
45 Correct 84 ms 3524 KB Output is correct
46 Correct 84 ms 3524 KB Output is correct
47 Correct 374 ms 15452 KB Output is correct
48 Correct 1395 ms 49820 KB Output is correct
49 Correct 1495 ms 51640 KB Output is correct
50 Correct 1470 ms 51636 KB Output is correct
51 Correct 1482 ms 51496 KB Output is correct
52 Correct 1513 ms 51416 KB Output is correct
53 Correct 1489 ms 51320 KB Output is correct
54 Correct 1405 ms 51780 KB Output is correct
55 Correct 1472 ms 51600 KB Output is correct
56 Correct 1396 ms 51564 KB Output is correct
57 Correct 1426 ms 51844 KB Output is correct
58 Correct 1454 ms 51860 KB Output is correct
59 Correct 1436 ms 50236 KB Output is correct
60 Correct 1382 ms 50352 KB Output is correct
61 Correct 1361 ms 50472 KB Output is correct
62 Correct 1363 ms 50092 KB Output is correct
63 Correct 1286 ms 50096 KB Output is correct
64 Correct 1321 ms 50312 KB Output is correct
65 Correct 1317 ms 49844 KB Output is correct
66 Correct 1265 ms 50076 KB Output is correct
67 Correct 1337 ms 50100 KB Output is correct