답안 #467701

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
467701 2021-08-24T06:01:37 Z ETK Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
3794 ms 51352 KB
#include "bubblesort2.h"

#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(x) x.begin(),x.end()
#define PB push_back

using vi=vector<int>;
using pi=pair<int,int>;
const int inf=INT_MAX/2;

struct SegTree{
	vi mx,lz;
	int s;
	SegTree(int n){
		s=1;
		while(s<n)s*=2;
		mx.resize(s*2,0);
		lz.resize(s*2,0);
	}
	void Propagate(int i){
		mx[i]+=lz[i];
		lz[i*2]+=lz[i];
		lz[i*2+1]+=lz[i];
		lz[i]=0;
	}
	int Get(int i){
		return mx[i]+lz[i];
	}
	void Add(int b,int e,int v,int l,int r,int i){
		if(e<=l||r<=b)return;
		if(b<=l&&r<=e){
			lz[i]+=v;
			return;
		}
		Propagate(i);
		Add(b,e,v,l,(l+r)/2,i*2);
		Add(b,e,v,(l+r)/2,r,i*2+1);
		mx[i]=max(Get(i*2),Get(i*2+1));
	}
	void Add(int b,int e,int v){
		if(b<e)
			Add(b,e,v,0,s,1);
	}
	int Get(){
		return Get(1);
	}
};

