Submission #568878

# Submission time Handle Problem Language Result Execution time Memory
568878 2022-05-26T09:58:21 Z nonsensenonsense1 Fish 2 (JOI22_fish2) C++17
13 / 100
4000 ms 4360 KB
#include <cstdio>
#include <utility>
#include <algorithm>

const int N = 100005;
int n, q, a[N], le[N], ri[N], cnt[N];
std::pair<int, int> b[N];
bool u[N];
long long sum[N];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) scanf("%d", a + i);
	scanf("%d", &q);
	while (q--) {
		int t;
		scanf("%d", &t);
		if (t == 1) {
			int x, y;
			scanf("%d%d", &x, &y);
			a[x - 1] = y;
		} else {
			int l, r;
			scanf("%d%d", &l, &r);
			--l;
			int len = r - l;
			for (int i = 0; i < len; ++i) {
				b[i] = std::make_pair(a[l + i], i);
				sum[i + 1] = sum[i] + a[l + i];
				le[i] = ri[i] = i;
				cnt[i] = 0;
				u[i] = 0;
			}
			std::sort(b, b + len);
			for (int i = 0; i < len; ++i) {
				int id = b[i].second;
				u[id] = 1;
				int ll = id && u[id - 1] ? le[id - 1] : id, rr = id + 1 < len && u[id + 1] ? ri[id + 1] : id, curcnt = 1;
				if (sum[rr + 1] - sum[id + 1] >= sum[id + 1] - sum[id]) curcnt += cnt[id + 1];
				if (sum[id] - sum[ll] >= sum[id + 1] - sum[id]) curcnt += cnt[id - 1];
				ri[ll] = rr;
				le[rr] = ll;
				cnt[ll] = cnt[rr] = curcnt;
			}
			printf("%d\n", cnt[0]);
		}
	}
	return 0;
}

Compilation message

fish2.cpp: In function 'int main()':
fish2.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
fish2.cpp:13:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  for (int i = 0; i < n; ++i) scanf("%d", a + i);
      |                              ~~~~~^~~~~~~~~~~~~
fish2.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
fish2.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d", &t);
      |   ~~~~~^~~~~~~~~~
fish2.cpp:20:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |    scanf("%d%d", &x, &y);
      |    ~~~~~^~~~~~~~~~~~~~~~
fish2.cpp:24:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |    scanf("%d%d", &l, &r);
      |    ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 2 ms 300 KB Output is correct
