Submission #58847

# Submission time Handle Problem Language Result Execution time Memory
58847 2018-07-19T16:04:56 Z khohko Bubble Sort 2 (JOI18_bubblesort2) C++17
38 / 100
8710 ms 2048 KB
#include<bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
 
#define ll int
#define fr first
#define sc second
#define pb push_back
#define ARRS ((ll)(2e6+100))
#define MAX ((ll)(1e17+100))
 
ll fw[ARRS];
ll add(ll i,ll x){
	i++;
	while(i<=8005){
		fw[i]+=x;
		i+=i&-i;
	}
}
 
ll sum(ll i){
	i++;
	ll p=0;
	while(i>0){
		p+=fw[i];
		i-=i&-i;
	}
	return p;
}
 
 
ll t[8005];
ll slv(vector<ll> a){
	for(int i=0; i<8005; i++)fw[i]=0;
	ll n=a.size();
	vector<pair<ll,ll> > b;
	for(int i=0; i<n; i++)b.pb({a[i],i});
	sort(b.begin(),b.end());
	ll c=1;
//	for(int i=0; i<n; i++)cout<<a[i]<<" \n"[i==n-1];
	for(int i=0; i<n; i++){
		if(i&&b[i].fr!=b[i-1].fr)c++;
		a[b[i].sc]=c;
	}
//	for(int i=0; i<n; i++)cout<<a[i]<<" \n"[i==n-1];
 
 
	ll pas=0;
	for(int i=0; i<8005; i++)fw[i]=0;
//	for(int i=0; i<n; i++)
//		cout<<a[i]<<" \n"[i==n-1];
	for(int i=0; i<n; i++){
		//cout<<t[i]<<" "<<sum(n-a[i]-1)<<endl;
		pas=max(pas,sum(n-a[i]-1));
		add(n-a[i],1);
	}
	return pas;
}
 
vector<int> countScans(vector<int> a,vector<int> X,vector<int> V){
	ll n;
	n=a.size();
	ll q=X.size();
	vector<ll> PAS;
//	for(int i=0; i<q; i++){
//		ll k=X[i];
//		ll p=V[i];
//		s[a[k]].erase(k);
//		a[k]=p;
//		s[a[k]].insert(k);
//		ll pas=0;
//		for(int j=1; j<=100; j++){
//			if(st[j].size())
//				v.pb({*st[j].begin(),j});
//			if(st[j].size()>1)
//				v.pb({*(--st[j].end()),j});
//			pas+=max(0,st[j].size()-2);
//		}
//		sort(v.begin(),v.end());
//		for(auto x:v){
//			g.pb(x.sc);
//		}
//		PAS.pb(pas+slv(g));
//	}
	for(int i=0; i<q; i++){
		ll k=X[i];
		ll p=V[i];
		a[k]=p;
//		cout<<slv(a)<<endl;
		PAS.pb(slv(a));
	}
//	cout<<c<<endl;
//	cout<<"-----"<<endl;
	return PAS;
}

Compilation message

bubblesort2.cpp: In function 'int add(int, int)':
bubblesort2.cpp:19:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:61:5: warning: variable 'n' set but not used [-Wunused-but-set-variable]
  ll n;
     ^
# Verdict Execution time Memory Grader output
1 Correct 34 ms 504 KB Output is correct
2 Correct 97 ms 504 KB Output is correct
3 Correct 447 ms 624 KB Output is correct
4 Correct 452 ms 672 KB Output is correct
5 Correct 451 ms 732 KB Output is correct
6 Correct 417 ms 740 KB Output is correct
7 Correct 386 ms 760 KB Output is correct
8 Correct 449 ms 760 KB Output is correct
9 Correct 446 ms 760 KB Output is correct
10 Correct 318 ms 784 KB Output is correct
11 Correct 330 ms 796 KB Output is correct
12 Correct 315 ms 800 KB Output is correct
13 Correct 284 ms 800 KB Output is correct
14 Correct 316 ms 800 KB Output is correct
15 Correct 323 ms 812 KB Output is correct
16 Correct 352 ms 812 KB Output is correct
17 Correct 311 ms 812 KB Output is correct
18 Correct 287 ms 812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 504 KB Output is correct
2 Correct 97 ms 504 KB Output is correct
3 Correct 447 ms 624 KB Output is correct
4 Correct 452 ms 672 KB Output is correct
5 Correct 451 ms 732 KB Output is correct
6 Correct 417 ms 740 KB Output is correct
7 Correct 386 ms 760 KB Output is correct
8 Correct 449 ms 760 KB Output is correct
9 Correct 446 ms 760 KB Output is correct
10 Correct 318 ms 784 KB Output is correct
11 Correct 330 ms 796 KB Output is correct
12 Correct 315 ms 800 KB Output is correct
13 Correct 284 ms 800 KB Output is correct
14 Correct 316 ms 800 KB Output is correct
15 Correct 323 ms 812 KB Output is correct
16 Correct 352 ms 812 KB Output is correct
17 Correct 311 ms 812 KB Output is correct
18 Correct 287 ms 812 KB Output is correct
19 Correct 5807 ms 1028 KB Output is correct
20 Correct 7571 ms 1056 KB Output is correct
21 Correct 7053 ms 1056 KB Output is correct
22 Correct 6948 ms 1068 KB Output is correct
23 Correct 4779 ms 1068 KB Output is correct
24 Correct 5243 ms 1156 KB Output is correct
25 Correct 4921 ms 1156 KB Output is correct
26 Correct 4840 ms 1156 KB Output is correct
27 Correct 4961 ms 1156 KB Output is correct
28 Correct 5410 ms 1156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 8710 ms 2048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 504 KB Output is correct
2 Correct 97 ms 504 KB Output is correct
3 Correct 447 ms 624 KB Output is correct
4 Correct 452 ms 672 KB Output is correct
5 Correct 451 ms 732 KB Output is correct
6 Correct 417 ms 740 KB Output is correct
7 Correct 386 ms 760 KB Output is correct
8 Correct 449 ms 760 KB Output is correct
9 Correct 446 ms 760 KB Output is correct
10 Correct 318 ms 784 KB Output is correct
11 Correct 330 ms 796 KB Output is correct
12 Correct 315 ms 800 KB Output is correct
13 Correct 284 ms 800 KB Output is correct
14 Correct 316 ms 800 KB Output is correct
15 Correct 323 ms 812 KB Output is correct
16 Correct 352 ms 812 KB Output is correct
17 Correct 311 ms 812 KB Output is correct
18 Correct 287 ms 812 KB Output is correct
19 Correct 5807 ms 1028 KB Output is correct
20 Correct 7571 ms 1056 KB Output is correct
21 Correct 7053 ms 1056 KB Output is correct
22 Correct 6948 ms 1068 KB Output is correct
23 Correct 4779 ms 1068 KB Output is correct
24 Correct 5243 ms 1156 KB Output is correct
25 Correct 4921 ms 1156 KB Output is correct
26 Correct 4840 ms 1156 KB Output is correct
27 Correct 4961 ms 1156 KB Output is correct
28 Correct 5410 ms 1156 KB Output is correct
29 Incorrect 8710 ms 2048 KB Output isn't correct
30 Halted 0 ms 0 KB -