답안 #987166

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987166 2024-05-22T07:34:40 Z Pyqe 송신탑 (IOI22_towers) C++17
35 / 100
1281 ms 157700 KB
#include <bits/stdc++.h>
#include "towers.h"

using namespace std;

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

const long long inf=1e18;
long long n,udn=0,a[100069],uds[100069];
multiset<long long> ms;
multiset<pair<long long,pair<long long,long long>>> rg;
bitset<100069> spc;

struct segtree
{
	long long l,r,sm;
	pair<long long,long long> mxl,mxr;
	segtree *p[2];
	
	void bd(long long lb,long long rb)
	{
		l=lb;
		r=rb;
		if(l==r)
		{
			sm=spc[l];
			mxl={spc[l],-l};
			mxr={spc[l],l};
		}
		else
		{
			long long 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);
			}
			sm=p[0]->sm+p[1]->sm;
			mxl=max(p[0]->mxl,p[1]->mxl);
			mxr=max(p[0]->mxr,p[1]->mxr);
		}
	}
	void ud(long long x,long long w)
	{
		if(l>=x&&r<=x)
		{
			sm+=w;
			mxl.fr+=w;
			mxr.fr+=w;
		}
		else
		{
			long long ii;
			
			for(ii=0;ii<2;ii++)
			{
				if(!(p[ii]->l>x||p[ii]->r<x))
				{
					segtree *tmp=p[ii];
					
					p[ii]=new segtree;
					*p[ii]=*tmp;
					p[ii]->ud(x,w);
				}
			}
			sm=p[0]->sm+p[1]->sm;
			mxl=max(p[0]->mxl,p[1]->mxl);
			mxr=max(p[0]->mxr,p[1]->mxr);
		}
	}
	long long qrs(long long lb,long long rb)
	{
		if(l>rb||r<lb)
		{
			return 0;
		}
		else if(l>=lb&&r<=rb)
		{
			return sm;
		}
		else
		{
			return p[0]->qrs(lb,rb)+p[1]->qrs(lb,rb);
		}
	}
	pair<long long,long long> qrxl(long long lb,long long rb)
	{
		if(l>rb||r<lb)
		{
			return {-inf,-1};
		}
		else if(l>=lb&&r<=rb)
		{
			return mxl;
		}
		else
		{
			return max(p[0]->qrxl(lb,rb),p[1]->qrxl(lb,rb));
		}
	}
	pair<long long,long long> qrxr(long long lb,long long rb)
	{
		if(l>rb||r<lb)
		{
			return {-inf,-1};
		}
		else if(l>=lb&&r<=rb)
		{
			return mxr;
		}
		else
		{
			return max(p[0]->qrxr(lb,rb),p[1]->qrxr(lb,rb));
		}
	}
}
sg[100069];

void init(int on,vector<int> aa)
{
	long long i,k,l=-1,w,k2,l2;
	
	n=on;
	for(i=1;i<=n;i++)
	{
		a[i]=aa[i-1];
	}
	ms.insert(-inf);
	ms.insert(inf);
	for(i=1;i<=n;i++)
	{
		if(((i==1||a[i]<a[i-1])&&(i==n||a[i]<a[i+1]))||(i>1&&i<n&&a[i]>max(a[i-1],a[i+1])))
		{
			ms.insert(i);
			if(l!=-1)
			{
				rg.insert({abs(a[l]-a[i]),{l,i}});
			}
			l=i;
			spc[i]=1;
		}
	}
	sg[0].bd(1,n);
	for(;!rg.empty();)
	{
		w=rg.begin()->fr;
		k=rg.begin()->sc.fr;
		l=rg.begin()->sc.sc;
		rg.erase(rg.begin());
		if(ms.find(k)==ms.end()||ms.find(l)==ms.end())
		{
			continue;
		}
		ms.erase(k);
		ms.erase(l);
		k2=*prev(ms.lower_bound(k));
		l2=*ms.upper_bound(l);
		if(k2!=-inf&&l2!=inf)
		{
			rg.insert({abs(a[k2]-a[l2]),{k2,l2}});
		}
		udn++;
		uds[udn]=w;
		sg[udn]=sg[udn-1];
		sg[udn].ud(k,-1);
		sg[udn].ud(l,-1);
	}
}

