답안 #1040330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1040330 2024-08-01T01:15:11 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
8 / 100
3000 ms 262144 KB
#include<bits/stdc++.h>
using namespace std;
long long n,m,a[1000006],b[1000006],rmx[30][1000006],vt[30][1000006];
void buildd()
{
	for(int i=1;i<=n;i++)
	{
		rmx[0][i]=a[i];
		vt[0][i]=i;
	}
	for(int i=1;i<=21;i++)
	{
		for(int j=1;j<=n-(1<<i)+1;j++)
		{
			if(rmx[i-1][j]>=rmx[i-1][j+(1<<(i-1))])
			{
				rmx[i][j]=rmx[i-1][j];
				vt[i][j]=vt[i-1][j];
			}
			else
			{
				rmx[i][j]=rmx[i-1][j+(1<<(i-1))];
				vt[i][j]=vt[i-1][j+(1<<(i-1))];
			}
		}
	}
}
pair<int,int> getmx(long long l,long long r)
{
	long long k=__lg(r-l+1);
	if(rmx[k][l]>=rmx[k][r-(1<<k)+1])
	{
		return {rmx[k][l],vt[k][l]};
	}
	else return {rmx[k][r-(1<<k)+1],vt[k][r-(1<<k)+1]};
}
long long get(long long l,long long r,long long w)
{
	if(l==r)
	{
		if(a[l]!=w) return a[l];
		else return -1;
	}
	if(getmx(l,r).first!=w) return w;
	long long mid=(l+r)/2;
	return max(get(l,mid,w),get(mid+1,r,w));
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
//	freopen(".inp","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	buildd();
	while(m--)
	{
		long long l,r,k;
		cin>>l>>r>>k;
//		while(r>=l&&getmx(l,r).first==a[r])
//		{
//			r--;
//		}
//		if(r<l) cout<<1<<endl;
//		else
//		{
//			pair<long long,long long> p=getmx(l,r);
//			long long h=get(p.second,r,p.first);
//			if(p.first+h<=k)
//			{
//				cout<<1<<endl;
//			}
//			else cout<<0<<endl;
//		}
		long long res=0;
		for(int i=l;i<=r;i++)
		{
			b[i]=a[i];
		}
		for(int i=1;i<=r-l+1;i++)
		{
			for(int j=l;j<=r-i;j++)
			{
				if(b[j]>b[j+1])
				{
					res=max(res,b[j]+b[j+1]);
					swap(b[j],b[j+1]);
				}
			}
		}
		if(res<=k) cout<<1<<endl;
		else cout<<0<<endl;
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 10 ms 604 KB Output is correct
7 Correct 10 ms 604 KB Output is correct
8 Correct 23 ms 604 KB Output is correct
9 Correct 7 ms 604 KB Output is correct
10 Correct 20 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 10 ms 604 KB Output is correct
7 Correct 10 ms 604 KB Output is correct
8 Correct 23 ms 604 KB Output is correct
9 Correct 7 ms 604 KB Output is correct
10 Correct 20 ms 604 KB Output is correct
11 Correct 400 ms 860 KB Output is correct
12 Execution timed out 3016 ms 1624 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 156 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3072 ms 26756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 10 ms 604 KB Output is correct
7 Correct 10 ms 604 KB Output is correct
8 Correct 23 ms 604 KB Output is correct
9 Correct 7 ms 604 KB Output is correct
10 Correct 20 ms 604 KB Output is correct
11 Correct 400 ms 860 KB Output is correct
12 Execution timed out 3016 ms 1624 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 10 ms 604 KB Output is correct
7 Correct 10 ms 604 KB Output is correct
8 Correct 23 ms 604 KB Output is correct
9 Correct 7 ms 604 KB Output is correct
10 Correct 20 ms 604 KB Output is correct
11 Correct 400 ms 860 KB Output is correct
12 Execution timed out 3016 ms 1624 KB Time limit exceeded
13 Halted 0 ms 0 KB -