vector<int> countScans(vector<int> a,vector<int> x,vector<int> v){
	int n=a.size(),q=x.size();
	
	vector<pi> crd;
	REP(i,n)crd.PB(pi(a[i],i));
	REP(i,q)crd.PB(pi(v[i],x[i]));
	sort(ALL(crd));
	crd.erase(unique(ALL(crd)),crd.end());
	
	int s=crd.size();
	SegTree seg(s);
	seg.Add(0,s,-inf);
	
	const auto Ins=[&](int p,int r){
		int i=lower_bound(ALL(crd),pi(p,r))-crd.begin();
		seg.Add(i,i+1,inf+r);
		seg.Add(i+1,s,-1);
	};
	const auto Ers=[&](int p,int r){
		int i=lower_bound(ALL(crd),pi(p,r))-crd.begin();
		seg.Add(i,i+1,-(inf+r));
		seg.Add(i+1,s,1);
	};
	
	REP(i,n)
		Ins(a[i],i);
	
	vi res(q);
	REP(i,q){
		Ers(a[x[i]],x[i]);
		Ins(v[i],x[i]);
		a[x[i]]=v[i];
		res[i]=seg.Get();
	}
	
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 6 ms 516 KB Output is correct
4 Correct 7 ms 460 KB Output is correct
5 Correct 6 ms 508 KB Output is correct
6 Correct 6 ms 460 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 436 KB Output is correct
9 Correct 6 ms 460 KB Output is correct
10 Correct 7 ms 460 KB Output is correct
11 Correct 7 ms 460 KB Output is correct
12 Correct 8 ms 460 KB Output is correct
13 Correct 7 ms 460 KB Output is correct
14 Correct 6 ms 460 KB Output is correct
15 Correct 6 ms 460 KB Output is correct
16 Correct 7 ms 460 KB Output is correct
17 Correct 6 ms 460 KB Output is correct
18 Correct 6 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 6 ms 516 KB Output is correct
4 Correct 7 ms 460 KB Output is correct
5 Correct 6 ms 508 KB Output is correct
6 Correct 6 ms 460 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 436 KB Output is correct
9 Correct 6 ms 460 KB Output is correct
10 Correct 7 ms 460 KB Output is correct
11 Correct 7 ms 460 KB Output is correct
12 Correct 8 ms 460 KB Output is correct
13 Correct 7 ms 460 KB Output is correct
14 Correct 6 ms 460 KB Output is correct
15 Correct 6 ms 460 KB Output is correct
16 Correct 7 ms 460 KB Output is correct
17 Correct 6 ms 460 KB Output is correct
18 Correct 6 ms 460 KB Output is correct
19 Correct 30 ms 1004 KB Output is correct
20 Correct 27 ms 1072 KB Output is correct
21 Correct 28 ms 1084 KB Output is correct
22 Correct 28 ms 1068 KB Output is correct
23 Correct 29 ms 972 KB Output is correct
24 Correct 30 ms 1052 KB Output is correct
25 Correct 27 ms 1068 KB Output is correct
26 Correct 26 ms 1072 KB Output is correct
27 Correct 26 ms 1060 KB Output is correct
28 Correct 25 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 1352 KB Output is correct
2 Correct 134 ms 2644 KB Output is correct
3 Correct 252 ms 4504 KB Output is correct
4 Correct 240 ms 4408 KB Output is correct
5 Correct 237 ms 4616 KB Output is correct
6 Correct 227 ms 4504 KB Output is correct
7 Correct 235 ms 4504 KB Output is correct
8 Correct 267 ms 4408 KB Output is correct
9 Correct 243 ms 4500 KB Output is correct
10 Correct 178 ms 3384 KB Output is correct
11 Correct 198 ms 3400 KB Output is correct
12 Correct 199 ms 3364 KB Output is correct
13 Correct 182 ms 3404 KB Output is correct
14 Correct 190 ms 3524 KB Output is correct
15 Correct 195 ms 3408 KB Output is correct
16 Correct 166 ms 3384 KB Output is correct
17 Correct 187 ms 3512 KB Output is correct
18 Correct 182 ms 3388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 6 ms 516 KB Output is correct
4 Correct 7 ms 460 KB Output is correct
5 Correct 6 ms 508 KB Output is correct
6 Correct 6 ms 460 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 436 KB Output is correct
9 Correct 6 ms 460 KB Output is correct
10 Correct 7 ms 460 KB Output is correct
11 Correct 7 ms 460 KB Output is correct
12 Correct 8 ms 460 KB Output is correct
13 Correct 7 ms 460 KB Output is correct
14 Correct 6 ms 460 KB Output is correct
15 Correct 6 ms 460 KB Output is correct
16 Correct 7 ms 460 KB Output is correct
17 Correct 6 ms 460 KB Output is correct
18 Correct 6 ms 460 KB Output is correct
19 Correct 30 ms 1004 KB Output is correct
20 Correct 27 ms 1072 KB Output is correct
21 Correct 28 ms 1084 KB Output is correct
22 Correct 28 ms 1068 KB Output is correct
23 Correct 29 ms 972 KB Output is correct
24 Correct 30 ms 1052 KB Output is correct
25 Correct 27 ms 1068 KB Output is correct
26 Correct 26 ms 1072 KB Output is correct
27 Correct 26 ms 1060 KB Output is correct
28 Correct 25 ms 972 KB Output is correct
29 Correct 41 ms 1352 KB Output is correct
30 Correct 134 ms 2644 KB Output is correct
31 Correct 252 ms 4504 KB Output is correct
32 Correct 240 ms 4408 KB Output is correct
33 Correct 237 ms 4616 KB Output is correct
34 Correct 227 ms 4504 KB Output is correct
35 Correct 235 ms 4504 KB Output is correct
36 Correct 267 ms 4408 KB Output is correct
37 Correct 243 ms 4500 KB Output is correct
38 Correct 178 ms 3384 KB Output is correct
39 Correct 198 ms 3400 KB Output is correct
40 Correct 199 ms 3364 KB Output is correct
41 Correct 182 ms 3404 KB Output is correct
42 Correct 190 ms 3524 KB Output is correct
43 Correct 195 ms 3408 KB Output is correct
44 Correct 166 ms 3384 KB Output is correct
45 Correct 187 ms 3512 KB Output is correct
46 Correct 182 ms 3388 KB Output is correct
47 Correct 944 ms 18564 KB Output is correct
48 Correct 3685 ms 48536 KB Output is correct
49 Correct 3755 ms 51204 KB Output is correct
50 Correct 3794 ms 51120 KB Output is correct
51 Correct 3708 ms 51120 KB Output is correct
52 Correct 3713 ms 51120 KB Output is correct
53 Correct 3623 ms 51112 KB Output is correct
54 Correct 3496 ms 51264 KB Output is correct
55 Correct 3374 ms 51308 KB Output is correct
56 Correct 3391 ms 51352 KB Output is correct
57 Correct 3509 ms 51292 KB Output is correct
58 Correct 3381 ms 51264 KB Output is correct
59 Correct 3217 ms 49936 KB Output is correct
60 Correct 3360 ms 49896 KB Output is correct
61 Correct 3217 ms 49864 KB Output is correct
62 Correct 3209 ms 49788 KB Output is correct
63 Correct 3171 ms 49688 KB Output is correct
64 Correct 3063 ms 49952 KB Output is correct
65 Correct 2951 ms 49656 KB Output is correct
66 Correct 2903 ms 49652 KB Output is correct
67 Correct 2922 ms 49656 KB Output is correct