int max_towers(int lb,int rb,int cw)
{
	long long k,w,w2,w3,p,z;
	pair<long long,long long> tmp;
	
	lb++;
	rb++;
	p=lower_bound(uds+1,uds+udn+1,cw)-uds-1;
	w=sg[p].sm;
	w2=sg[p].qrs(1,lb-1);
	w3=sg[p].qrs(rb+1,n);
	z=(max(w-(w2+1)/2*2-(w3+1)/2*2,0ll)+1)/2;
	if(w2%2)
	{
		tmp=sg[p].qrxl(lb,rb);
		if(tmp.fr)
		{
			k=-tmp.sc;
			z+=a[k]-a[lb]>=cw;
		}
	}
	if(w3%2)
	{
		tmp=sg[p].qrxr(lb,rb);
		if(tmp.fr)
		{
			k=tmp.sc;
			z+=a[k]-a[rb]>=cw;
		}
	}
	z=max(z,1ll);
	return z;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 350 ms 17724 KB Output is correct
2 Correct 768 ms 24532 KB Output is correct
3 Correct 771 ms 24540 KB Output is correct
4 Correct 852 ms 24524 KB Output is correct
5 Correct 748 ms 24536 KB Output is correct
6 Correct 811 ms 24532 KB Output is correct
7 Correct 736 ms 24536 KB Output is correct
8 Correct 3 ms 7256 KB Output is correct
9 Correct 4 ms 7768 KB Output is correct
10 Correct 4 ms 7768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7768 KB Output is correct
2 Correct 6 ms 8792 KB Output is correct
3 Correct 6 ms 8792 KB Output is correct
4 Correct 7 ms 9560 KB Output is correct
5 Correct 7 ms 9560 KB Output is correct
6 Correct 7 ms 9560 KB Output is correct
7 Incorrect 8 ms 9536 KB 1st lines differ - on the 1st token, expected: '34', found: '33'
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7768 KB Output is correct
2 Correct 6 ms 8792 KB Output is correct
3 Correct 6 ms 8792 KB Output is correct
4 Correct 7 ms 9560 KB Output is correct
5 Correct 7 ms 9560 KB Output is correct
6 Correct 7 ms 9560 KB Output is correct
7 Incorrect 8 ms 9536 KB 1st lines differ - on the 1st token, expected: '34', found: '33'
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 815 ms 112060 KB Output is correct
2 Correct 1043 ms 113088 KB Output is correct
3 Correct 1025 ms 113232 KB Output is correct
4 Correct 1149 ms 157376 KB Output is correct
5 Correct 1238 ms 157400 KB Output is correct
6 Correct 1281 ms 157384 KB Output is correct
7 Correct 1277 ms 157436 KB Output is correct
8 Correct 755 ms 24536 KB Output is correct
9 Correct 788 ms 24508 KB Output is correct
10 Correct 819 ms 24528 KB Output is correct
11 Correct 753 ms 24736 KB Output is correct
12 Correct 725 ms 24540 KB Output is correct
13 Correct 759 ms 24664 KB Output is correct
14 Correct 4 ms 7256 KB Output is correct
15 Correct 4 ms 7768 KB Output is correct
16 Correct 5 ms 7768 KB Output is correct
17 Correct 348 ms 112888 KB Output is correct
18 Correct 415 ms 157488 KB Output is correct
19 Correct 430 ms 157376 KB Output is correct
20 Correct 25 ms 24792 KB Output is correct
21 Correct 27 ms 24584 KB Output is correct
22 Correct 274 ms 113000 KB Output is correct
23 Correct 369 ms 157368 KB Output is correct
24 Correct 466 ms 157348 KB Output is correct
25 Correct 24 ms 24512 KB Output is correct
26 Correct 28 ms 24488 KB Output is correct
27 Correct 6 ms 8792 KB Output is correct
28 Correct 7 ms 9560 KB Output is correct
29 Correct 7 ms 9560 KB Output is correct
30 Correct 4 ms 7768 KB Output is correct
31 Correct 4 ms 7964 KB Output is correct
32 Correct 7 ms 8792 KB Output is correct
33 Correct 8 ms 9560 KB Output is correct
34 Correct 8 ms 9560 KB Output is correct
35 Correct 5 ms 7768 KB Output is correct
36 Correct 4 ms 7768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 30032 KB Output is correct
2 Correct 777 ms 113092 KB Output is correct
3 Correct 844 ms 113056 KB Output is correct
4 Correct 1006 ms 157520 KB Output is correct
5 Correct 1014 ms 157376 KB Output is correct
6 Correct 934 ms 157352 KB Output is correct
7 Correct 1004 ms 157412 KB Output is correct
8 Correct 556 ms 24512 KB Output is correct
9 Correct 558 ms 24540 KB Output is correct
10 Correct 552 ms 24508 KB Output is correct
11 Correct 560 ms 24520 KB Output is correct
12 Correct 265 ms 112996 KB Output is correct
13 Correct 423 ms 157460 KB Output is correct
14 Correct 383 ms 157644 KB Output is correct
15 Correct 25 ms 24532 KB Output is correct
16 Correct 27 ms 24536 KB Output is correct
17 Correct 265 ms 109476 KB Output is correct
18 Correct 268 ms 113172 KB Output is correct
19 Correct 301 ms 113360 KB Output is correct
20 Correct 483 ms 157412 KB Output is correct
21 Correct 415 ms 157428 KB Output is correct
22 Correct 470 ms 157700 KB Output is correct
23 Correct 427 ms 157380 KB Output is correct
24 Correct 28 ms 24780 KB Output is correct
25 Correct 26 ms 24684 KB Output is correct
26 Correct 26 ms 24532 KB Output is correct
27 Correct 35 ms 24528 KB Output is correct
28 Correct 6 ms 8792 KB Output is correct
29 Correct 7 ms 9560 KB Output is correct
30 Correct 7 ms 9560 KB Output is correct
31 Correct 4 ms 7768 KB Output is correct
32 Correct 5 ms 7768 KB Output is correct
33 Correct 5 ms 8024 KB Output is correct
34 Correct 9 ms 9004 KB Output is correct
35 Correct 6 ms 8792 KB Output is correct
36 Correct 8 ms 9560 KB Output is correct
37 Correct 7 ms 9560 KB Output is correct
38 Correct 7 ms 9560 KB Output is correct
39 Correct 7 ms 9560 KB Output is correct
40 Correct 4 ms 7924 KB Output is correct
41 Correct 4 ms 7768 KB Output is correct
42 Correct 4 ms 7768 KB Output is correct
43 Correct 4 ms 7764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7768 KB Output is correct
2 Correct 6 ms 8792 KB Output is correct
3 Correct 6 ms 8792 KB Output is correct
4 Correct 7 ms 9560 KB Output is correct
5 Correct 7 ms 9560 KB Output is correct
6 Correct 7 ms 9560 KB Output is correct
7 Incorrect 8 ms 9536 KB 1st lines differ - on the 1st token, expected: '34', found: '33'
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 350 ms 17724 KB Output is correct
2 Correct 768 ms 24532 KB Output is correct
3 Correct 771 ms 24540 KB Output is correct
4 Correct 852 ms 24524 KB Output is correct
5 Correct 748 ms 24536 KB Output is correct
6 Correct 811 ms 24532 KB Output is correct
7 Correct 736 ms 24536 KB Output is correct
8 Correct 3 ms 7256 KB Output is correct
9 Correct 4 ms 7768 KB Output is correct
10 Correct 4 ms 7768 KB Output is correct
11 Correct 4 ms 7768 KB Output is correct
12 Correct 6 ms 8792 KB Output is correct
13 Correct 6 ms 8792 KB Output is correct
14 Correct 7 ms 9560 KB Output is correct
15 Correct 7 ms 9560 KB Output is correct
16 Correct 7 ms 9560 KB Output is correct
17 Incorrect 8 ms 9536 KB 1st lines differ - on the 1st token, expected: '34', found: '33'
18 Halted 0 ms 0 KB -