Submission #421930

# Submission time Handle Problem Language Result Execution time Memory
421930 2021-06-09T13:54:20 Z pavement Food Court (JOI21_foodcourt) C++17
21 / 100
512 ms 101860 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<iii, null_type, greater<iii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void read(int &v) {
	v = 0;
	char ch = getchar_unlocked();
	for (; ch < '0' || ch > '9'; ch = getchar_unlocked());
	for (; '0' <= ch && ch <= '9'; ch = getchar_unlocked())
		v = (v << 3ll) + (v << 1ll) + (ch & 15ll);
}

int N, M, Q, T, L, R, C, K, A, curq, q1, B, out[100005], ft[250005];
iiii vq1[250005];

struct node {
	node *left, *right;
	int S, E, val, pv, pmx;
	bool hasmx;
	node(int _s, int _e) : S(_s), E(_e),val(0), pv(0), pmx(-1e18), hasmx(0) {
		if (S == E) return;
		int M = (S + E) >> 1;
		left = new node(S, M);
		right = new node(M + 1, E);
	}
	void add_prop(bool t, int x) {
		if (t == 0) {
			pv += x;
			if (hasmx) pmx += x;
		} else {
			pmx = max(pmx, x);
			hasmx = 1;
		}
	}
	void prop() {
		if (S == E) return;
		left->val += pv;
		right->val += pv;
		left->add_prop(0, pv);
		right->add_prop(0, pv);
		pv = 0;
		if (hasmx) {
			left->val = max(left->val, pmx);
			right->val = max(right->val, pmx);
			left->add_prop(1, pmx);
			right->add_prop(1, pmx);
			pmx = -1e18;
		} else assert(pmx == -1e18);
		hasmx = 0;
	}
	void add(int l, int r, int v) {
		if (l > E || r < S) return;
		if (l <= S && E <= r) {
			add_prop(0, v);
			val += v;
			return;
		}
		prop();
		left->add(l, r, v);
		right->add(l, r, v);
	}
	int qry(int p) {
		if (S == E) return val;
		int M = (S + E) >> 1;
		prop();
		if (p <= M) return left->qry(p);
		else return right->qry(p);
	}
} *root;

inline int ls(int x) { return x & -x; }

void upd(int l, int r, int v) {
	for (; l <= N; l += ls(l)) ft[l] += v;
	for (r++; r <= N; r += ls(r)) ft[r] -= v;
}

int qry(int p) {
	int r = 0;
	for (; p; p -= ls(p)) r += ft[p];
	return r;
}

struct node2 {
	node2 *left, *right;
	int S, E, pos, pv;
	vector<ii> val;
	iii mv;
	node2(int _s, int _e) : S(_s), E(_e), pos(0), pv(0) {
		mv = mt(1e18, -1, -1);
		if (S == E) return;
		int M = (S + E) >> 1;
		left = new node2(S, M);
		right = new node2(M + 1, E);
	}
	void prop() {
		if (S == E || !pv) return;
		g0(left->mv) += pv;
		left->pv += pv;
		g0(right->mv) += pv;
		right->pv += pv;
		pv = 0;
	}
	void upd(int p, int a, int b) {
		if (S == E) {
			val.eb(a, b);
			return;
		}
		int M = (S + E) >> 1;
		prop();
		if (p <= M) left->upd(p, a, b);
		else right->upd(p, a, b);
		mv = min(left->mv, right->mv);
	}
	void add(int l, int r, int v) {
		if (l > E || r < S) return;
		if (l <= S && E <= r) {
			g0(mv) += v;
			pv += v;
			return;
		}
		prop();
		left->add(l, r, v);
		right->add(l, r, v);
		mv = min(left->mv, right->mv);
	}
	void sortall() {
		if (S == E) {
			sort(val.begin(), val.end());
			if (!val.empty()) mv = mt(val[0].first, S, val[0].second);
			return;
		}
		prop();
		left->sortall();
		right->sortall();
		mv = min(left->mv, right->mv);
	}
	void del(int p) {
		if (S == E) {
			assert(pos < val.size());
			pos++;
			if (pos < val.size()) mv = mt(val[pos].first, S, val[pos].second);
			else mv = mt(1e18, -1, -1);
			return;
		}
		int M = (S + E) >> 1;
		prop();
		if (p <= M) left->del(p);
		else right->del(p);
		mv = min(left->mv, right->mv);
	}
} *root2;

