Submission #499316

# Submission time Handle Problem Language Result Execution time Memory
499316 2021-12-28T02:32:37 Z hollwo_pelw Food Court (JOI21_foodcourt) C++17
68 / 100
414 ms 61156 KB
/*
// is short or still long ???
hollwo_pelw's template(short)
// Note : -Dhollwo_pelw_local
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>

using namespace std;
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;

void FAST_IO(string filein = "", string fileout = "", string fileerr = ""){
	if (fopen(filein.c_str(), "r")){
		freopen(filein.c_str(), "r", stdin);
		freopen(fileout.c_str(), "w", stdout);
#ifdef hollwo_pelw_local
		freopen(fileerr.c_str(), "w", stderr);
#endif
	}
	cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
}

void Hollwo_Pelw();

signed main(){
#ifdef hollwo_pelw_local
	FAST_IO("input.inp", "output.out", "error.err");
	auto start = chrono::steady_clock::now();
#else
	FAST_IO("hollwo_pelw.inp", "hollwo_pelw.out");
#endif
	int testcases = 1;
	// cin >> testcases;
	for (int test = 1; test <= testcases; test++){
		// cout << "Case #" << test << ": ";
		Hollwo_Pelw();
	}
#ifdef hollwo_pelw_local
	auto end = chrono::steady_clock::now();
	cout << "\nExcution time : " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
	return 0;
}

const int N = 2.5e5 + 5;

#define int long long

vector<pair<int, int>> supd[N], fupd[N], qry[N];
int n, m, q, color[N], res[N];

// segment tree
struct node_t {
	int mx, sum;
	node_t (int _mx = 0, int _sum = 0)
		: mx(_mx), sum(_sum) {}
	friend node_t merge(const node_t &a, const node_t &b) {
		return node_t(max(a.mx + b.sum, b.mx), a.sum + b.sum);
	}
} st[N << 2];

#define tm (tl + tr >> 1)
#define left id << 1, tl, tm
#define right id << 1 | 1, tm + 1, tr

void update_st(int p, int v, int id = 1, int tl = 1, int tr = q) {
	if (tl == tr)
		return st[id] = node_t(max(0ll, v), v), (void) 0;
	(p > tm ? update_st(p, v, right)
			: update_st(p, v, left));
	st[id] = merge(st[id << 1], st[id << 1 | 1]);
}

node_t query_st(int l, int r, int id = 1, int tl = 1, int tr = q) {
	if (l > tr || tl > r) return node_t();
	if (l <= tl && tr <= r) return st[id];
	return merge(query_st(l, r, left), query_st(l, r, right));
}

// fenwick tree
int bit[N];
inline void update_fw(int p, int v) {
	for (; p < N; p += p & -p)
		bit[p] += v;
}

inline int query_fw(int p) {
	int r = 0;
	for (; p > 0; p -= p & -p)
		r += bit[p];
	return r;
}

inline int find_kth(int val) {
	int p = 0;
	for (int i = 17; ~i; i--) {
		if (bit[p + (1 << i)] < val) {
			p += 1 << i;
			val -= bit[p];
		}
	}
	return p + 1;
}

void Hollwo_Pelw() {
	cin >> n >> m >> q;

	for (int i = 1, t, l, r, k; i <= q; i++) {
		cin >> t;
		if (t == 1) {
			cin >> l >> r >> color[i] >> k;
			supd[l    ].emplace_back(i, +k);
			supd[r + 1].emplace_back(i,  0);
			fupd[l    ].emplace_back(i, +k);
			fupd[r + 1].emplace_back(i, -k);
		}
		if (t == 2) {
			cin >> l >> r >> k;
			supd[l    ].emplace_back(i, -k);
			supd[r + 1].emplace_back(i,  0);
		}
		if (t == 3) {
			cin >> l >> k;
			qry[l].emplace_back(i, k);
		}
	}

	memset(res, -1, sizeof res);

	for (int i = 1; i <= n; i++) {
		for (auto [p, v] : supd[i])
			update_st(p, v);
		for (auto [p, v] : fupd[i])
			update_fw(p, v);
		for (auto [p, v] : qry[i]) {
			auto cur_state = query_st(1, p);

			if (v > cur_state.mx) {
				res[p] = 0;
			} else {
				v = query_fw(p) - (cur_state.mx - v);
				res[p] = color[find_kth(v)];
			}
		}
	}

	for (int i = 1; i <= q; i++)
		if (~res[i]) cout << res[i] << '\n';
}

Compilation message

foodcourt.cpp: In function 'void update_st(long long int, long long int, long long int, long long int, long long int)':
foodcourt.cpp:66:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
foodcourt.cpp:73:7: note: in expansion of macro 'tm'
   73 |  (p > tm ? update_st(p, v, right)
      |       ^~
foodcourt.cpp:66:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
foodcourt.cpp:68:28: note: in expansion of macro 'tm'
   68 | #define right id << 1 | 1, tm + 1, tr
      |                            ^~
foodcourt.cpp:73:28: note: in expansion of macro 'right'
   73 |  (p > tm ? update_st(p, v, right)
      |                            ^~~~~
foodcourt.cpp:66:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
foodcourt.cpp:67:27: note: in expansion of macro 'tm'
   67 | #define left id << 1, tl, tm
      |                           ^~
foodcourt.cpp:74:22: note: in expansion of macro 'left'
   74 |    : update_st(p, v, left));
      |                      ^~~~
foodcourt.cpp: In function 'node_t query_st(long long int, long long int, long long int, long long int, long long int)':
foodcourt.cpp:66:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
foodcourt.cpp:67:27: note: in expansion of macro 'tm'
   67 | #define left id << 1, tl, tm
      |                           ^~
foodcourt.cpp:81:30: note: in expansion of macro 'left'
   81 |  return merge(query_st(l, r, left), query_st(l, r, right));
      |                              ^~~~
foodcourt.cpp:66:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 | #define tm (tl + tr >> 1)
      |             ~~~^~~~
foodcourt.cpp:68:28: note: in expansion of macro 'tm'
   68 | #define right id << 1 | 1, tm + 1, tr
      |                            ^~
foodcourt.cpp:81:52: note: in expansion of macro 'right'
   81 |  return merge(query_st(l, r, left), query_st(l, r, right));
      |                                                    ^~~~~
foodcourt.cpp: In function 'void FAST_IO(std::string, std::string, std::string)':
foodcourt.cpp:18:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   freopen(filein.c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   freopen(fileout.c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 35652 KB Output is correct
2 Correct 17 ms 35652 KB Output is correct
3 Correct 16 ms 35660 KB Output is correct
4 Correct 16 ms 35744 KB Output is correct
5 Correct 16 ms 35852 KB Output is correct
6 Correct 16 ms 35660 KB Output is correct
7 Correct 17 ms 35740 KB Output is correct
8 Correct 17 ms 35660 KB Output is correct
9 Correct 16 ms 35652 KB Output is correct
10 Correct 16 ms 35660 KB Output is correct
11 Correct 19 ms 35640 KB Output is correct
12 Correct 16 ms 35648 KB Output is correct
13 Correct 16 ms 35728 KB Output is correct
14 Correct 17 ms 35916 KB Output is correct
15 Correct 16 ms 35652 KB Output is correct
16 Correct 16 ms 35652 KB Output is correct
17 Correct 16 ms 35688 KB Output is correct
18 Correct 16 ms 35764 KB Output is correct
19 Correct 16 ms 35736 KB Output is correct
20 Correct 17 ms 35788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 35652 KB Output is correct
2 Correct 17 ms 35652 KB Output is correct
3 Correct 16 ms 35660 KB Output is correct
4 Correct 16 ms 35744 KB Output is correct
5 Correct 16 ms 35852 KB Output is correct
6 Correct 16 ms 35660 KB Output is correct
7 Correct 17 ms 35740 KB Output is correct
8 Correct 17 ms 35660 KB Output is correct
9 Correct 16 ms 35652 KB Output is correct
10 Correct 16 ms 35660 KB Output is correct
11 Correct 19 ms 35640 KB Output is correct
12 Correct 16 ms 35648 KB Output is correct
13 Correct 16 ms 35728 KB Output is correct
14 Correct 17 ms 35916 KB Output is correct
15 Correct 16 ms 35652 KB Output is correct
16 Correct 16 ms 35652 KB Output is correct
17 Correct 16 ms 35688 KB Output is correct
18 Correct 16 ms 35764 KB Output is correct
19 Correct 16 ms 35736 KB Output is correct
20 Correct 17 ms 35788 KB Output is correct
21 Correct 16 ms 35660 KB Output is correct
22 Correct 17 ms 35780 KB Output is correct
23 Correct 17 ms 35788 KB Output is correct
24 Correct 19 ms 35780 KB Output is correct
25 Correct 16 ms 35688 KB Output is correct
26 Correct 16 ms 35660 KB Output is correct
27 Correct 17 ms 35788 KB Output is correct
28 Correct 17 ms 35736 KB Output is correct
29 Correct 17 ms 35776 KB Output is correct
30 Correct 16 ms 35788 KB Output is correct
31 Correct 17 ms 35700 KB Output is correct
32 Correct 16 ms 35788 KB Output is correct
33 Correct 16 ms 35716 KB Output is correct
34 Correct 16 ms 35788 KB Output is correct
35 Correct 16 ms 35652 KB Output is correct
36 Correct 17 ms 35784 KB Output is correct
37 Correct 17 ms 35776 KB Output is correct
38 Correct 18 ms 35788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 41784 KB Output is correct
2 Correct 80 ms 42528 KB Output is correct
3 Correct 76 ms 41860 KB Output is correct
4 Correct 82 ms 41780 KB Output is correct
5 Correct 84 ms 42560 KB Output is correct
6 Correct 79 ms 42464 KB Output is correct
7 Correct 40 ms 39704 KB Output is correct
8 Correct 45 ms 40096 KB Output is correct
9 Correct 77 ms 41724 KB Output is correct
10 Correct 82 ms 42116 KB Output is correct
11 Correct 77 ms 41924 KB Output is correct
12 Correct 86 ms 42236 KB Output is correct
13 Correct 68 ms 41548 KB Output is correct
14 Correct 78 ms 42432 KB Output is correct
15 Correct 83 ms 43588 KB Output is correct
16 Correct 87 ms 43716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 365 ms 59068 KB Output is correct
2 Correct 283 ms 54596 KB Output is correct
3 Incorrect 414 ms 61156 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 35652 KB Output is correct
2 Correct 17 ms 35652 KB Output is correct
3 Correct 16 ms 35660 KB Output is correct
4 Correct 16 ms 35744 KB Output is correct
5 Correct 16 ms 35852 KB Output is correct
6 Correct 16 ms 35660 KB Output is correct
7 Correct 17 ms 35740 KB Output is correct
8 Correct 17 ms 35660 KB Output is correct
9 Correct 16 ms 35652 KB Output is correct
10 Correct 16 ms 35660 KB Output is correct
11 Correct 19 ms 35640 KB Output is correct
12 Correct 16 ms 35648 KB Output is correct
13 Correct 16 ms 35728 KB Output is correct
14 Correct 17 ms 35916 KB Output is correct
15 Correct 16 ms 35652 KB Output is correct
16 Correct 16 ms 35652 KB Output is correct
17 Correct 16 ms 35688 KB Output is correct
18 Correct 16 ms 35764 KB Output is correct
19 Correct 16 ms 35736 KB Output is correct
20 Correct 17 ms 35788 KB Output is correct
21 Correct 79 ms 41784 KB Output is correct
22 Correct 80 ms 42528 KB Output is correct
23 Correct 76 ms 41860 KB Output is correct
24 Correct 82 ms 41780 KB Output is correct
25 Correct 84 ms 42560 KB Output is correct
26 Correct 79 ms 42464 KB Output is correct
27 Correct 40 ms 39704 KB Output is correct
28 Correct 45 ms 40096 KB Output is correct
29 Correct 77 ms 41724 KB Output is correct
30 Correct 82 ms 42116 KB Output is correct
31 Correct 77 ms 41924 KB Output is correct
32 Correct 86 ms 42236 KB Output is correct
33 Correct 68 ms 41548 KB Output is correct
34 Correct 78 ms 42432 KB Output is correct
35 Correct 83 ms 43588 KB Output is correct
36 Correct 87 ms 43716 KB Output is correct
37 Correct 82 ms 41036 KB Output is correct
38 Correct 71 ms 41016 KB Output is correct
39 Correct 36 ms 39292 KB Output is correct
40 Correct 41 ms 40032 KB Output is correct
41 Correct 79 ms 41444 KB Output is correct
42 Correct 79 ms 41976 KB Output is correct
43 Correct 84 ms 41924 KB Output is correct
44 Correct 84 ms 41784 KB Output is correct
45 Correct 84 ms 41968 KB Output is correct
46 Correct 86 ms 42008 KB Output is correct
47 Correct 48 ms 40532 KB Output is correct
48 Correct 70 ms 41692 KB Output is correct
49 Correct 61 ms 40148 KB Output is correct
50 Correct 77 ms 41084 KB Output is correct
51 Correct 88 ms 42092 KB Output is correct
52 Correct 83 ms 42040 KB Output is correct
53 Correct 80 ms 41940 KB Output is correct
54 Correct 87 ms 43760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 41924 KB Output is correct
2 Correct 89 ms 42552 KB Output is correct
3 Correct 87 ms 42684 KB Output is correct
4 Correct 66 ms 40672 KB Output is correct
5 Correct 78 ms 41740 KB Output is correct
6 Correct 89 ms 42696 KB Output is correct
7 Correct 45 ms 40216 KB Output is correct
8 Correct 43 ms 39832 KB Output is correct
9 Correct 57 ms 41252 KB Output is correct
10 Correct 53 ms 40388 KB Output is correct
11 Correct 69 ms 41924 KB Output is correct
12 Correct 69 ms 42004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 35652 KB Output is correct
2 Correct 17 ms 35652 KB Output is correct
3 Correct 16 ms 35660 KB Output is correct
4 Correct 16 ms 35744 KB Output is correct
5 Correct 16 ms 35852 KB Output is correct
6 Correct 16 ms 35660 KB Output is correct
7 Correct 17 ms 35740 KB Output is correct
8 Correct 17 ms 35660 KB Output is correct
9 Correct 16 ms 35652 KB Output is correct
10 Correct 16 ms 35660 KB Output is correct
11 Correct 19 ms 35640 KB Output is correct
12 Correct 16 ms 35648 KB Output is correct
13 Correct 16 ms 35728 KB Output is correct
14 Correct 17 ms 35916 KB Output is correct
15 Correct 16 ms 35652 KB Output is correct
16 Correct 16 ms 35652 KB Output is correct
17 Correct 16 ms 35688 KB Output is correct
18 Correct 16 ms 35764 KB Output is correct
19 Correct 16 ms 35736 KB Output is correct
20 Correct 17 ms 35788 KB Output is correct
21 Correct 16 ms 35660 KB Output is correct
22 Correct 17 ms 35780 KB Output is correct
23 Correct 17 ms 35788 KB Output is correct
24 Correct 19 ms 35780 KB Output is correct
25 Correct 16 ms 35688 KB Output is correct
26 Correct 16 ms 35660 KB Output is correct
27 Correct 17 ms 35788 KB Output is correct
28 Correct 17 ms 35736 KB Output is correct
29 Correct 17 ms 35776 KB Output is correct
30 Correct 16 ms 35788 KB Output is correct
31 Correct 17 ms 35700 KB Output is correct
32 Correct 16 ms 35788 KB Output is correct
33 Correct 16 ms 35716 KB Output is correct
34 Correct 16 ms 35788 KB Output is correct
35 Correct 16 ms 35652 KB Output is correct
36 Correct 17 ms 35784 KB Output is correct
37 Correct 17 ms 35776 KB Output is correct
38 Correct 18 ms 35788 KB Output is correct
39 Correct 79 ms 41784 KB Output is correct
40 Correct 80 ms 42528 KB Output is correct
41 Correct 76 ms 41860 KB Output is correct
42 Correct 82 ms 41780 KB Output is correct
43 Correct 84 ms 42560 KB Output is correct
44 Correct 79 ms 42464 KB Output is correct
45 Correct 40 ms 39704 KB Output is correct
46 Correct 45 ms 40096 KB Output is correct
47 Correct 77 ms 41724 KB Output is correct
48 Correct 82 ms 42116 KB Output is correct
49 Correct 77 ms 41924 KB Output is correct
50 Correct 86 ms 42236 KB Output is correct
51 Correct 68 ms 41548 KB Output is correct
52 Correct 78 ms 42432 KB Output is correct
53 Correct 83 ms 43588 KB Output is correct
54 Correct 87 ms 43716 KB Output is correct
55 Correct 82 ms 41036 KB Output is correct
56 Correct 71 ms 41016 KB Output is correct
57 Correct 36 ms 39292 KB Output is correct
58 Correct 41 ms 40032 KB Output is correct
59 Correct 79 ms 41444 KB Output is correct
60 Correct 79 ms 41976 KB Output is correct
61 Correct 84 ms 41924 KB Output is correct
62 Correct 84 ms 41784 KB Output is correct
63 Correct 84 ms 41968 KB Output is correct
64 Correct 86 ms 42008 KB Output is correct
65 Correct 48 ms 40532 KB Output is correct
66 Correct 70 ms 41692 KB Output is correct
67 Correct 61 ms 40148 KB Output is correct
68 Correct 77 ms 41084 KB Output is correct
69 Correct 88 ms 42092 KB Output is correct
70 Correct 83 ms 42040 KB Output is correct
71 Correct 80 ms 41940 KB Output is correct
72 Correct 87 ms 43760 KB Output is correct
73 Correct 79 ms 41924 KB Output is correct
74 Correct 89 ms 42552 KB Output is correct
75 Correct 87 ms 42684 KB Output is correct
76 Correct 66 ms 40672 KB Output is correct
77 Correct 78 ms 41740 KB Output is correct
78 Correct 89 ms 42696 KB Output is correct
79 Correct 45 ms 40216 KB Output is correct
80 Correct 43 ms 39832 KB Output is correct
81 Correct 57 ms 41252 KB Output is correct
82 Correct 53 ms 40388 KB Output is correct
83 Correct 69 ms 41924 KB Output is correct
84 Correct 69 ms 42004 KB Output is correct
85 Correct 81 ms 41584 KB Output is correct
86 Correct 91 ms 42288 KB Output is correct
87 Correct 111 ms 42020 KB Output is correct
88 Correct 88 ms 43000 KB Output is correct
89 Correct 64 ms 39880 KB Output is correct
90 Correct 86 ms 42508 KB Output is correct
91 Correct 78 ms 41152 KB Output is correct
92 Correct 79 ms 40896 KB Output is correct
93 Correct 94 ms 42560 KB Output is correct
94 Correct 91 ms 42252 KB Output is correct
95 Correct 89 ms 42292 KB Output is correct
96 Correct 120 ms 42436 KB Output is correct
97 Correct 95 ms 42504 KB Output is correct
98 Correct 76 ms 41436 KB Output is correct
99 Correct 54 ms 40748 KB Output is correct
100 Correct 72 ms 40784 KB Output is correct
101 Correct 70 ms 42144 KB Output is correct
102 Correct 81 ms 43592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 35652 KB Output is correct
2 Correct 17 ms 35652 KB Output is correct
3 Correct 16 ms 35660 KB Output is correct
4 Correct 16 ms 35744 KB Output is correct
5 Correct 16 ms 35852 KB Output is correct
6 Correct 16 ms 35660 KB Output is correct
7 Correct 17 ms 35740 KB Output is correct
8 Correct 17 ms 35660 KB Output is correct
9 Correct 16 ms 35652 KB Output is correct
10 Correct 16 ms 35660 KB Output is correct
11 Correct 19 ms 35640 KB Output is correct
12 Correct 16 ms 35648 KB Output is correct
13 Correct 16 ms 35728 KB Output is correct
14 Correct 17 ms 35916 KB Output is correct
15 Correct 16 ms 35652 KB Output is correct
16 Correct 16 ms 35652 KB Output is correct
17 Correct 16 ms 35688 KB Output is correct
18 Correct 16 ms 35764 KB Output is correct
19 Correct 16 ms 35736 KB Output is correct
20 Correct 17 ms 35788 KB Output is correct
21 Correct 16 ms 35660 KB Output is correct
22 Correct 17 ms 35780 KB Output is correct
23 Correct 17 ms 35788 KB Output is correct
24 Correct 19 ms 35780 KB Output is correct
25 Correct 16 ms 35688 KB Output is correct
26 Correct 16 ms 35660 KB Output is correct
27 Correct 17 ms 35788 KB Output is correct
28 Correct 17 ms 35736 KB Output is correct
29 Correct 17 ms 35776 KB Output is correct
30 Correct 16 ms 35788 KB Output is correct
31 Correct 17 ms 35700 KB Output is correct
32 Correct 16 ms 35788 KB Output is correct
33 Correct 16 ms 35716 KB Output is correct
34 Correct 16 ms 35788 KB Output is correct
35 Correct 16 ms 35652 KB Output is correct
36 Correct 17 ms 35784 KB Output is correct
37 Correct 17 ms 35776 KB Output is correct
38 Correct 18 ms 35788 KB Output is correct
39 Correct 79 ms 41784 KB Output is correct
40 Correct 80 ms 42528 KB Output is correct
41 Correct 76 ms 41860 KB Output is correct
42 Correct 82 ms 41780 KB Output is correct
43 Correct 84 ms 42560 KB Output is correct
44 Correct 79 ms 42464 KB Output is correct
45 Correct 40 ms 39704 KB Output is correct
46 Correct 45 ms 40096 KB Output is correct
47 Correct 77 ms 41724 KB Output is correct
48 Correct 82 ms 42116 KB Output is correct
49 Correct 77 ms 41924 KB Output is correct
50 Correct 86 ms 42236 KB Output is correct
51 Correct 68 ms 41548 KB Output is correct
52 Correct 78 ms 42432 KB Output is correct
53 Correct 83 ms 43588 KB Output is correct
54 Correct 87 ms 43716 KB Output is correct
55 Correct 365 ms 59068 KB Output is correct
56 Correct 283 ms 54596 KB Output is correct
57 Incorrect 414 ms 61156 KB Output isn't correct
58 Halted 0 ms 0 KB -