답안 #1095529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095529 2024-10-02T13:27:03 Z epicci23 Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
2025 ms 66468 KB
#include "bubblesort2.h"
#include "bits/stdc++.h"
using namespace std;


struct SegT{
  int n;
  vector<int> seg,lazy;
  SegT(int _n){
  	n=_n;
    seg.assign(4*n+5,0);
    lazy.assign(4*n+5,0);
  }
  void push(int rt,int l,int r){
  	int u=lazy[rt];
  	lazy[rt]=0;
  	seg[rt]+=u;
  	if(l==r) return;
  	lazy[rt*2]+=u;
  	lazy[rt*2+1]+=u;
  }
  void update(int rt,int l,int r,int gl,int gr,int u){
  	if(l>r || gl>gr || gr>=n) return;
  	push(rt,l,r);
  	if(r<gl || l>gr) return;
  	if(l>=gl && r<=gr){
  	  lazy[rt]+=u;
  	  push(rt,l,r);
  	  return;
  	}
  	int m=(l+r)/2;
  	update(rt*2,l,m,gl,gr,u),update(rt*2+1,m+1,r,gl,gr,u);
  	seg[rt]=max(seg[rt*2],seg[rt*2+1]);
  }

  void update(int l,int r,int u){
  	update(1,0,n-1,l,r,u);
  }
};

vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){
	int q=X.size(),n=A.size();
	vector<int> answer(q);
	vector<array<int,2>> zip;
	for(int i=0;i<n;i++) zip.push_back({A[i],i});	
	for(int i=0;i<q;i++) zip.push_back({V[i],X[i]});
	sort(zip.begin(),zip.end());
    zip.erase(unique(zip.begin(),zip.end()),zip.end());
    for(int i=0;i<n;i++) A[i]=lower_bound(zip.begin(),zip.end(),
    	 array<int,2>{A[i],i})-zip.begin();
    for(int i=0;i<q;i++) V[i]=lower_bound(zip.begin(),zip.end(),
    	 array<int,2>{V[i],X[i]})-zip.begin();

    SegT T(n+q+5);
    
    for(int i=0;i<n;i++){
      T.update(A[i],A[i],i);
      T.update(A[i]+1,n+q,-1);	
    }  

    for(int i=0;i<q;i++){
      T.update(A[X[i]],A[X[i]],-X[i]);
      T.update(A[X[i]]+1,n+q,1);
      A[X[i]]=V[i];
      T.update(A[X[i]],A[X[i]],X[i]);
      T.update(A[X[i]]+1,n+q,-1);
      answer[i]=T.seg[1];
    }
  
  	return answer;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 4 ms 700 KB Output is correct
5 Correct 5 ms 604 KB Output is correct
6 Correct 4 ms 724 KB Output is correct
7 Correct 4 ms 600 KB Output is correct
8 Correct 4 ms 704 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 4 ms 656 KB Output is correct
12 Correct 4 ms 700 KB Output is correct
13 Correct 5 ms 604 KB Output is correct
14 Correct 4 ms 492 KB Output is correct
15 Correct 7 ms 604 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 716 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 4 ms 700 KB Output is correct
5 Correct 5 ms 604 KB Output is correct
6 Correct 4 ms 724 KB Output is correct
7 Correct 4 ms 600 KB Output is correct
8 Correct 4 ms 704 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 4 ms 656 KB Output is correct
12 Correct 4 ms 700 KB Output is correct
13 Correct 5 ms 604 KB Output is correct
14 Correct 4 ms 492 KB Output is correct
15 Correct 7 ms 604 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 716 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
19 Correct 19 ms 1372 KB Output is correct
20 Correct 29 ms 1372 KB Output is correct
21 Correct 18 ms 1652 KB Output is correct
22 Correct 18 ms 1492 KB Output is correct
23 Correct 21 ms 1372 KB Output is correct
24 Correct 21 ms 1372 KB Output is correct
25 Correct 17 ms 1368 KB Output is correct
26 Correct 18 ms 1372 KB Output is correct
27 Correct 18 ms 1580 KB Output is correct
28 Correct 18 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 2012 KB Output is correct
2 Correct 99 ms 4024 KB Output is correct
3 Correct 140 ms 6352 KB Output is correct
4 Correct 138 ms 6348 KB Output is correct
5 Correct 132 ms 6372 KB Output is correct
6 Correct 135 ms 6344 KB Output is correct
7 Correct 136 ms 6340 KB Output is correct
8 Correct 156 ms 6324 KB Output is correct
9 Correct 150 ms 6380 KB Output is correct
10 Correct 128 ms 6440 KB Output is correct
11 Correct 134 ms 6340 KB Output is correct
12 Correct 130 ms 6596 KB Output is correct
13 Correct 129 ms 6488 KB Output is correct
14 Correct 131 ms 6352 KB Output is correct
15 Correct 127 ms 6340 KB Output is correct
16 Correct 135 ms 6340 KB Output is correct
17 Correct 127 ms 6344 KB Output is correct
18 Correct 126 ms 6604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 4 ms 700 KB Output is correct
5 Correct 5 ms 604 KB Output is correct
6 Correct 4 ms 724 KB Output is correct
7 Correct 4 ms 600 KB Output is correct
8 Correct 4 ms 704 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 4 ms 656 KB Output is correct
12 Correct 4 ms 700 KB Output is correct
13 Correct 5 ms 604 KB Output is correct
14 Correct 4 ms 492 KB Output is correct
15 Correct 7 ms 604 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 716 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
19 Correct 19 ms 1372 KB Output is correct
20 Correct 29 ms 1372 KB Output is correct
21 Correct 18 ms 1652 KB Output is correct
22 Correct 18 ms 1492 KB Output is correct
23 Correct 21 ms 1372 KB Output is correct
24 Correct 21 ms 1372 KB Output is correct
25 Correct 17 ms 1368 KB Output is correct
26 Correct 18 ms 1372 KB Output is correct
27 Correct 18 ms 1580 KB Output is correct
28 Correct 18 ms 1372 KB Output is correct
29 Correct 29 ms 2012 KB Output is correct
30 Correct 99 ms 4024 KB Output is correct
31 Correct 140 ms 6352 KB Output is correct
32 Correct 138 ms 6348 KB Output is correct
33 Correct 132 ms 6372 KB Output is correct
34 Correct 135 ms 6344 KB Output is correct
35 Correct 136 ms 6340 KB Output is correct
36 Correct 156 ms 6324 KB Output is correct
37 Correct 150 ms 6380 KB Output is correct
38 Correct 128 ms 6440 KB Output is correct
39 Correct 134 ms 6340 KB Output is correct
40 Correct 130 ms 6596 KB Output is correct
41 Correct 129 ms 6488 KB Output is correct
42 Correct 131 ms 6352 KB Output is correct
43 Correct 127 ms 6340 KB Output is correct
44 Correct 135 ms 6340 KB Output is correct
45 Correct 127 ms 6344 KB Output is correct
46 Correct 126 ms 6604 KB Output is correct
47 Correct 477 ms 19752 KB Output is correct
48 Correct 1796 ms 60932 KB Output is correct
49 Correct 1981 ms 66220 KB Output is correct
50 Correct 2013 ms 66112 KB Output is correct
51 Correct 1923 ms 66220 KB Output is correct
52 Correct 1898 ms 66276 KB Output is correct
53 Correct 1892 ms 66196 KB Output is correct
54 Correct 1781 ms 66428 KB Output is correct
55 Correct 1923 ms 66468 KB Output is correct
56 Correct 2025 ms 66220 KB Output is correct
57 Correct 1982 ms 66220 KB Output is correct
58 Correct 1947 ms 66224 KB Output is correct
59 Correct 1883 ms 65104 KB Output is correct
60 Correct 1820 ms 65096 KB Output is correct
61 Correct 1829 ms 65180 KB Output is correct
62 Correct 1826 ms 64948 KB Output is correct
63 Correct 1895 ms 64940 KB Output is correct
64 Correct 1866 ms 64940 KB Output is correct
65 Correct 1779 ms 64812 KB Output is correct
66 Correct 1787 ms 64752 KB Output is correct
67 Correct 1620 ms 64680 KB Output is correct