답안 #1083177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083177 2024-09-02T17:15:18 Z kes0716 Sushi (JOI16_sushi) C++17
100 / 100
8003 ms 56192 KB
#include <bits/stdc++.h>
#define TEST2
#define RAND2
using namespace std;
const int MAXN = 401557, buc = 1500, BUCN = MAXN/buc;
int n, a[MAXN];
priority_queue<int, vector<int>, greater<int> > lazy[BUCN];
multiset<int> st[BUCN];	//i-th bucket: [i*buc, (i+1)*buc)
void dolazy(int v){
	int li = v*buc, ri = min((v+1)*buc, n) - 1, k;
	#ifdef TEST
	printf("v=%d lazy.size=%d\n", v, lazy[v].size());
	#endif
	for(k=li; k<=ri; k++){
		lazy[v].push(a[k]);
		a[k] = lazy[v].top();
		lazy[v].pop();
	}
	while(!lazy[v].empty())
		lazy[v].pop();
}
int go(int v, int l, int r, int val){
	//printf("v=%d l=%d r=%d\n", v, l, r);
	int now = val;
	int k;
	for(k=l; k<=r; k++){
		#ifdef TEST
		printf("k=%d a[k]=%d\n", k, a[k]);
		#endif
		//printf("k=%d false=%d\n", k, st[v].find(a[k]) == st[v].end());
		if(a[k] > now){
			st[v].erase(st[v].find(a[k]));
			st[v].insert(now);
			swap(a[k], now);
		}
	}
	return now;
}
int main(){
	int q, i, l, r, val;
	scanf("%d %d", &n, &q);
	int m = (n+buc-1)/buc;
	srand(time(NULL));
	for(i=0; i<n; i++){
		#ifdef RAND
		a[i] = rand() % 50;
		printf("%d ", a[i]);
		#endif
		#ifndef RAND
		scanf("%d", &a[i]);
		#endif
		st[i/buc].insert(a[i]);
	}
	//printf("\n");
	while(q--){
		#ifndef RAND
		scanf("%d %d %d", &l, &r, &val);
		#endif
		#ifdef RAND
		l = rand() % n + 1;
		r = rand() % n + 1;
		val = rand() % 40;
		printf("%d %d %d\n", l, r, val);
		#endif
		l--;
		r--;
		int lb = l/buc, rb = r/buc;
		if(l > r){
			rb += m;
		}
		if(lb == rb){
			dolazy(lb);
			printf("%d\n", go(lb, l, r, val));
			continue;
		}
		dolazy(lb);
		val = go(lb, l, min((lb+1)*buc, n) - 1, val);
		//printf("lb=%d rb=%d\n", lb, rb);
		for(int t=lb+1; t<rb; t++){
			i = t%m;
			lazy[i].push(val);
			st[i].insert(val);
			val = *(--st[i].end());
			st[i].erase(--st[i].end());
		}
		dolazy(rb%m);
		printf("%d\n", go(rb%m, rb%m*buc, r, val));
		#ifdef TEST
		for(i=0; i<m; i++){
			printf("bucket %d: ", i);
			for(int v: st[i])
				printf("%d ", v);
			printf("\n");
		}
		#endif
	}
	return 0;
}

Compilation message

