답안 #157746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
157746 2019-10-12T19:29:12 Z TadijaSebez Sushi (JOI16_sushi) C++11
5 / 100
12000 ms 21120 KB
#include <bits/stdc++.h>
using namespace std;
const int N=400050;
const int S=N;
const int M=N/S+1;
const int Q=25050;
multiset<pair<int,int>> st[M];
int a[N],n,q,ok[M];
bool mark[N];
int Push(int B, int x)
{
	st[B].insert({x,0});
	int p;tie(x,p)=*st[B].rbegin();
	st[B].erase(--st[B].end());
	if(p) mark[-p]=1,ok[B]=0;
	return x;
}
void BuildBlock(int B, int l, int r){ for(int i=l;i<=r;i++) st[B].insert({a[i],-i}),mark[i]=0;ok[B]=1;}
void BreakBlock(int B)
{
	if(ok[B]) st[B].clear();
	else
	{
		int l=B*S,r=min((B+1)*S,n)-1;
		for(int i=r;i>=l;i--)
		{
			if(mark[i])
			{
				int x,y;tie(x,y)=*st[B].rbegin();
				st[B].erase(--st[B].end());
				a[i]=x;
				if(y) mark[-y]=1;
			}
			else
			{
				st[B].erase(st[B].find({a[i],-i}));
			}
		}
	}
}
int Push(int B, int l, int r, int x)
{
	BreakBlock(B);
	for(int i=l;i<=r;i++) if(a[i]>x) swap(a[i],x);
	BuildBlock(B,B*S,min((B+1)*S,n)-1);
	return x;
}
void BuildAll(){ for(int l=0;l<n;l+=S) BuildBlock(l/S,l,min(l+S,n)-1);}
int Query(int l, int r, int x)
{
	int L=l/S,R=r/S;
	if(L==R)
	{
		if(l==L*S && r==R*S+S-1) x=Push(L,x);
		else x=Push(L,l,r,x);
	}
	else
	{
		if(l==L*S) x=Push(L,x);
		else x=Push(L,l,L*S+S-1,x);
		for(int i=L+1;i<R;i++) x=Push(i,x);
		if(r==R*S+S-1) x=Push(R,x);
		else x=Push(R,R*S,r,x);
	}
	return x;
}
int main()
{
	scanf("%i %i",&n,&q);
	for(int i=0;i<n;i++) scanf("%i",&a[i]);
	BuildAll();
	while(q--)
	{
		int l,r,x;
		scanf("%i %i %i",&l,&r,&x);
		l--;r--;
		if(l<=r) x=Query(l,r,x);
		else x=Query(0,r,Query(l,n-1,x));
		printf("%i\n",x);
	}
	return 0;
}

Compilation message

sushi.cpp: In function 'int main()':
sushi.cpp:69:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&q);
  ~~~~~^~~~~~~~~~~~~~~
sushi.cpp:70:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) scanf("%i",&a[i]);
                       ~~~~~^~~~~~~~~~~~
sushi.cpp:75:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i %i",&l,&r,&x);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 946 ms 512 KB Output is correct
2 Correct 941 ms 380 KB Output is correct
3 Correct 940 ms 504 KB Output is correct
4 Correct 942 ms 504 KB Output is correct
5 Correct 960 ms 604 KB Output is correct
6 Correct 972 ms 632 KB Output is correct
7 Correct 757 ms 604 KB Output is correct
8 Correct 766 ms 504 KB Output is correct
9 Correct 938 ms 620 KB Output is correct
10 Correct 934 ms 636 KB Output is correct
11 Correct 775 ms 612 KB Output is correct
12 Correct 777 ms 528 KB Output is correct
13 Correct 827 ms 504 KB Output is correct
14 Correct 1241 ms 504 KB Output is correct
15 Correct 1231 ms 608 KB Output is correct
16 Correct 641 ms 632 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 12073 ms 21120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 946 ms 512 KB Output is correct
2 Correct 941 ms 380 KB Output is correct
3 Correct 940 ms 504 KB Output is correct
4 Correct 942 ms 504 KB Output is correct
5 Correct 960 ms 604 KB Output is correct
6 Correct 972 ms 632 KB Output is correct
7 Correct 757 ms 604 KB Output is correct
8 Correct 766 ms 504 KB Output is correct
9 Correct 938 ms 620 KB Output is correct
10 Correct 934 ms 636 KB Output is correct
11 Correct 775 ms 612 KB Output is correct
12 Correct 777 ms 528 KB Output is correct
13 Correct 827 ms 504 KB Output is correct
14 Correct 1241 ms 504 KB Output is correct
15 Correct 1231 ms 608 KB Output is correct
16 Correct 641 ms 632 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 252 KB Output is correct
23 Execution timed out 12073 ms 21120 KB Time limit exceeded
24 Halted 0 ms 0 KB -