Submission #1094768

# Submission time Handle Problem Language Result Execution time Memory
1094768 2024-09-30T13:41:43 Z vjudge1 Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
1260 ms 51648 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());
	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(n+q);
	auto upd=[&](int i,int v){
		s.update(a[i],a[i],i*v);
		s.update(a[i]+1,n+q,-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 348 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 3 ms 600 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 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 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 4 ms 656 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 3 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 348 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 3 ms 600 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 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 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 4 ms 656 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 11 ms 1116 KB Output is correct
20 Correct 13 ms 1116 KB Output is correct
21 Correct 13 ms 1116 KB Output is correct
22 Correct 13 ms 1248 KB Output is correct
23 Correct 12 ms 1116 KB Output is correct
24 Correct 13 ms 1080 KB Output is correct
25 Correct 13 ms 1208 KB Output is correct
26 Correct 12 ms 1192 KB Output is correct
27 Correct 12 ms 1112 KB Output is correct
28 Correct 12 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1504 KB Output is correct
2 Correct 56 ms 3100 KB Output is correct
3 Correct 98 ms 5316 KB Output is correct
4 Correct 93 ms 5324 KB Output is correct
5 Correct 94 ms 5320 KB Output is correct
6 Correct 92 ms 5316 KB Output is correct
7 Correct 95 ms 5320 KB Output is correct
8 Correct 95 ms 5324 KB Output is correct
9 Correct 91 ms 5320 KB Output is correct
10 Correct 99 ms 5432 KB Output is correct
11 Correct 82 ms 5320 KB Output is correct
12 Correct 83 ms 5328 KB Output is correct
13 Correct 83 ms 5328 KB Output is correct
14 Correct 81 ms 5412 KB Output is correct
15 Correct 81 ms 5416 KB Output is correct
16 Correct 79 ms 5320 KB Output is correct
17 Correct 86 ms 5408 KB Output is correct
18 Correct 79 ms 5408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 3 ms 600 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 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 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 4 ms 656 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 11 ms 1116 KB Output is correct
20 Correct 13 ms 1116 KB Output is correct
21 Correct 13 ms 1116 KB Output is correct
22 Correct 13 ms 1248 KB Output is correct
23 Correct 12 ms 1116 KB Output is correct
24 Correct 13 ms 1080 KB Output is correct
25 Correct 13 ms 1208 KB Output is correct
26 Correct 12 ms 1192 KB Output is correct
27 Correct 12 ms 1112 KB Output is correct
28 Correct 12 ms 1116 KB Output is correct
29 Correct 20 ms 1504 KB Output is correct
30 Correct 56 ms 3100 KB Output is correct
31 Correct 98 ms 5316 KB Output is correct
32 Correct 93 ms 5324 KB Output is correct
33 Correct 94 ms 5320 KB Output is correct
34 Correct 92 ms 5316 KB Output is correct
35 Correct 95 ms 5320 KB Output is correct
36 Correct 95 ms 5324 KB Output is correct
37 Correct 91 ms 5320 KB Output is correct
38 Correct 99 ms 5432 KB Output is correct
39 Correct 82 ms 5320 KB Output is correct
40 Correct 83 ms 5328 KB Output is correct
41 Correct 83 ms 5328 KB Output is correct
42 Correct 81 ms 5412 KB Output is correct
43 Correct 81 ms 5416 KB Output is correct
44 Correct 79 ms 5320 KB Output is correct
45 Correct 86 ms 5408 KB Output is correct
46 Correct 79 ms 5408 KB Output is correct
47 Correct 330 ms 20408 KB Output is correct
48 Correct 1127 ms 49076 KB Output is correct
49 Correct 1205 ms 51420 KB Output is correct
50 Correct 1222 ms 51368 KB Output is correct
51 Correct 1172 ms 51416 KB Output is correct
52 Correct 1260 ms 51376 KB Output is correct
53 Correct 1201 ms 51384 KB Output is correct
54 Correct 1148 ms 51372 KB Output is correct
55 Correct 1147 ms 51632 KB Output is correct
56 Correct 1118 ms 51376 KB Output is correct
57 Correct 1193 ms 51592 KB Output is correct
58 Correct 1171 ms 51648 KB Output is correct
59 Correct 1071 ms 50100 KB Output is correct
60 Correct 1088 ms 50100 KB Output is correct
61 Correct 1099 ms 50356 KB Output is correct
62 Correct 1091 ms 50044 KB Output is correct
63 Correct 1076 ms 50044 KB Output is correct
64 Correct 1109 ms 50096 KB Output is correct
65 Correct 1097 ms 49844 KB Output is correct
66 Correct 1080 ms 49784 KB Output is correct
67 Correct 1083 ms 49952 KB Output is correct