8 Correct 5 ms 300 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 4 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 6 ms 348 KB Output is correct
19 Correct 3 ms 300 KB Output is correct
20 Correct 14 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 27 ms 4036 KB Output is correct
3 Correct 24 ms 3796 KB Output is correct
4 Correct 27 ms 4016 KB Output is correct
5 Correct 22 ms 3808 KB Output is correct
6 Correct 25 ms 4172 KB Output is correct
7 Correct 22 ms 3716 KB Output is correct
8 Correct 26 ms 4272 KB Output is correct
9 Correct 21 ms 3712 KB Output is correct
10 Correct 25 ms 4072 KB Output is correct
11 Correct 19 ms 3796 KB Output is correct
12 Correct 22 ms 3796 KB Output is correct
13 Correct 21 ms 3668 KB Output is correct
14 Correct 26 ms 4024 KB Output is correct
15 Correct 26 ms 4036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 2 ms 300 KB Output is correct
8 Correct 5 ms 300 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 4 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 6 ms 348 KB Output is correct
19 Correct 3 ms 300 KB Output is correct
20 Correct 14 ms 300 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 27 ms 4036 KB Output is correct
23 Correct 24 ms 3796 KB Output is correct
24 Correct 27 ms 4016 KB Output is correct
25 Correct 22 ms 3808 KB Output is correct
26 Correct 25 ms 4172 KB Output is correct
27 Correct 22 ms 3716 KB Output is correct
28 Correct 26 ms 4272 KB Output is correct
29 Correct 21 ms 3712 KB Output is correct
30 Correct 25 ms 4072 KB Output is correct
31 Correct 19 ms 3796 KB Output is correct
32 Correct 22 ms 3796 KB Output is correct
33 Correct 21 ms 3668 KB Output is correct
34 Correct 26 ms 4024 KB Output is correct
35 Correct 26 ms 4036 KB Output is correct
36 Correct 1606 ms 4024 KB Output is correct
37 Correct 2329 ms 3672 KB Output is correct
38 Correct 2593 ms 3732 KB Output is correct
39 Correct 628 ms 3804 KB Output is correct
40 Correct 2911 ms 3648 KB Output is correct
41 Correct 2142 ms 4232 KB Output is correct
42 Correct 2717 ms 4360 KB Output is correct
43 Correct 2391 ms 3644 KB Output is correct
44 Correct 2850 ms 3576 KB Output is correct
45 Correct 1793 ms 4040 KB Output is correct
46 Correct 2248 ms 4048 KB Output is correct
47 Correct 2787 ms 3760 KB Output is correct
48 Correct 891 ms 3608 KB Output is correct
49 Correct 3072 ms 3720 KB Output is correct
50 Correct 1696 ms 4028 KB Output is correct
51 Execution timed out 4038 ms 4088 KB Time limit exceeded
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 27 ms 4036 KB Output is correct
3 Correct 24 ms 3796 KB Output is correct
4 Correct 27 ms 4016 KB Output is correct
5 Correct 22 ms 3808 KB Output is correct
6 Correct 25 ms 4172 KB Output is correct
7 Correct 22 ms 3716 KB Output is correct
8 Correct 26 ms 4272 KB Output is correct
9 Correct 21 ms 3712 KB Output is correct
10 Correct 25 ms 4072 KB Output is correct
11 Correct 19 ms 3796 KB Output is correct
12 Correct 22 ms 3796 KB Output is correct
13 Correct 21 ms 3668 KB Output is correct
14 Correct 26 ms 4024 KB Output is correct
15 Correct 26 ms 4036 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 4017 ms 3860 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 27 ms 4036 KB Output is correct
3 Correct 24 ms 3796 KB Output is correct
4 Correct 27 ms 4016 KB Output is correct
5 Correct 22 ms 3808 KB Output is correct
6 Correct 25 ms 4172 KB Output is correct
7 Correct 22 ms 3716 KB Output is correct
8 Correct 26 ms 4272 KB Output is correct
9 Correct 21 ms 3712 KB Output is correct
10 Correct 25 ms 4072 KB Output is correct
11 Correct 19 ms 3796 KB Output is correct
12 Correct 22 ms 3796 KB Output is correct
13 Correct 21 ms 3668 KB Output is correct
14 Correct 26 ms 4024 KB Output is correct
15 Correct 26 ms 4036 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Execution timed out 4069 ms 4040 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 2 ms 300 KB Output is correct
8 Correct 5 ms 300 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 4 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 6 ms 348 KB Output is correct
19 Correct 3 ms 300 KB Output is correct
20 Correct 14 ms 300 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 27 ms 4036 KB Output is correct
23 Correct 24 ms 3796 KB Output is correct
24 Correct 27 ms 4016 KB Output is correct
25 Correct 22 ms 3808 KB Output is correct
26 Correct 25 ms 4172 KB Output is correct
27 Correct 22 ms 3716 KB Output is correct
28 Correct 26 ms 4272 KB Output is correct
29 Correct 21 ms 3712 KB Output is correct
30 Correct 25 ms 4072 KB Output is correct
31 Correct 19 ms 3796 KB Output is correct
32 Correct 22 ms 3796 KB Output is correct
33 Correct 21 ms 3668 KB Output is correct
34 Correct 26 ms 4024 KB Output is correct
35 Correct 26 ms 4036 KB Output is correct
36 Correct 1606 ms 4024 KB Output is correct
37 Correct 2329 ms 3672 KB Output is correct
38 Correct 2593 ms 3732 KB Output is correct
39 Correct 628 ms 3804 KB Output is correct
40 Correct 2911 ms 3648 KB Output is correct
41 Correct 2142 ms 4232 KB Output is correct
42 Correct 2717 ms 4360 KB Output is correct
43 Correct 2391 ms 3644 KB Output is correct
44 Correct 2850 ms 3576 KB Output is correct
45 Correct 1793 ms 4040 KB Output is correct
46 Correct 2248 ms 4048 KB Output is correct
47 Correct 2787 ms 3760 KB Output is correct
48 Correct 891 ms 3608 KB Output is correct
49 Correct 3072 ms 3720 KB Output is correct
50 Correct 1696 ms 4028 KB Output is correct
51 Execution timed out 4038 ms 4088 KB Time limit exceeded
52 Halted 0 ms 0 KB -