답안 #157761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
157761 2019-10-12T19:47:20 Z TadijaSebez Sushi (JOI16_sushi) C++11
100 / 100
9197 ms 7056 KB
#include <bits/stdc++.h>
using namespace std;
const int N=400050;
const int S=777;
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 322 ms 504 KB Output is correct
2 Correct 316 ms 556 KB Output is correct
3 Correct 321 ms 504 KB Output is correct
4 Correct 315 ms 516 KB Output is correct
5 Correct 327 ms 548 KB Output is correct
6 Correct 328 ms 504 KB Output is correct
7 Correct 239 ms 376 KB Output is correct
8 Correct 242 ms 412 KB Output is correct
9 Correct 320 ms 448 KB Output is correct
10 Correct 318 ms 484 KB Output is correct
11 Correct 308 ms 416 KB Output is correct
12 Correct 311 ms 420 KB Output is correct
13 Correct 331 ms 548 KB Output is correct
14 Correct 446 ms 504 KB Output is correct
15 Correct 441 ms 376 KB Output is correct
16 Correct 146 ms 380 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 5091 ms 6964 KB Output is correct
2 Correct 5107 ms 6776 KB Output is correct
3 Correct 4370 ms 6528 KB Output is correct
4 Correct 5082 ms 6736 KB Output is correct
5 Correct 4006 ms 6840 KB Output is correct
6 Correct 5005 ms 6960 KB Output is correct
7 Correct 4983 ms 6816 KB Output is correct
8 Correct 4914 ms 6884 KB Output is correct
9 Correct 4062 ms 6620 KB Output is correct
10 Correct 4117 ms 6740 KB Output is correct
11 Correct 4011 ms 6744 KB Output is correct
12 Correct 4072 ms 6840 KB Output is correct
13 Correct 5070 ms 6788 KB Output is correct
14 Correct 5169 ms 6868 KB Output is correct
15 Correct 4346 ms 6604 KB Output is correct
16 Correct 5103 ms 6856 KB Output is correct
17 Correct 4040 ms 6860 KB Output is correct
18 Correct 4979 ms 6812 KB Output is correct
19 Correct 4977 ms 6868 KB Output is correct
20 Correct 4896 ms 6868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 322 ms 504 KB Output is correct
2 Correct 316 ms 556 KB Output is correct
3 Correct 321 ms 504 KB Output is correct
4 Correct 315 ms 516 KB Output is correct
5 Correct 327 ms 548 KB Output is correct
6 Correct 328 ms 504 KB Output is correct
7 Correct 239 ms 376 KB Output is correct
8 Correct 242 ms 412 KB Output is correct
9 Correct 320 ms 448 KB Output is correct
10 Correct 318 ms 484 KB Output is correct
11 Correct 308 ms 416 KB Output is correct
12 Correct 311 ms 420 KB Output is correct
13 Correct 331 ms 548 KB Output is correct
14 Correct 446 ms 504 KB Output is correct
15 Correct 441 ms 376 KB Output is correct
16 Correct 146 ms 380 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 5091 ms 6964 KB Output is correct
24 Correct 5107 ms 6776 KB Output is correct
25 Correct 4370 ms 6528 KB Output is correct
26 Correct 5082 ms 6736 KB Output is correct
27 Correct 4006 ms 6840 KB Output is correct
28 Correct 5005 ms 6960 KB Output is correct
29 Correct 4983 ms 6816 KB Output is correct
30 Correct 4914 ms 6884 KB Output is correct
31 Correct 4062 ms 6620 KB Output is correct
32 Correct 4117 ms 6740 KB Output is correct
33 Correct 4011 ms 6744 KB Output is correct
34 Correct 4072 ms 6840 KB Output is correct
35 Correct 5070 ms 6788 KB Output is correct
36 Correct 5169 ms 6868 KB Output is correct
37 Correct 4346 ms 6604 KB Output is correct
38 Correct 5103 ms 6856 KB Output is correct
39 Correct 4040 ms 6860 KB Output is correct
40 Correct 4979 ms 6812 KB Output is correct
41 Correct 4977 ms 6868 KB Output is correct
42 Correct 4896 ms 6868 KB Output is correct
43 Correct 6542 ms 6792 KB Output is correct
44 Correct 6505 ms 6924 KB Output is correct
45 Correct 5778 ms 6644 KB Output is correct
46 Correct 6528 ms 6920 KB Output is correct
47 Correct 6532 ms 6836 KB Output is correct
48 Correct 6296 ms 6944 KB Output is correct
49 Correct 6908 ms 6876 KB Output is correct
50 Correct 6972 ms 6912 KB Output is correct
51 Correct 6862 ms 6828 KB Output is correct
52 Correct 8748 ms 6936 KB Output is correct
53 Correct 8491 ms 7036 KB Output is correct
54 Correct 8301 ms 6980 KB Output is correct
55 Correct 9197 ms 7000 KB Output is correct
56 Correct 9166 ms 7016 KB Output is correct
57 Correct 9075 ms 6992 KB Output is correct
58 Correct 4624 ms 6872 KB Output is correct
59 Correct 4372 ms 6940 KB Output is correct
60 Correct 4155 ms 6836 KB Output is correct
61 Correct 5025 ms 7040 KB Output is correct
62 Correct 5014 ms 6956 KB Output is correct
63 Correct 4963 ms 6948 KB Output is correct
64 Correct 5234 ms 6560 KB Output is correct
65 Correct 3932 ms 6760 KB Output is correct
66 Correct 3903 ms 6904 KB Output is correct
67 Correct 7918 ms 7012 KB Output is correct
68 Correct 8791 ms 7056 KB Output is correct
69 Correct 8734 ms 6924 KB Output is correct
70 Correct 8561 ms 7032 KB Output is correct