답안 #421928

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421928 2021-06-09T13:53:30 Z pavement 푸드 코트 (JOI21_foodcourt) C++17
0 / 100
687 ms 90944 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) root2->upd(A, tmp - (sz - B), curq);
		}
	}
	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() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 25904 KB Output is correct
2 Correct 106 ms 26256 KB Output is correct
3 Incorrect 107 ms 25984 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 687 ms 90944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 136 ms 26196 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -