답안 #537200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537200 2022-03-14T17:48:04 Z michao Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
1880 ms 54820 KB
#include <bits/stdc++.h>
//#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=1<<20;
const int STALA=1e6;
const int inf=1e9+9;
int LAZY[MAX*4],MAXI[MAX*4];
 
void push(int u){
  LAZY[2*u]+=LAZY[u];
  LAZY[2*u+1]+=LAZY[u];
  MAXI[u]+=LAZY[u];
  LAZY[u]=0;
}
 
void update(int a,int b,int u,int lo,int hi,int c){
  if (b<lo || a>hi)return;
  if (a<=lo && b>=hi){
    LAZY[u]+=c;
    return;
  }
  int mid=(lo+hi)>>1;
  update(a,b,2*u,lo,mid,c);
  update(a,b,2*u+1,mid+1,hi,c);
  MAXI[u]=max(MAXI[2*u]+LAZY[2*u],MAXI[2*u+1]+LAZY[2*u+1]);
}
 
int getmax(int a,int b,int u,int lo,int hi){
  if (b<lo || a>hi)return -inf;
  push(u);
  if (a<=lo && b>=hi)
    return MAXI[u];
  int mid=(lo+hi)>>1;
  int L=getmax(a,b,2*u,lo,mid);
  int R=getmax(a,b,2*u+1,mid+1,hi);
  return max(L,R);
}
void upd(int u,int v,int c){
	update(u,v,1,1,MAX,c);
}

int ran(int u,int v){
	return getmax(u,v,1,1,MAX);
}
int a[MAX],x[MAX],v[MAX];

