답안 #962641

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962641 2024-04-14T05:17:43 Z pcc Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
1431 ms 111948 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("popcnt,avx2,sse4")
using namespace std;

#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fs first
#define sc second

const int mxn = 5e5+10;
const ll inf = 1e9+10;



namespace BRUTE{

	void bubble(vector<int> &v){
		for(int i = 0;i+1<v.size();i++){
			if(v[i]>v[i+1])swap(v[i],v[i+1]);
		}
		return;
	}
	bool sorted(vector<int> &v){
		for(int i = 0;i+1<v.size();i++){
			if(v[i]>v[i+1])return false;
		}
		return true;
	}

	int getans(vector<int> &A){
		int re = 0;
		auto tmp = A;
		while(!sorted(tmp))re++,bubble(tmp);
		return re;
	}

}

struct SEG{
#define ls now*2+1
#define rs now*2+2
#define mid ((l+r)>>1)
	pll seg[mxn*8];
	SEG(){}
	void modify(int now,int l,int r,int s,int e,int v){
		if(l>=s&&e>=r){
			seg[now].sc += v;
			return;
		}
		if(mid>=s)modify(ls,l,mid,s,e,v);
		if(mid<e)modify(rs,mid+1,r,s,e,v);
		seg[now].fs = max(seg[ls].fs+seg[ls].sc,seg[rs].fs+seg[rs].sc);
	}
	int getval(int now,int l,int r,int s,int e){
		if(l>=s&&e>=r)return seg[now].fs+seg[now].sc;
		if(mid>=e)return seg[now].sc+getval(ls,l,mid,s,e);
		else if(mid<s)return seg[now].sc+getval(rs,mid+1,r,s,e);
		else return max(getval(ls,l,mid,s,e),getval(rs,mid+1,r,s,e))+seg[now].sc;
	}
#undef ls
#undef rs
#undef mid
};

ll arr[mxn];
pll req[mxn];
int N,Q;
vector<ll> all;
SEG seg;
vector<int> ans;

void del(int p){
	seg.modify(0,0,all.size(),arr[p],arr[p],-p-inf);
	seg.modify(0,0,all.size(),arr[p]+1,all.size(),1);
	return;
}
void add(int p){
	seg.modify(0,0,all.size(),arr[p],arr[p],inf);
	seg.modify(0,0,all.size(),arr[p],arr[p],p);
	seg.modify(0,0,all.size(),arr[p]+1,all.size(),-1);
	return;
}

#define _all(T) T.begin(),T.end()
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
	all.push_back(inf*inf);
	all.push_back(0);
	N = A.size(),Q = X.size();
	for(int i = 0;i<N;i++)arr[i] = 1ll*A[i]*mxn+i,all.push_back(arr[i]);
	for(int i = 0;i<Q;i++){
		req[i].fs = X[i];
		req[i].sc = 1ll*V[i]*mxn+req[i].fs;
		all.push_back(req[i].sc);
	}
	sort(all.begin(),all.end());all.resize(unique(all.begin(),all.end())-all.begin());
	for(int i = 0;i<N;i++)arr[i] = lower_bound(_all(all),arr[i])-all.begin();
	for(int i = 0;i<Q;i++)req[i].sc = lower_bound(_all(all),req[i].sc)-all.begin();
	seg.modify(0,0,all.size(),0,all.size(),-inf);
	for(int i = 0;i<N;i++){
		seg.modify(0,0,all.size(),arr[i],arr[i],inf);
		seg.modify(0,0,all.size(),arr[i],arr[i],i);
		seg.modify(0,0,all.size(),arr[i]+1,all.size(),-1);
	}
	for(int i = 0;i<Q;i++){
		del(req[i].fs);
		arr[req[i].fs] = req[i].sc;
		add(req[i].fs);
		ans.push_back(seg.getval(0,0,all.size(),0,all.size()));
	}
	return ans;
}

Compilation message

