답안 #191494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
191494 2020-01-15T02:30:42 Z dndhk Sushi (JOI16_sushi) C++14
100 / 100
7555 ms 10764 KB
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX_N = 400000;
const int SQ = 700;

int N, Q;
int arr[MAX_N+1];
int g[MAX_N+1];
priority_queue<int> pq1[SQ+1], pq2;

int solve(int gn, int s, int e, int k){
	int x = gn*SQ+1, y = min((gn+1)*SQ, N);
	//cout<<s<<" "<<e<<" "<<k<<" "<<endl;
	//cout<<x<<" "<<y<<endl;
	if(s<=x && y<=e){
		pq1[gn].push(k);
		k = pq1[gn].top();
		pq1[gn].pop();
		return k;
	}else{
		for(int i=y; i>=x; i--){
			while(!pq1[gn].empty() && !pq2.empty() && pq1[gn].top()==pq2.top()){
				pq1[gn].pop();
				pq2.pop();
			}
			//cout<<i<<" "<<pq1[gn].top()<<" "<<arr[i]<<endl;
			if(arr[i]>pq1[gn].top()){
				arr[i] = pq1[gn].top();
				pq1[gn].pop();
			}else{
				pq2.push(arr[i]);
			}
		}
		while(!pq1[gn].empty())	pq1[gn].pop();
		while(!pq2.empty())	pq2.pop();
		for(int i=x; i<=y; i++){
			if(s<=i && i<=e){
				if(k<arr[i]){
					int tmp = k;
					k = arr[i];
					arr[i] = tmp;
				}
			}
			pq1[gn].push(arr[i]);
		}
		return k;
	}
}

int main(){
	scanf("%d%d", &N, &Q);
	for(int i=1; i<=N; i++){
		scanf("%d", &arr[i]);
		g[i] = (i-1)/SQ;
		pq1[g[i]].push(arr[i]);
	}
	for(int i=1; i<=Q; i++){
		int s, e, k;
		scanf("%d%d%d", &s, &e, &k);
		if(s<=e){
			int n = g[s];
			while(n<=g[e]){
				k = solve(n, s, e, k);
				n++;
			}
		}else{
			int n = g[s];
			while(n<=g[N]){
				k = solve(n, s, N, k);
				n++;
			}
			n = 0;
			while(n<=g[e]){
				k = solve(n, 1, e, k);
				n++;
			}
		}
		printf("%d\n", k);
	}

}

Compilation message

sushi.cpp: In function 'int main()':
sushi.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &Q);
  ~~~~~^~~~~~~~~~~~~~~~
sushi.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &arr[i]);
   ~~~~~^~~~~~~~~~~~~~~
