답안 #157750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
157750 2019-10-12T19:37:03 Z TadijaSebez Sushi (JOI16_sushi) C++11
100 / 100
6598 ms 11496 KB
#include <bits/stdc++.h>
using namespace std;
const int N=400050;
const int S=200;
const int M=N/S+1;
const int Q=25050;
priority_queue<pair<int,int>> st[M];
int a[N],n,q;
bool mark[N];
int Push(int B, int x)
{
	st[B].push({x,0});
	int p;tie(x,p)=st[B].top();
	st[B].pop();
	if(p) mark[-p]=1;
	return x;
}
void BuildBlock(int B, int l, int r){ for(int i=l;i<=r;i++) st[B].push({a[i],-i}),mark[i]=0;}
void BreakBlock(int B)
{
	int l=B*S,r=min((B+1)*S,n)-1;
	for(int i=r;i>=l;i--)
	{
		if(mark[i])
		{
			int x,y;
			do
			{
				tie(x,y)=st[B].top();
				st[B].pop();
			}while(-y>i);
			a[i]=x;
			if(y) mark[-y]=1;
		}
	}
	while(st[B].size()) st[B].pop();
}
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)
	{
		x=Push(L,l,r,x);
	}
	else
	{
		x=Push(L,l,L*S+S-1,x);
		for(int i=L+1;i<R;i++) x=Push(i,x);
		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:63: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:64: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:69: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 102 ms 376 KB Output is correct
2 Correct 99 ms 496 KB Output is correct
3 Correct 100 ms 492 KB Output is correct
4 Correct 104 ms 504 KB Output is correct
5 Correct 100 ms 508 KB Output is correct
6 Correct 101 ms 376 KB Output is correct
7 Correct 74 ms 464 KB Output is correct
8 Correct 74 ms 504 KB Output is correct
9 Correct 101 ms 520 KB Output is correct
10 Correct 100 ms 376 KB Output is correct
11 Correct 96 ms 504 KB Output is correct
12 Correct 97 ms 376 KB Output is correct
13 Correct 107 ms 504 KB Output is correct
14 Correct 134 ms 504 KB Output is correct
15 Correct 129 ms 528 KB Output is correct
16 Correct 39 ms 376 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 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5438 ms 6888 KB Output is correct
2 Correct 5531 ms 9924 KB Output is correct
3 Correct 6201 ms 7776 KB Output is correct
4 Correct 5332 ms 11164 KB Output is correct
5 Correct 3579 ms 11260 KB Output is correct
6 Correct 6150 ms 11268 KB Output is correct
7 Correct 6096 ms 11220 KB Output is correct
8 Correct 6033 ms 11276 KB Output is correct
9 Correct 5618 ms 7672 KB Output is correct
10 Correct 3735 ms 9904 KB Output is correct
11 Correct 5523 ms 7652 KB Output is correct
12 Correct 3619 ms 9980 KB Output is correct
13 Correct 5333 ms 11084 KB Output is correct
14 Correct 5612 ms 9816 KB Output is correct
15 Correct 6182 ms 7772 KB Output is correct
16 Correct 5313 ms 11272 KB Output is correct
17 Correct 3564 ms 11316 KB Output is correct
18 Correct 6138 ms 11380 KB Output is correct
19 Correct 6075 ms 11272 KB Output is correct
20 Correct 6040 ms 11300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 376 KB Output is correct
2 Correct 99 ms 496 KB Output is correct
3 Correct 100 ms 492 KB Output is correct
4 Correct 104 ms 504 KB Output is correct
5 Correct 100 ms 508 KB Output is correct
6 Correct 101 ms 376 KB Output is correct
7 Correct 74 ms 464 KB Output is correct
8 Correct 74 ms 504 KB Output is correct
9 Correct 101 ms 520 KB Output is correct
10 Correct 100 ms 376 KB Output is correct
11 Correct 96 ms 504 KB Output is correct
12 Correct 97 ms 376 KB Output is correct
13 Correct 107 ms 504 KB Output is correct
14 Correct 134 ms 504 KB Output is correct
15 Correct 129 ms 528 KB Output is correct
16 Correct 39 ms 376 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 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 5438 ms 6888 KB Output is correct
24 Correct 5531 ms 9924 KB Output is correct
25 Correct 6201 ms 7776 KB Output is correct
26 Correct 5332 ms 11164 KB Output is correct
27 Correct 3579 ms 11260 KB Output is correct
28 Correct 6150 ms 11268 KB Output is correct
29 Correct 6096 ms 11220 KB Output is correct
30 Correct 6033 ms 11276 KB Output is correct
31 Correct 5618 ms 7672 KB Output is correct
32 Correct 3735 ms 9904 KB Output is correct
33 Correct 5523 ms 7652 KB Output is correct
34 Correct 3619 ms 9980 KB Output is correct
35 Correct 5333 ms 11084 KB Output is correct
36 Correct 5612 ms 9816 KB Output is correct
37 Correct 6182 ms 7772 KB Output is correct
38 Correct 5313 ms 11272 KB Output is correct
39 Correct 3564 ms 11316 KB Output is correct
40 Correct 6138 ms 11380 KB Output is correct
41 Correct 6075 ms 11272 KB Output is correct
42 Correct 6040 ms 11300 KB Output is correct
43 Correct 3190 ms 11276 KB Output is correct
44 Correct 3182 ms 11276 KB Output is correct
45 Correct 3879 ms 7968 KB Output is correct
46 Correct 3195 ms 11384 KB Output is correct
47 Correct 3178 ms 11336 KB Output is correct
48 Correct 3801 ms 11408 KB Output is correct
49 Correct 4324 ms 11368 KB Output is correct
50 Correct 4143 ms 11404 KB Output is correct
51 Correct 4129 ms 11404 KB Output is correct
52 Correct 5354 ms 11264 KB Output is correct
53 Correct 5116 ms 11320 KB Output is correct
54 Correct 5958 ms 11496 KB Output is correct
55 Correct 6550 ms 11284 KB Output is correct
56 Correct 6598 ms 11352 KB Output is correct
57 Correct 6504 ms 11404 KB Output is correct
58 Correct 3611 ms 11140 KB Output is correct
59 Correct 3647 ms 11356 KB Output is correct
60 Correct 3978 ms 11240 KB Output is correct
61 Correct 6160 ms 11288 KB Output is correct
62 Correct 6163 ms 11208 KB Output is correct
63 Correct 6097 ms 11400 KB Output is correct
64 Correct 3562 ms 7952 KB Output is correct
65 Correct 2681 ms 9952 KB Output is correct
66 Correct 2630 ms 9784 KB Output is correct
67 Correct 4669 ms 11484 KB Output is correct
68 Correct 6089 ms 11480 KB Output is correct
69 Correct 6078 ms 11424 KB Output is correct
70 Correct 5994 ms 11372 KB Output is correct