bubblesort2.cpp: In function 'void BRUTE::bubble(std::vector<int>&)':
bubblesort2.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for(int i = 0;i+1<v.size();i++){
      |                 ~~~^~~~~~~~~
bubblesort2.cpp: In function 'bool BRUTE::sorted(std::vector<int>&)':
bubblesort2.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for(int i = 0;i+1<v.size();i++){
      |                 ~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 66188 KB Output is correct
2 Correct 11 ms 66392 KB Output is correct
3 Correct 15 ms 66396 KB Output is correct
4 Correct 14 ms 66232 KB Output is correct
5 Correct 12 ms 66292 KB Output is correct
6 Correct 12 ms 66396 KB Output is correct
7 Correct 12 ms 66256 KB Output is correct
8 Correct 13 ms 66396 KB Output is correct
9 Correct 12 ms 66396 KB Output is correct
10 Correct 12 ms 66308 KB Output is correct
11 Correct 11 ms 66264 KB Output is correct
12 Correct 12 ms 66396 KB Output is correct
13 Correct 12 ms 66396 KB Output is correct
14 Correct 12 ms 66392 KB Output is correct
15 Correct 12 ms 66392 KB Output is correct
16 Correct 13 ms 66396 KB Output is correct
17 Correct 12 ms 66396 KB Output is correct
18 Correct 11 ms 66260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 66188 KB Output is correct
2 Correct 11 ms 66392 KB Output is correct
3 Correct 15 ms 66396 KB Output is correct
4 Correct 14 ms 66232 KB Output is correct
5 Correct 12 ms 66292 KB Output is correct
6 Correct 12 ms 66396 KB Output is correct
7 Correct 12 ms 66256 KB Output is correct
8 Correct 13 ms 66396 KB Output is correct
9 Correct 12 ms 66396 KB Output is correct
10 Correct 12 ms 66308 KB Output is correct
11 Correct 11 ms 66264 KB Output is correct
12 Correct 12 ms 66396 KB Output is correct
13 Correct 12 ms 66396 KB Output is correct
14 Correct 12 ms 66392 KB Output is correct
15 Correct 12 ms 66392 KB Output is correct
16 Correct 13 ms 66396 KB Output is correct
17 Correct 12 ms 66396 KB Output is correct
18 Correct 11 ms 66260 KB Output is correct
19 Correct 19 ms 66652 KB Output is correct
20 Correct 21 ms 66900 KB Output is correct
21 Correct 21 ms 66908 KB Output is correct
22 Correct 23 ms 67024 KB Output is correct
23 Correct 20 ms 66652 KB Output is correct
24 Correct 21 ms 66908 KB Output is correct
25 Correct 20 ms 66744 KB Output is correct
26 Correct 21 ms 66660 KB Output is correct
27 Correct 20 ms 66652 KB Output is correct
28 Correct 20 ms 66648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 66912 KB Output is correct
2 Correct 57 ms 67884 KB Output is correct
3 Correct 99 ms 69152 KB Output is correct
4 Correct 96 ms 69036 KB Output is correct
5 Correct 105 ms 69172 KB Output is correct
6 Correct 106 ms 69172 KB Output is correct
7 Correct 93 ms 69172 KB Output is correct
8 Correct 95 ms 69076 KB Output is correct
9 Correct 94 ms 69168 KB Output is correct
10 Correct 80 ms 69444 KB Output is correct
11 Correct 79 ms 69248 KB Output is correct
12 Correct 94 ms 69244 KB Output is correct
13 Correct 77 ms 69232 KB Output is correct
14 Correct 77 ms 69316 KB Output is correct
15 Correct 87 ms 69236 KB Output is correct
16 Correct 81 ms 69220 KB Output is correct
17 Correct 74 ms 69220 KB Output is correct
18 Correct 75 ms 69072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 66188 KB Output is correct
2 Correct 11 ms 66392 KB Output is correct
3 Correct 15 ms 66396 KB Output is correct
4 Correct 14 ms 66232 KB Output is correct
5 Correct 12 ms 66292 KB Output is correct
6 Correct 12 ms 66396 KB Output is correct
7 Correct 12 ms 66256 KB Output is correct
8 Correct 13 ms 66396 KB Output is correct
9 Correct 12 ms 66396 KB Output is correct
10 Correct 12 ms 66308 KB Output is correct
11 Correct 11 ms 66264 KB Output is correct
12 Correct 12 ms 66396 KB Output is correct
13 Correct 12 ms 66396 KB Output is correct
14 Correct 12 ms 66392 KB Output is correct
15 Correct 12 ms 66392 KB Output is correct
16 Correct 13 ms 66396 KB Output is correct
17 Correct 12 ms 66396 KB Output is correct
18 Correct 11 ms 66260 KB Output is correct
19 Correct 19 ms 66652 KB Output is correct
20 Correct 21 ms 66900 KB Output is correct
21 Correct 21 ms 66908 KB Output is correct
22 Correct 23 ms 67024 KB Output is correct
23 Correct 20 ms 66652 KB Output is correct
24 Correct 21 ms 66908 KB Output is correct
25 Correct 20 ms 66744 KB Output is correct
26 Correct 21 ms 66660 KB Output is correct
27 Correct 20 ms 66652 KB Output is correct
28 Correct 20 ms 66648 KB Output is correct
29 Correct 26 ms 66912 KB Output is correct
30 Correct 57 ms 67884 KB Output is correct
31 Correct 99 ms 69152 KB Output is correct
32 Correct 96 ms 69036 KB Output is correct
33 Correct 105 ms 69172 KB Output is correct
34 Correct 106 ms 69172 KB Output is correct
35 Correct 93 ms 69172 KB Output is correct
36 Correct 95 ms 69076 KB Output is correct
37 Correct 94 ms 69168 KB Output is correct
38 Correct 80 ms 69444 KB Output is correct
39 Correct 79 ms 69248 KB Output is correct
40 Correct 94 ms 69244 KB Output is correct
41 Correct 77 ms 69232 KB Output is correct
42 Correct 77 ms 69316 KB Output is correct
43 Correct 87 ms 69236 KB Output is correct
44 Correct 81 ms 69220 KB Output is correct
45 Correct 74 ms 69220 KB Output is correct
46 Correct 75 ms 69072 KB Output is correct
47 Correct 342 ms 79840 KB Output is correct
48 Correct 1259 ms 108960 KB Output is correct
49 Correct 1377 ms 111240 KB Output is correct
50 Correct 1431 ms 111240 KB Output is correct
51 Correct 1407 ms 111292 KB Output is correct
52 Correct 1372 ms 111284 KB Output is correct
53 Correct 1358 ms 111240 KB Output is correct
54 Correct 1284 ms 111948 KB Output is correct
55 Correct 1316 ms 111324 KB Output is correct
56 Correct 1246 ms 111328 KB Output is correct
57 Correct 1305 ms 111416 KB Output is correct
58 Correct 1270 ms 111676 KB Output is correct
59 Correct 1177 ms 110060 KB Output is correct
60 Correct 1199 ms 109856 KB Output is correct
61 Correct 1230 ms 109852 KB Output is correct
62 Correct 1159 ms 109960 KB Output is correct
63 Correct 1133 ms 109920 KB Output is correct
64 Correct 1103 ms 109884 KB Output is correct
65 Correct 1116 ms 110096 KB Output is correct
66 Correct 1134 ms 109776 KB Output is correct
67 Correct 1126 ms 109924 KB Output is correct