답안 #285137

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285137 2020-08-28T11:00:34 Z Pyqe Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
3813 ms 129084 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define fr first
#define sc second

int n,inf=1e9;
pair<int,int> as[1000069];

struct segtree
{
	int l,r,mx,lz;
	segtree *p[2];
	
	void bd(int lh,int rh)
	{
		l=lh;
		r=rh;
		mx=-inf;
		lz=0;
		if(l==r);
		else
		{
			int ii,md=(l+r)/2;
			
			for(ii=0;ii<2;ii++)
			{
				p[ii]=new segtree;
				p[ii]->bd(!ii?l:md+1,!ii?md:r);
			}
		}
	}
	void blc()
	{
		int ii;
		
		for(ii=0;ii<2;ii++)
		{
			p[ii]->mx+=lz;
			p[ii]->lz+=lz;
		}
		lz=0;
	}
	void ud(int lh,int rh,int w)
	{
		if(l>rh||r<lh);
		else if(l>=lh&&r<=rh)
		{
			mx+=w;
			lz+=w;
		}
		else
		{
			int ii;
			
			blc();
			for(ii=0;ii<2;ii++)
			{
				p[ii]->ud(lh,rh,w);
			}
			mx=max(p[0]->mx,p[1]->mx);
		}
	}
	void ins(int x)
	{
		if(l>x||r<x);
		else if(l>=x&&r<=x)
		{
			mx=lz-(n-1-as[l].sc);
		}
		else
		{
			int ii;
			
			blc();
			for(ii=0;ii<2;ii++)
			{
				p[ii]->ins(x);
			}
			mx=max(p[0]->mx,p[1]->mx);
		}
	}
	void ers(int x)
	{
		if(l>x||r<x);
		else if(l>=x&&r<=x)
		{
			mx=-inf;
		}
		else
		{
			int ii;
			
			blc();
			for(ii=0;ii<2;ii++)
			{
				p[ii]->ers(x);
			}
			mx=max(p[0]->mx,p[1]->mx);
		}
	}
}
sg;

vector<int> countScans(vector<int> a,vector<int> qp,vector<int> qw)
{
	int t=qp.size(),rr,i,k,w;
	vector<int> sq;
	
	n=a.size();
	for(i=0;i<n;i++)
	{
		as[i]={a[i],i};
	}
	for(rr=0;rr<t;rr++)
	{
		k=qp[rr];
		w=qw[rr];
		as[n+rr]={w,k};
	}
	sort(as,as+n+t);
	sg.bd(0,n+t-1);
	for(i=0;i<n;i++)
	{
		sg.ins(lower_bound(as,as+n+t,mp(a[i],i))-as);
		sg.ud(0,lower_bound(as,as+n+t,mp(a[i],0))-as-1,1);
	}
	for(rr=0;rr<t;rr++)
	{
		k=qp[rr];
		w=qw[rr];
		sg.ers(lower_bound(as,as+n+t,mp(a[k],k))-as);
		sg.ud(0,lower_bound(as,as+n+t,mp(a[k],0))-as-1,-1);
		a[k]=w;
		sg.ins(lower_bound(as,as+n+t,mp(w,k))-as);
		sg.ud(0,lower_bound(as,as+n+t,mp(w,0))-as-1,1);
		sq.push_back(sg.mx);
	}
	return sq;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 8 ms 896 KB Output is correct
4 Correct 6 ms 896 KB Output is correct
5 Correct 6 ms 896 KB Output is correct
6 Correct 6 ms 896 KB Output is correct
7 Correct 6 ms 896 KB Output is correct
8 Correct 6 ms 896 KB Output is correct
9 Correct 6 ms 896 KB Output is correct
10 Correct 6 ms 896 KB Output is correct
11 Correct 6 ms 768 KB Output is correct
12 Correct 6 ms 896 KB Output is correct
13 Correct 6 ms 880 KB Output is correct
14 Correct 6 ms 896 KB Output is correct
15 Correct 7 ms 800 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 6 ms 896 KB Output is correct
18 Correct 6 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 8 ms 896 KB Output is correct
4 Correct 6 ms 896 KB Output is correct
5 Correct 6 ms 896 KB Output is correct
6 Correct 6 ms 896 KB Output is correct
7 Correct 6 ms 896 KB Output is correct
8 Correct 6 ms 896 KB Output is correct
9 Correct 6 ms 896 KB Output is correct
10 Correct 6 ms 896 KB Output is correct
11 Correct 6 ms 768 KB Output is correct
12 Correct 6 ms 896 KB Output is correct
13 Correct 6 ms 880 KB Output is correct
14 Correct 6 ms 896 KB Output is correct
15 Correct 7 ms 800 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 6 ms 896 KB Output is correct
18 Correct 6 ms 896 KB Output is correct
19 Correct 24 ms 2176 KB Output is correct
20 Correct 32 ms 2424 KB Output is correct
21 Correct 26 ms 2432 KB Output is correct
22 Correct 27 ms 2432 KB Output is correct
23 Correct 25 ms 2424 KB Output is correct
24 Correct 25 ms 2432 KB Output is correct
25 Correct 28 ms 2432 KB Output is correct
26 Correct 24 ms 2432 KB Output is correct
27 Correct 29 ms 2424 KB Output is correct
28 Correct 25 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 3712 KB Output is correct
2 Correct 132 ms 8188 KB Output is correct
3 Correct 241 ms 12792 KB Output is correct
4 Correct 232 ms 12668 KB Output is correct
5 Correct 243 ms 12664 KB Output is correct
6 Correct 219 ms 12664 KB Output is correct
7 Correct 216 ms 12664 KB Output is correct
8 Correct 211 ms 12792 KB Output is correct
9 Correct 208 ms 12664 KB Output is correct
10 Correct 168 ms 12664 KB Output is correct
11 Correct 159 ms 12664 KB Output is correct
12 Correct 163 ms 12664 KB Output is correct
13 Correct 162 ms 12664 KB Output is correct
14 Correct 162 ms 12768 KB Output is correct
15 Correct 172 ms 12760 KB Output is correct
16 Correct 162 ms 12664 KB Output is correct
17 Correct 161 ms 12736 KB Output is correct
18 Correct 154 ms 12664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 8 ms 896 KB Output is correct
4 Correct 6 ms 896 KB Output is correct
5 Correct 6 ms 896 KB Output is correct
6 Correct 6 ms 896 KB Output is correct
7 Correct 6 ms 896 KB Output is correct
8 Correct 6 ms 896 KB Output is correct
9 Correct 6 ms 896 KB Output is correct
10 Correct 6 ms 896 KB Output is correct
11 Correct 6 ms 768 KB Output is correct
12 Correct 6 ms 896 KB Output is correct
13 Correct 6 ms 880 KB Output is correct
14 Correct 6 ms 896 KB Output is correct
15 Correct 7 ms 800 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 6 ms 896 KB Output is correct
18 Correct 6 ms 896 KB Output is correct
19 Correct 24 ms 2176 KB Output is correct
20 Correct 32 ms 2424 KB Output is correct
21 Correct 26 ms 2432 KB Output is correct
22 Correct 27 ms 2432 KB Output is correct
23 Correct 25 ms 2424 KB Output is correct
24 Correct 25 ms 2432 KB Output is correct
25 Correct 28 ms 2432 KB Output is correct
26 Correct 24 ms 2432 KB Output is correct
27 Correct 29 ms 2424 KB Output is correct
28 Correct 25 ms 2424 KB Output is correct
29 Correct 34 ms 3712 KB Output is correct
30 Correct 132 ms 8188 KB Output is correct
31 Correct 241 ms 12792 KB Output is correct
32 Correct 232 ms 12668 KB Output is correct
33 Correct 243 ms 12664 KB Output is correct
34 Correct 219 ms 12664 KB Output is correct
35 Correct 216 ms 12664 KB Output is correct
36 Correct 211 ms 12792 KB Output is correct
37 Correct 208 ms 12664 KB Output is correct
38 Correct 168 ms 12664 KB Output is correct
39 Correct 159 ms 12664 KB Output is correct
40 Correct 163 ms 12664 KB Output is correct
41 Correct 162 ms 12664 KB Output is correct
42 Correct 162 ms 12768 KB Output is correct
43 Correct 172 ms 12760 KB Output is correct
44 Correct 162 ms 12664 KB Output is correct
45 Correct 161 ms 12736 KB Output is correct
46 Correct 154 ms 12664 KB Output is correct
47 Correct 888 ms 36836 KB Output is correct
48 Correct 3574 ms 118140 KB Output is correct
49 Correct 3813 ms 128932 KB Output is correct
50 Correct 3759 ms 129004 KB Output is correct
51 Correct 3651 ms 128872 KB Output is correct
52 Correct 3651 ms 129080 KB Output is correct
53 Correct 3638 ms 128872 KB Output is correct
54 Correct 3335 ms 129000 KB Output is correct
55 Correct 3479 ms 129000 KB Output is correct
56 Correct 3264 ms 129000 KB Output is correct
57 Correct 3519 ms 129084 KB Output is correct
58 Correct 3197 ms 129000 KB Output is correct
59 Correct 2950 ms 127724 KB Output is correct
60 Correct 3020 ms 127848 KB Output is correct
61 Correct 3001 ms 127768 KB Output is correct
62 Correct 2900 ms 127916 KB Output is correct
63 Correct 2916 ms 127568 KB Output is correct
64 Correct 2894 ms 127732 KB Output is correct
65 Correct 2717 ms 127544 KB Output is correct
66 Correct 2685 ms 127568 KB Output is correct
67 Correct 2670 ms 127468 KB Output is correct