답안 #1023476

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023476 2024-07-14T20:01:44 Z NintsiChkhaidze Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
2872 ms 114472 KB
#include <bits/stdc++.h>
#include "bubblesort2.h"
#define left h*2,l,(l + r)/2
#define right h*2+1,(l + r)/2 + 1,r
#define pii pair <int,int>
#define s second
#define f first
#define pb push_back
using namespace std;
 
const int N = 1e6 + 5;
int lz[4*N],AA[N],VV[N];
pii t[4*N];
map <int,int> l1;
 
void build(int h,int l,int r){
	if (l == r){
		t[h] = {0,l};
		return;
	}
	build(left);
	build(right);
	t[h] = max(t[h*2],t[h*2 + 1]);
}
 
void push(int h){
	if (lz[h]==0) return ;
	lz[h*2] += lz[h];
	lz[h*2 + 1] += lz[h];
	t[h*2].f += lz[h];
	t[h*2 + 1].f += lz[h];
	lz[h] = 0;
}
 
void upd(int h,int l,int r,int L,int R,int val){
	if (r < L || R < l) return;
	if (L <= l && r <= R){
		t[h].f += val;
		lz[h] += val;
		return;
	}
	push(h);
	upd(left,L,R,val);
	upd(right,L,R,val);
	t[h] = max(t[h*2],t[h*2 + 1]);
}
 
vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){
	vector <pair <pii,int> > vec;
	for (int i=0;i<A.size();i++){
		vec.pb({{A[i],i},1});
	}
	for (int i=0;i<V.size();i++){
		vec.pb({{V[i],i},2});
	}
	sort(vec.begin(),vec.end());
	
	int m = vec.size();
	for (int i = 0; i < vec.size(); i++){
		int tp = vec[i].s;
		if (tp == 1) AA[vec[i].f.s] = i + 1;
		else VV[vec[i].f.s] = i + 1;
		if (!i || vec[i].f.f != vec[i - 1].f.f)
			l1[vec[i].f.f] = i + 1;
	}
	
	build(1,1,m);
	for (int i = 0; i < A.size(); i++){
		upd(1,1,m,l1[A[i]],m,-1);
		upd(1,1,m,AA[i],AA[i],i+1);
	}
	
	int Q=X.size();
	vector<int> answer(Q);
	
	for (int j = 0; j < X.size(); j++){
      
		int i = X[j];
		upd(1,1,m,l1[A[i]],m,+1);
		upd(1,1,m,AA[i],AA[i],-i-1);
		
		A[i] = V[j];
		AA[i] = VV[j];
		
		upd(1,1,m,l1[A[i]],m,-1);
		upd(1,1,m,AA[i],AA[i],i+1);
		answer[j] = t[1].f;
	}
	
	return answer;
}

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:50:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for (int i=0;i<A.size();i++){
      |               ~^~~~~~~~~
bubblesort2.cpp:53:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |  for (int i=0;i<V.size();i++){
      |               ~^~~~~~~~~
bubblesort2.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for (int i = 0; i < vec.size(); i++){
      |                  ~~^~~~~~~~~~~~
bubblesort2.cpp:68:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |  for (int i = 0; i < A.size(); i++){
      |                  ~~^~~~~~~~~~
bubblesort2.cpp:76:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |  for (int j = 0; j < X.size(); j++){
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 4 ms 2912 KB Output is correct
4 Correct 4 ms 2952 KB Output is correct
5 Correct 5 ms 2904 KB Output is correct
6 Correct 4 ms 2908 KB Output is correct
7 Correct 4 ms 2908 KB Output is correct
8 Correct 4 ms 2960 KB Output is correct
9 Correct 4 ms 2908 KB Output is correct
10 Correct 4 ms 2908 KB Output is correct
11 Correct 4 ms 2908 KB Output is correct
12 Correct 5 ms 2756 KB Output is correct
13 Correct 4 ms 2904 KB Output is correct
14 Correct 4 ms 2904 KB Output is correct
15 Correct 4 ms 2908 KB Output is correct
16 Correct 3 ms 2896 KB Output is correct
17 Correct 4 ms 2904 KB Output is correct
18 Correct 4 ms 2904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 4 ms 2912 KB Output is correct
4 Correct 4 ms 2952 KB Output is correct
5 Correct 5 ms 2904 KB Output is correct
6 Correct 4 ms 2908 KB Output is correct
7 Correct 4 ms 2908 KB Output is correct
8 Correct 4 ms 2960 KB Output is correct
9 Correct 4 ms 2908 KB Output is correct
10 Correct 4 ms 2908 KB Output is correct
11 Correct 4 ms 2908 KB Output is correct
12 Correct 5 ms 2756 KB Output is correct
13 Correct 4 ms 2904 KB Output is correct
14 Correct 4 ms 2904 KB Output is correct
15 Correct 4 ms 2908 KB Output is correct
16 Correct 3 ms 2896 KB Output is correct
17 Correct 4 ms 2904 KB Output is correct
18 Correct 4 ms 2904 KB Output is correct
19 Correct 16 ms 4124 KB Output is correct
20 Correct 22 ms 4128 KB Output is correct
21 Correct 21 ms 4124 KB Output is correct
22 Correct 18 ms 4228 KB Output is correct
23 Correct 17 ms 4124 KB Output is correct
24 Correct 17 ms 4124 KB Output is correct
25 Correct 16 ms 4060 KB Output is correct
26 Correct 16 ms 4104 KB Output is correct
27 Correct 15 ms 3864 KB Output is correct
28 Correct 15 ms 3868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 3928 KB Output is correct
2 Correct 47 ms 5944 KB Output is correct
3 Correct 87 ms 8808 KB Output is correct
4 Correct 82 ms 8656 KB Output is correct
5 Correct 84 ms 8904 KB Output is correct
6 Correct 82 ms 8900 KB Output is correct
7 Correct 103 ms 8812 KB Output is correct
8 Correct 83 ms 8900 KB Output is correct
9 Correct 82 ms 8900 KB Output is correct
10 Correct 76 ms 8900 KB Output is correct
11 Correct 77 ms 8916 KB Output is correct
12 Correct 76 ms 8976 KB Output is correct
13 Correct 76 ms 8916 KB Output is correct
14 Correct 77 ms 8912 KB Output is correct
15 Correct 75 ms 8904 KB Output is correct
16 Correct 76 ms 8900 KB Output is correct
17 Correct 74 ms 8936 KB Output is correct
18 Correct 74 ms 8900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 4 ms 2912 KB Output is correct
4 Correct 4 ms 2952 KB Output is correct
5 Correct 5 ms 2904 KB Output is correct
6 Correct 4 ms 2908 KB Output is correct
7 Correct 4 ms 2908 KB Output is correct
8 Correct 4 ms 2960 KB Output is correct
9 Correct 4 ms 2908 KB Output is correct
10 Correct 4 ms 2908 KB Output is correct
11 Correct 4 ms 2908 KB Output is correct
12 Correct 5 ms 2756 KB Output is correct
13 Correct 4 ms 2904 KB Output is correct
14 Correct 4 ms 2904 KB Output is correct
15 Correct 4 ms 2908 KB Output is correct
16 Correct 3 ms 2896 KB Output is correct
17 Correct 4 ms 2904 KB Output is correct
18 Correct 4 ms 2904 KB Output is correct
19 Correct 16 ms 4124 KB Output is correct
20 Correct 22 ms 4128 KB Output is correct
21 Correct 21 ms 4124 KB Output is correct
22 Correct 18 ms 4228 KB Output is correct
23 Correct 17 ms 4124 KB Output is correct
24 Correct 17 ms 4124 KB Output is correct
25 Correct 16 ms 4060 KB Output is correct
26 Correct 16 ms 4104 KB Output is correct
27 Correct 15 ms 3864 KB Output is correct
28 Correct 15 ms 3868 KB Output is correct
29 Correct 15 ms 3928 KB Output is correct
30 Correct 47 ms 5944 KB Output is correct
31 Correct 87 ms 8808 KB Output is correct
32 Correct 82 ms 8656 KB Output is correct
33 Correct 84 ms 8904 KB Output is correct
34 Correct 82 ms 8900 KB Output is correct
35 Correct 103 ms 8812 KB Output is correct
36 Correct 83 ms 8900 KB Output is correct
37 Correct 82 ms 8900 KB Output is correct
38 Correct 76 ms 8900 KB Output is correct
39 Correct 77 ms 8916 KB Output is correct
40 Correct 76 ms 8976 KB Output is correct
41 Correct 76 ms 8916 KB Output is correct
42 Correct 77 ms 8912 KB Output is correct
43 Correct 75 ms 8904 KB Output is correct
44 Correct 76 ms 8900 KB Output is correct
45 Correct 74 ms 8936 KB Output is correct
46 Correct 74 ms 8900 KB Output is correct
47 Correct 546 ms 40380 KB Output is correct
48 Correct 2480 ms 106672 KB Output is correct
49 Correct 2638 ms 114024 KB Output is correct
50 Correct 2822 ms 114104 KB Output is correct
51 Correct 2786 ms 114212 KB Output is correct
52 Correct 2748 ms 114212 KB Output is correct
53 Correct 2872 ms 114052 KB Output is correct
54 Correct 2447 ms 114344 KB Output is correct
55 Correct 2573 ms 114472 KB Output is correct
56 Correct 2345 ms 114224 KB Output is correct
57 Correct 2603 ms 114168 KB Output is correct
58 Correct 2365 ms 114260 KB Output is correct
59 Correct 2126 ms 107140 KB Output is correct
60 Correct 2070 ms 107112 KB Output is correct
61 Correct 2104 ms 107128 KB Output is correct
62 Correct 1930 ms 104052 KB Output is correct
63 Correct 2013 ms 104052 KB Output is correct
64 Correct 1984 ms 104108 KB Output is correct
65 Correct 1766 ms 100848 KB Output is correct
66 Correct 1757 ms 100976 KB Output is correct
67 Correct 1701 ms 101044 KB Output is correct