sushi.cpp: In function 'int main()':
sushi.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  scanf("%d %d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~
sushi.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
sushi.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%d %d %d", &l, &r, &val);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 600 KB Output is correct
2 Correct 16 ms 604 KB Output is correct
3 Correct 17 ms 604 KB Output is correct
4 Correct 19 ms 604 KB Output is correct
5 Correct 15 ms 600 KB Output is correct
6 Correct 16 ms 604 KB Output is correct
7 Correct 15 ms 348 KB Output is correct
8 Correct 14 ms 348 KB Output is correct
9 Correct 17 ms 632 KB Output is correct
10 Correct 16 ms 604 KB Output is correct
11 Correct 68 ms 624 KB Output is correct
12 Correct 66 ms 604 KB Output is correct
13 Correct 46 ms 608 KB Output is correct
14 Correct 23 ms 600 KB Output is correct
15 Correct 24 ms 604 KB Output is correct
16 Correct 7 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3578 ms 55824 KB Output is correct
2 Correct 3577 ms 54416 KB Output is correct
3 Correct 2481 ms 52304 KB Output is correct
4 Correct 3596 ms 56148 KB Output is correct
5 Correct 7992 ms 55996 KB Output is correct
6 Correct 6935 ms 55932 KB Output is correct
7 Correct 6788 ms 56012 KB Output is correct
8 Correct 7007 ms 55856 KB Output is correct
9 Correct 2717 ms 52516 KB Output is correct
10 Correct 4970 ms 54532 KB Output is correct
11 Correct 2696 ms 52556 KB Output is correct
12 Correct 5058 ms 54728 KB Output is correct
13 Correct 3558 ms 56192 KB Output is correct
14 Correct 3599 ms 54568 KB Output is correct
15 Correct 2446 ms 52444 KB Output is correct
16 Correct 3671 ms 55792 KB Output is correct
17 Correct 8003 ms 55960 KB Output is correct
18 Correct 6713 ms 55868 KB Output is correct
19 Correct 6954 ms 56024 KB Output is correct
20 Correct 7183 ms 56024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 600 KB Output is correct
2 Correct 16 ms 604 KB Output is correct
3 Correct 17 ms 604 KB Output is correct
4 Correct 19 ms 604 KB Output is correct
5 Correct 15 ms 600 KB Output is correct
6 Correct 16 ms 604 KB Output is correct
7 Correct 15 ms 348 KB Output is correct
8 Correct 14 ms 348 KB Output is correct
9 Correct 17 ms 632 KB Output is correct
10 Correct 16 ms 604 KB Output is correct
11 Correct 68 ms 624 KB Output is correct
12 Correct 66 ms 604 KB Output is correct
13 Correct 46 ms 608 KB Output is correct
14 Correct 23 ms 600 KB Output is correct
15 Correct 24 ms 604 KB Output is correct
16 Correct 7 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 3578 ms 55824 KB Output is correct
24 Correct 3577 ms 54416 KB Output is correct
25 Correct 2481 ms 52304 KB Output is correct
26 Correct 3596 ms 56148 KB Output is correct
27 Correct 7992 ms 55996 KB Output is correct
28 Correct 6935 ms 55932 KB Output is correct
29 Correct 6788 ms 56012 KB Output is correct
30 Correct 7007 ms 55856 KB Output is correct
31 Correct 2717 ms 52516 KB Output is correct
32 Correct 4970 ms 54532 KB Output is correct
33 Correct 2696 ms 52556 KB Output is correct
34 Correct 5058 ms 54728 KB Output is correct
35 Correct 3558 ms 56192 KB Output is correct
36 Correct 3599 ms 54568 KB Output is correct
37 Correct 2446 ms 52444 KB Output is correct
38 Correct 3671 ms 55792 KB Output is correct
39 Correct 8003 ms 55960 KB Output is correct
40 Correct 6713 ms 55868 KB Output is correct
41 Correct 6954 ms 56024 KB Output is correct
42 Correct 7183 ms 56024 KB Output is correct
43 Correct 1978 ms 25948 KB Output is correct
44 Correct 1959 ms 25904 KB Output is correct
45 Correct 2525 ms 22740 KB Output is correct
46 Correct 1971 ms 26192 KB Output is correct
47 Correct 1997 ms 26192 KB Output is correct
48 Correct 5674 ms 26012 KB Output is correct
49 Correct 5118 ms 26132 KB Output is correct
50 Correct 5133 ms 26080 KB Output is correct
51 Correct 5144 ms 26028 KB Output is correct
52 Correct 2386 ms 27732 KB Output is correct
53 Correct 2309 ms 27540 KB Output is correct
54 Correct 5462 ms 27732 KB Output is correct
55 Correct 5028 ms 27624 KB Output is correct
56 Correct 5081 ms 27732 KB Output is correct
57 Correct 5127 ms 27752 KB Output is correct
58 Correct 7720 ms 26472 KB Output is correct
59 Correct 6472 ms 26752 KB Output is correct
60 Correct 7518 ms 56148 KB Output is correct
61 Correct 6175 ms 56000 KB Output is correct
62 Correct 6282 ms 56056 KB Output is correct
63 Correct 6524 ms 56000 KB Output is correct
64 Correct 2332 ms 22660 KB Output is correct
65 Correct 2083 ms 39656 KB Output is correct
66 Correct 2051 ms 39692 KB Output is correct
67 Correct 4791 ms 50520 KB Output is correct
68 Correct 3619 ms 50600 KB Output is correct
69 Correct 3585 ms 50508 KB Output is correct
70 Correct 3668 ms 50468 KB Output is correct