int smaller(int xd){
	return xd-1;
}
vi countScans(vi _a,vi _x,vi _v){
	int n=sz(_a);
	int q=sz(_v);
	assert(sz(_v)==sz(_x));
	vector<pii> compress;
	compress.clear();
	for (int i=1;i<=n;i++)a[i]=_a[i-1],compress.pb(mp(a[i],i));
	for (int i=1;i<=q;i++){
		x[i]=_x[i-1];
		v[i]=_v[i-1];
		x[i]++;
		compress.pb(mp(v[i],x[i]));
	}
	sort(compress.begin(),compress.end());
	compress.erase(unique(compress.begin(),compress.end()),compress.end());
	for (int i=1;i<=n;i++){
		a[i]=lower_bound(compress.begin(),compress.end(),mp(a[i],i))-compress.begin()+1;
	}
	
	for (int i=1;i<=q;i++){
		v[i]=lower_bound(compress.begin(),compress.end(),mp(v[i],x[i]))-compress.begin()+1;
	}
	int ile=sz(compress);
	for (int i=1;i<=n;i++){
		upd(a[i],a[i],smaller(i)); // assert uniqueness
		upd(a[i]+1,ile,-1);
	}
	vi ans;
	ans.clear();
	for (int i=1;i<=q;i++){
		upd(a[x[i]],a[x[i]],-smaller(x[i]));
		upd(a[x[i]]+1,ile,1);
		a[x[i]]=v[i];
		upd(a[x[i]],a[x[i]],smaller(x[i]));
		upd(a[x[i]]+1,ile,-1);
		ans.pb(ran(1,STALA));
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 4 ms 668 KB Output is correct
3 Correct 6 ms 596 KB Output is correct
4 Correct 6 ms 684 KB Output is correct
5 Correct 6 ms 580 KB Output is correct
6 Correct 7 ms 576 KB Output is correct
7 Correct 5 ms 596 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 5 ms 596 KB Output is correct
10 Correct 5 ms 596 KB Output is correct
11 Correct 5 ms 596 KB Output is correct
12 Correct 5 ms 576 KB Output is correct
13 Correct 5 ms 664 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 6 ms 596 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 6 ms 596 KB Output is correct
18 Correct 5 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 4 ms 668 KB Output is correct
3 Correct 6 ms 596 KB Output is correct
4 Correct 6 ms 684 KB Output is correct
5 Correct 6 ms 580 KB Output is correct
6 Correct 7 ms 576 KB Output is correct
7 Correct 5 ms 596 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 5 ms 596 KB Output is correct
10 Correct 5 ms 596 KB Output is correct
11 Correct 5 ms 596 KB Output is correct
12 Correct 5 ms 576 KB Output is correct
13 Correct 5 ms 664 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 6 ms 596 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 6 ms 596 KB Output is correct
18 Correct 5 ms 596 KB Output is correct
19 Correct 18 ms 1264 KB Output is correct
20 Correct 20 ms 1364 KB Output is correct
21 Correct 19 ms 1364 KB Output is correct
22 Correct 19 ms 1364 KB Output is correct
23 Correct 25 ms 1324 KB Output is correct
24 Correct 19 ms 1216 KB Output is correct
25 Correct 29 ms 1296 KB Output is correct
26 Correct 20 ms 1236 KB Output is correct
27 Correct 19 ms 1216 KB Output is correct
28 Correct 19 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1508 KB Output is correct
2 Correct 77 ms 3188 KB Output is correct
3 Correct 139 ms 5164 KB Output is correct
4 Correct 157 ms 5088 KB Output is correct
5 Correct 138 ms 5164 KB Output is correct
6 Correct 132 ms 5184 KB Output is correct
7 Correct 172 ms 5140 KB Output is correct
8 Correct 130 ms 5184 KB Output is correct
9 Correct 135 ms 5252 KB Output is correct
10 Correct 116 ms 4724 KB Output is correct
11 Correct 135 ms 4728 KB Output is correct
12 Correct 138 ms 4708 KB Output is correct
13 Correct 116 ms 4764 KB Output is correct
14 Correct 117 ms 4716 KB Output is correct
15 Correct 164 ms 4660 KB Output is correct
16 Correct 109 ms 4712 KB Output is correct
17 Correct 112 ms 4672 KB Output is correct
18 Correct 115 ms 4684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 4 ms 668 KB Output is correct
3 Correct 6 ms 596 KB Output is correct
4 Correct 6 ms 684 KB Output is correct
5 Correct 6 ms 580 KB Output is correct
6 Correct 7 ms 576 KB Output is correct
7 Correct 5 ms 596 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 5 ms 596 KB Output is correct
10 Correct 5 ms 596 KB Output is correct
11 Correct 5 ms 596 KB Output is correct
12 Correct 5 ms 576 KB Output is correct
13 Correct 5 ms 664 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 6 ms 596 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 6 ms 596 KB Output is correct
18 Correct 5 ms 596 KB Output is correct
19 Correct 18 ms 1264 KB Output is correct
20 Correct 20 ms 1364 KB Output is correct
21 Correct 19 ms 1364 KB Output is correct
22 Correct 19 ms 1364 KB Output is correct
23 Correct 25 ms 1324 KB Output is correct
24 Correct 19 ms 1216 KB Output is correct
25 Correct 29 ms 1296 KB Output is correct
26 Correct 20 ms 1236 KB Output is correct
27 Correct 19 ms 1216 KB Output is correct
28 Correct 19 ms 1236 KB Output is correct
29 Correct 26 ms 1508 KB Output is correct
30 Correct 77 ms 3188 KB Output is correct
31 Correct 139 ms 5164 KB Output is correct
32 Correct 157 ms 5088 KB Output is correct
33 Correct 138 ms 5164 KB Output is correct
34 Correct 132 ms 5184 KB Output is correct
35 Correct 172 ms 5140 KB Output is correct
36 Correct 130 ms 5184 KB Output is correct
37 Correct 135 ms 5252 KB Output is correct
38 Correct 116 ms 4724 KB Output is correct
39 Correct 135 ms 4728 KB Output is correct
40 Correct 138 ms 4708 KB Output is correct
41 Correct 116 ms 4764 KB Output is correct
42 Correct 117 ms 4716 KB Output is correct
43 Correct 164 ms 4660 KB Output is correct
44 Correct 109 ms 4712 KB Output is correct
45 Correct 112 ms 4672 KB Output is correct
46 Correct 115 ms 4684 KB Output is correct
47 Correct 494 ms 16656 KB Output is correct
48 Correct 1825 ms 50424 KB Output is correct
49 Correct 1810 ms 54572 KB Output is correct
50 Correct 1797 ms 54360 KB Output is correct
51 Correct 1811 ms 54492 KB Output is correct
52 Correct 1880 ms 54512 KB Output is correct
53 Correct 1851 ms 54696 KB Output is correct
54 Correct 1727 ms 54748 KB Output is correct
55 Correct 1751 ms 54820 KB Output is correct
56 Correct 1705 ms 54556 KB Output is correct
57 Correct 1754 ms 54592 KB Output is correct
58 Correct 1711 ms 54780 KB Output is correct
59 Correct 1792 ms 51936 KB Output is correct
60 Correct 1732 ms 51780 KB Output is correct
61 Correct 1705 ms 51764 KB Output is correct
62 Correct 1613 ms 51116 KB Output is correct
63 Correct 1638 ms 51040 KB Output is correct
64 Correct 1633 ms 50960 KB Output is correct
65 Correct 1527 ms 50176 KB Output is correct
66 Correct 1586 ms 50104 KB Output is correct
67 Correct 1500 ms 50060 KB Output is correct