sushi.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &s, &e, &k);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 443 ms 520 KB Output is correct
2 Correct 444 ms 768 KB Output is correct
3 Correct 449 ms 648 KB Output is correct
4 Correct 439 ms 532 KB Output is correct
5 Correct 438 ms 632 KB Output is correct
6 Correct 436 ms 508 KB Output is correct
7 Correct 169 ms 504 KB Output is correct
8 Correct 172 ms 524 KB Output is correct
9 Correct 450 ms 536 KB Output is correct
10 Correct 450 ms 632 KB Output is correct
11 Correct 387 ms 528 KB Output is correct
12 Correct 403 ms 516 KB Output is correct
13 Correct 391 ms 632 KB Output is correct
14 Correct 478 ms 512 KB Output is correct
15 Correct 456 ms 732 KB Output is correct
16 Correct 245 ms 660 KB Output is correct
17 Correct 1 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 0 ms 376 KB Output is correct
22 Correct 1 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1538 ms 8408 KB Output is correct
2 Correct 1543 ms 8988 KB Output is correct
3 Correct 915 ms 6988 KB Output is correct
4 Correct 1551 ms 9248 KB Output is correct
5 Correct 883 ms 9248 KB Output is correct
6 Correct 1350 ms 10120 KB Output is correct
7 Correct 1321 ms 9696 KB Output is correct
8 Correct 1308 ms 9956 KB Output is correct
9 Correct 720 ms 7032 KB Output is correct
10 Correct 867 ms 9108 KB Output is correct
11 Correct 722 ms 7032 KB Output is correct
12 Correct 872 ms 9228 KB Output is correct
13 Correct 1515 ms 10332 KB Output is correct
14 Correct 1553 ms 9352 KB Output is correct
15 Correct 906 ms 7064 KB Output is correct
16 Correct 1549 ms 10572 KB Output is correct
17 Correct 853 ms 10712 KB Output is correct
18 Correct 1325 ms 10400 KB Output is correct
19 Correct 1343 ms 10672 KB Output is correct
20 Correct 1304 ms 10544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 443 ms 520 KB Output is correct
2 Correct 444 ms 768 KB Output is correct
3 Correct 449 ms 648 KB Output is correct
4 Correct 439 ms 532 KB Output is correct
5 Correct 438 ms 632 KB Output is correct
6 Correct 436 ms 508 KB Output is correct
7 Correct 169 ms 504 KB Output is correct
8 Correct 172 ms 524 KB Output is correct
9 Correct 450 ms 536 KB Output is correct
10 Correct 450 ms 632 KB Output is correct
11 Correct 387 ms 528 KB Output is correct
12 Correct 403 ms 516 KB Output is correct
13 Correct 391 ms 632 KB Output is correct
14 Correct 478 ms 512 KB Output is correct
15 Correct 456 ms 732 KB Output is correct
16 Correct 245 ms 660 KB Output is correct
17 Correct 1 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 0 ms 376 KB Output is correct
22 Correct 1 ms 380 KB Output is correct
23 Correct 1538 ms 8408 KB Output is correct
24 Correct 1543 ms 8988 KB Output is correct
25 Correct 915 ms 6988 KB Output is correct
26 Correct 1551 ms 9248 KB Output is correct
27 Correct 883 ms 9248 KB Output is correct
28 Correct 1350 ms 10120 KB Output is correct
29 Correct 1321 ms 9696 KB Output is correct
30 Correct 1308 ms 9956 KB Output is correct
31 Correct 720 ms 7032 KB Output is correct
32 Correct 867 ms 9108 KB Output is correct
33 Correct 722 ms 7032 KB Output is correct
34 Correct 872 ms 9228 KB Output is correct
35 Correct 1515 ms 10332 KB Output is correct
36 Correct 1553 ms 9352 KB Output is correct
37 Correct 906 ms 7064 KB Output is correct
38 Correct 1549 ms 10572 KB Output is correct
39 Correct 853 ms 10712 KB Output is correct
40 Correct 1325 ms 10400 KB Output is correct
41 Correct 1343 ms 10672 KB Output is correct
42 Correct 1304 ms 10544 KB Output is correct
43 Correct 7016 ms 10752 KB Output is correct
44 Correct 7015 ms 10748 KB Output is correct
45 Correct 3582 ms 7264 KB Output is correct
46 Correct 7064 ms 10584 KB Output is correct
47 Correct 7091 ms 10756 KB Output is correct
48 Correct 3928 ms 10468 KB Output is correct
49 Correct 4054 ms 10676 KB Output is correct
50 Correct 4040 ms 10680 KB Output is correct
51 Correct 4024 ms 10548 KB Output is correct
52 Correct 7555 ms 10244 KB Output is correct
53 Correct 7348 ms 10444 KB Output is correct
54 Correct 4703 ms 10540 KB Output is correct
55 Correct 4896 ms 10220 KB Output is correct
56 Correct 4958 ms 10764 KB Output is correct
57 Correct 4887 ms 10608 KB Output is correct
58 Correct 2364 ms 10248 KB Output is correct
59 Correct 2432 ms 10296 KB Output is correct
60 Correct 3791 ms 10444 KB Output is correct
61 Correct 4306 ms 10304 KB Output is correct
62 Correct 4295 ms 10556 KB Output is correct
63 Correct 4296 ms 10480 KB Output is correct
64 Correct 2303 ms 7300 KB Output is correct
65 Correct 3761 ms 9156 KB Output is correct
66 Correct 3910 ms 9424 KB Output is correct
67 Correct 4348 ms 10528 KB Output is correct
68 Correct 4732 ms 10348 KB Output is correct
69 Correct 4723 ms 10696 KB Output is correct
70 Correct 4703 ms 10628 KB Output is correct