main() {
	read(N);
	read(M);
	read(Q);
	root = new node(1, N);
	root2 = new node2(1, N);
	for (int i = 1; i <= Q; i++) {
		read(T);
		if (T == 1) {
			read(L);
			read(R);
			read(C);
			read(K);
			q1++;
			vq1[q1] = mt(L, R, C, K);
			root->add(L, R, K);
			upd(L, R, K);
		} else if (T == 2) {
			read(L);
			read(R);
			read(K);
			root->add(L, R, -K);
			root->val = max(0ll, root->val);
			root->add_prop(1, 0);
		} else {
			read(A);
			read(B);
			curq++;
			int sz = root->qry(A), tmp = qry(A);
			if (sz >= B) puts("1");
			else puts("0");
		}
	}
	return 0;
	root2->sortall();
	for (int i = 1; i <= q1; i++) {
		tie(L, R, C, K) = vq1[i];
		root2->add(L, R, -K);
		while (g0(root2->mv) <= 0) {
			out[g2(root2->mv)] = C;
			root2->del(g1(root2->mv));
		}
	}
	for (int i = 1; i <= curq; i++) printf("%lld\n", out[i]);
}

Compilation message

In file included from /usr/include/c++/10/ext/pb_ds/detail/pat_trie_/pat_trie_.hpp:45,
                 from /usr/include/c++/10/ext/pb_ds/detail/container_base_dispatch.hpp:90,
                 from /usr/include/c++/10/ext/pb_ds/assoc_container.hpp:48,
                 from foodcourt.cpp:2:
foodcourt.cpp: In member function 'void node2::del(long long int)':
foodcourt.cpp:163:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  163 |    assert(pos < val.size());
      |           ~~~~^~~~~~~~~~~~
foodcourt.cpp:165:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  165 |    if (pos < val.size()) mv = mt(val[pos].first, S, val[pos].second);
      |        ~~~~^~~~~~~~~~~~
foodcourt.cpp: At global scope:
foodcourt.cpp:177:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  177 | main() {
      | ^~~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:205:27: warning: unused variable 'tmp' [-Wunused-variable]
  205 |    int sz = root->qry(A), tmp = qry(A);
      |                           ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 25844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 426 ms 88824 KB Output is correct
2 Correct 347 ms 76944 KB Output is correct
3 Correct 443 ms 99012 KB Output is correct
4 Correct 368 ms 98244 KB Output is correct
5 Correct 333 ms 75104 KB Output is correct
6 Correct 487 ms 100112 KB Output is correct
7 Correct 23 ms 3012 KB Output is correct
8 Correct 25 ms 3008 KB Output is correct
9 Correct 431 ms 100340 KB Output is correct
10 Correct 443 ms 100632 KB Output is correct
11 Correct 426 ms 99612 KB Output is correct
12 Correct 512 ms 99672 KB Output is correct
13 Correct 443 ms 99540 KB Output is correct
14 Correct 467 ms 99516 KB Output is correct
15 Correct 473 ms 99652 KB Output is correct
16 Correct 465 ms 99524 KB Output is correct
17 Correct 499 ms 99632 KB Output is correct
18 Correct 449 ms 99508 KB Output is correct
19 Correct 487 ms 99620 KB Output is correct
20 Correct 467 ms 99524 KB Output is correct
21 Correct 495 ms 99524 KB Output is correct
22 Correct 481 ms 99792 KB Output is correct
23 Correct 481 ms 99572 KB Output is correct
24 Correct 480 ms 99584 KB Output is correct
25 Correct 308 ms 75920 KB Output is correct
26 Correct 317 ms 97396 KB Output is correct
27 Correct 309 ms 101860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 25260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -