답안 #285117

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285117 2020-08-28T10:27:47 Z Pyqe Bubble Sort 2 (JOI18_bubblesort2) C++14
60 / 100
1109 ms 524292 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>

using namespace std;

long long n,ma=1e9,inf=1e18;

struct segtree
{
	long long l,r,mx,lz;
	multiset<long long> ms;
	segtree *p[2];
	
	void bd(long long lh,long long rh)
	{
		long long ii;
		
		l=lh;
		r=rh;
		mx=-inf;
		lz=0;
		for(ii=0;ii<2;ii++)
		{
			p[ii]=0;
		}
	}
	void blc()
	{
		long long ii,md=(l+r)/2;
		
		for(ii=0;ii<2;ii++)
		{
			if(!p[ii])
			{
				p[ii]=new segtree;
				p[ii]->bd(!ii?l:md+1,!ii?md:r);
			}
			p[ii]->mx+=lz;
			p[ii]->lz+=lz;
		}
		lz=0;
	}
	void ud(long long lh,long long rh,long long w)
	{
		if(l>rh||r<lh);
		else if(l>=lh&&r<=rh)
		{
			mx+=w;
			lz+=w;
		}
		else
		{
			long long ii;
			
			blc();
			for(ii=0;ii<2;ii++)
			{
				p[ii]->ud(lh,rh,w);
			}
			mx=max(p[0]->mx,p[1]->mx);
		}
	}
	void ins(long long x,long long w)
	{
		if(l>x||r<x);
		else if(l>=x&&r<=x)
		{
			ms.insert(w);
			mx=*prev(ms.end())+lz;
		}
		else
		{
			long long ii;
			
			blc();
			for(ii=0;ii<2;ii++)
			{
				p[ii]->ins(x,w);
			}
			mx=max(p[0]->mx,p[1]->mx);
		}
	}
	void ers(long long x,long long w)
	{
		if(l>x||r<x);
		else if(l>=x&&r<=x)
		{
			ms.erase(ms.find(w));
			if(!ms.empty())
			{
				mx=*prev(ms.end())+lz;
			}
			else
			{
				mx=-inf;
			}
		}
		else
		{
			long long ii;
			
			blc();
			for(ii=0;ii<2;ii++)
			{
				p[ii]->ers(x,w);
			}
			mx=max(p[0]->mx,p[1]->mx);
		}
	}
}
sg;

vector<int> countScans(vector<int> a,vector<int> qp,vector<int> qw)
{
	long long t=qp.size(),rr,i,k,w;
	vector<int> sq;
	
	n=a.size();
	sg.bd(1,ma);
	for(i=0;i<n;i++)
	{
		sg.ins(a[i],i+1-n);
		sg.ud(1,a[i]-1,1);
	}
	for(rr=0;rr<t;rr++)
	{
		k=qp[rr];
		w=qw[rr];
		sg.ers(a[k],k+1-n);
		sg.ud(1,a[k]-1,-1);
		a[k]=w;
		sg.ins(w,k+1-n);
		sg.ud(1,w-1,1);
		sq.push_back(sg.mx);
	}
	return sq;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4864 KB Output is correct
2 Correct 11 ms 7168 KB Output is correct
3 Correct 24 ms 15452 KB Output is correct
4 Correct 24 ms 15480 KB Output is correct
5 Correct 23 ms 14848 KB Output is correct
6 Correct 24 ms 15232 KB Output is correct
7 Correct 23 ms 15232 KB Output is correct
8 Correct 23 ms 15096 KB Output is correct
9 Correct 23 ms 15096 KB Output is correct
10 Correct 19 ms 10360 KB Output is correct
11 Correct 18 ms 10496 KB Output is correct
12 Correct 18 ms 10496 KB Output is correct
13 Correct 17 ms 9600 KB Output is correct
14 Correct 17 ms 9600 KB Output is correct
15 Correct 17 ms 9600 KB Output is correct
16 Correct 16 ms 8704 KB Output is correct
17 Correct 16 ms 8704 KB Output is correct
18 Correct 18 ms 8704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4864 KB Output is correct
2 Correct 11 ms 7168 KB Output is correct
3 Correct 24 ms 15452 KB Output is correct
4 Correct 24 ms 15480 KB Output is correct
5 Correct 23 ms 14848 KB Output is correct
6 Correct 24 ms 15232 KB Output is correct
7 Correct 23 ms 15232 KB Output is correct
8 Correct 23 ms 15096 KB Output is correct
9 Correct 23 ms 15096 KB Output is correct
10 Correct 19 ms 10360 KB Output is correct
11 Correct 18 ms 10496 KB Output is correct
12 Correct 18 ms 10496 KB Output is correct
13 Correct 17 ms 9600 KB Output is correct
14 Correct 17 ms 9600 KB Output is correct
15 Correct 17 ms 9600 KB Output is correct
16 Correct 16 ms 8704 KB Output is correct
17 Correct 16 ms 8704 KB Output is correct
18 Correct 18 ms 8704 KB Output is correct
19 Correct 84 ms 48120 KB Output is correct
20 Correct 92 ms 53984 KB Output is correct
21 Correct 89 ms 53240 KB Output is correct
22 Correct 92 ms 51960 KB Output is correct
23 Correct 72 ms 36600 KB Output is correct
24 Correct 74 ms 36472 KB Output is correct
25 Correct 67 ms 33228 KB Output is correct
26 Correct 67 ms 33272 KB Output is correct
27 Correct 65 ms 30200 KB Output is correct
28 Correct 63 ms 30200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 2144 KB Output is correct
2 Correct 133 ms 3452 KB Output is correct
3 Correct 212 ms 4980 KB Output is correct
4 Correct 213 ms 4856 KB Output is correct
5 Correct 235 ms 4856 KB Output is correct
6 Correct 222 ms 4856 KB Output is correct
7 Correct 220 ms 5028 KB Output is correct
8 Correct 227 ms 4884 KB Output is correct
9 Correct 208 ms 4988 KB Output is correct
10 Correct 200 ms 4984 KB Output is correct
11 Correct 200 ms 4856 KB Output is correct
12 Correct 201 ms 4856 KB Output is correct
13 Correct 195 ms 4984 KB Output is correct
14 Correct 195 ms 4984 KB Output is correct
15 Correct 193 ms 4856 KB Output is correct
16 Correct 180 ms 4984 KB Output is correct
17 Correct 183 ms 4856 KB Output is correct
18 Correct 187 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4864 KB Output is correct
2 Correct 11 ms 7168 KB Output is correct
3 Correct 24 ms 15452 KB Output is correct
4 Correct 24 ms 15480 KB Output is correct
5 Correct 23 ms 14848 KB Output is correct
6 Correct 24 ms 15232 KB Output is correct
7 Correct 23 ms 15232 KB Output is correct
8 Correct 23 ms 15096 KB Output is correct
9 Correct 23 ms 15096 KB Output is correct
10 Correct 19 ms 10360 KB Output is correct
11 Correct 18 ms 10496 KB Output is correct
12 Correct 18 ms 10496 KB Output is correct
13 Correct 17 ms 9600 KB Output is correct
14 Correct 17 ms 9600 KB Output is correct
15 Correct 17 ms 9600 KB Output is correct
16 Correct 16 ms 8704 KB Output is correct
17 Correct 16 ms 8704 KB Output is correct
18 Correct 18 ms 8704 KB Output is correct
19 Correct 84 ms 48120 KB Output is correct
20 Correct 92 ms 53984 KB Output is correct
21 Correct 89 ms 53240 KB Output is correct
22 Correct 92 ms 51960 KB Output is correct
23 Correct 72 ms 36600 KB Output is correct
24 Correct 74 ms 36472 KB Output is correct
25 Correct 67 ms 33228 KB Output is correct
26 Correct 67 ms 33272 KB Output is correct
27 Correct 65 ms 30200 KB Output is correct
28 Correct 63 ms 30200 KB Output is correct
29 Correct 44 ms 2144 KB Output is correct
30 Correct 133 ms 3452 KB Output is correct
31 Correct 212 ms 4980 KB Output is correct
32 Correct 213 ms 4856 KB Output is correct
33 Correct 235 ms 4856 KB Output is correct
34 Correct 222 ms 4856 KB Output is correct
35 Correct 220 ms 5028 KB Output is correct
36 Correct 227 ms 4884 KB Output is correct
37 Correct 208 ms 4988 KB Output is correct
38 Correct 200 ms 4984 KB Output is correct
39 Correct 200 ms 4856 KB Output is correct
40 Correct 201 ms 4856 KB Output is correct
41 Correct 195 ms 4984 KB Output is correct
42 Correct 195 ms 4984 KB Output is correct
43 Correct 193 ms 4856 KB Output is correct
44 Correct 180 ms 4984 KB Output is correct
45 Correct 183 ms 4856 KB Output is correct
46 Correct 187 ms 5072 KB Output is correct
47 Runtime error 1109 ms 524292 KB Execution killed with signal 9
48 Halted 0 ms 0 KB -