Submission #590892

# Submission time Handle Problem Language Result Execution time Memory
590892 2022-07-06T13:27:34 Z UncoolAnon Bubble Sort 2 (JOI18_bubblesort2) C++14
38 / 100
44 ms 4584 KB
#include <bits/stdc++.h> 
#define pii pair<int,int> 
#define F first 
#define S second 
#define mp make_pair 
#define endl '\n'
using namespace std; 
const int inf=1e9,N=2e5+5,md=1e9+7; 
vector<int> countScans(vector<int> a ,vector<int> x , vector<int> v){
	set<int> c; 
	map<int,int> m; 
	for(int&x:a) c.insert(x); 
	for(int&x:v) c.insert(x); 
	int cnt=1; 
	for(int x:c) m[x]=cnt++;
	for(int&x:a) x=m[x];  
	for(int&x:v) x=m[x]; 
	vector<int> answer(x.size()),sg((cnt+5)*4); 
	vector<set<int>> cc(cnt+5); 
	vector<int> lz=sg; 
	for(int&x:sg) x=-inf; 
	for(set<int>&x:cc) x.insert(-inf); 
	function<void(int,int,int)> push=[&](int i,int l,int r){
		sg[i]+=lz[i]; 
		if(l!=r){
			lz[i*2]+=lz[i]; 
			lz[i*2+1]+=lz[i]; 
		}
		lz[i]=0; 
		return; 
	}; 
	function<void(int,int,int,int,int)> update=[&](int i,int l,int r,int index,int v){
		push(i,l,r); 
		if(index<l||r<index) return ; 
		if(l==r){
			sg[i]-=*(--cc[l].end()); 
			if(v<0) cc[l].erase(-v-1); 
			else cc[l].insert(v-1); 
			sg[i]+=*(--cc[l].end()); 
			return ; 
		}
		update(i*2,l,(r+l)/2,index,v); 
		update(i*2+1,(r+l)/2+1,r,index,v); 
		sg[i]=max(sg[i*2],sg[i*2+1]); 
		return ; 
	}; 
	function<void(int,int,int,int,int,int)> range=[&](int i,int l,int r,int ql,int qr,int v){
		push(i,l,r); 
		if(qr<l||r<ql) return;
		if(ql<=l&&r<=qr){
			lz[i]+=v; 
			push(i,l,r); 
			return; 
		}
		range(i*2,l,(r+l)/2,ql,qr,v); 
		range(i*2+1,(r+l)/2+1,r,ql,qr,v); 
		sg[i]=max(sg[i*2],sg[i*2+1]); 
		return; 
	};
	for(int i=0;i<a.size();i++){ 
		update(1,0,cnt,a[i],i+1);  
		range(1,0,cnt,a[i]+1,cnt,-1); 
	}
	for(int i=0;i<x.size();i++){
		update(1,0,cnt,a[x[i]],-(x[i]+1)); 
		range(1,0,cnt,a[x[i]]+1,cnt,1); 
		a[x[i]]=v[i]; 
		update(1,0,cnt,a[x[i]],x[i]+1); 
		range(1,0,cnt,a[x[i]]+1,cnt,-1); 
		push(1,0,cnt);
		answer[i]=sg[1]; 
	}
	return answer; 
}

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:60:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  for(int i=0;i<a.size();i++){
      |              ~^~~~~~~~~
bubblesort2.cpp:64:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for(int i=0;i<x.size();i++){
      |              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 9 ms 1364 KB Output is correct
4 Correct 9 ms 1364 KB Output is correct
5 Correct 9 ms 1364 KB Output is correct
6 Correct 8 ms 1364 KB Output is correct
7 Correct 8 ms 1364 KB Output is correct
8 Correct 8 ms 1364 KB Output is correct
9 Correct 10 ms 1320 KB Output is correct
10 Correct 8 ms 1236 KB Output is correct
11 Correct 8 ms 1236 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 8 ms 1148 KB Output is correct
14 Correct 8 ms 1116 KB Output is correct
15 Correct 8 ms 1196 KB Output is correct
16 Correct 8 ms 1108 KB Output is correct
17 Correct 8 ms 1108 KB Output is correct
18 Correct 8 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 9 ms 1364 KB Output is correct
4 Correct 9 ms 1364 KB Output is correct
5 Correct 9 ms 1364 KB Output is correct
6 Correct 8 ms 1364 KB Output is correct
7 Correct 8 ms 1364 KB Output is correct
8 Correct 8 ms 1364 KB Output is correct
9 Correct 10 ms 1320 KB Output is correct
10 Correct 8 ms 1236 KB Output is correct
11 Correct 8 ms 1236 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 8 ms 1148 KB Output is correct
14 Correct 8 ms 1116 KB Output is correct
15 Correct 8 ms 1196 KB Output is correct
16 Correct 8 ms 1108 KB Output is correct
17 Correct 8 ms 1108 KB Output is correct
18 Correct 8 ms 1108 KB Output is correct
19 Correct 36 ms 4052 KB Output is correct
20 Correct 39 ms 4584 KB Output is correct
21 Correct 38 ms 4556 KB Output is correct
22 Correct 44 ms 4524 KB Output is correct
23 Correct 39 ms 4104 KB Output is correct
24 Correct 38 ms 4140 KB Output is correct
25 Correct 36 ms 3848 KB Output is correct
26 Correct 35 ms 3796 KB Output is correct
27 Correct 35 ms 3668 KB Output is correct
28 Correct 35 ms 3668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 1928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 9 ms 1364 KB Output is correct
4 Correct 9 ms 1364 KB Output is correct
5 Correct 9 ms 1364 KB Output is correct
6 Correct 8 ms 1364 KB Output is correct
7 Correct 8 ms 1364 KB Output is correct
8 Correct 8 ms 1364 KB Output is correct
9 Correct 10 ms 1320 KB Output is correct
10 Correct 8 ms 1236 KB Output is correct
11 Correct 8 ms 1236 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 8 ms 1148 KB Output is correct
14 Correct 8 ms 1116 KB Output is correct
15 Correct 8 ms 1196 KB Output is correct
16 Correct 8 ms 1108 KB Output is correct
17 Correct 8 ms 1108 KB Output is correct
18 Correct 8 ms 1108 KB Output is correct
19 Correct 36 ms 4052 KB Output is correct
20 Correct 39 ms 4584 KB Output is correct
21 Correct 38 ms 4556 KB Output is correct
22 Correct 44 ms 4524 KB Output is correct
23 Correct 39 ms 4104 KB Output is correct
24 Correct 38 ms 4140 KB Output is correct
25 Correct 36 ms 3848 KB Output is correct
26 Correct 35 ms 3796 KB Output is correct
27 Correct 35 ms 3668 KB Output is correct
28 Correct 35 ms 3668 KB Output is correct
29 Incorrect 27 ms 1928 KB Output isn't correct
30 Halted 0 ms 0 KB -