Submission #1042200

# Submission time Handle Problem Language Result Execution time Memory
1042200 2024-08-02T15:58:51 Z flappybird Sushi (JOI16_sushi) C++17
5 / 100
1609 ms 262144 KB
//#define LOCAL
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 1010101
#define MAXQ 101010
#define INF 1'000'000'100
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 1000000007
#define TC 1
#ifdef LOCAL
#define DEBUG(a) cout<<a
#else
#define DEBUG(...) 1234
#endif
#define B 2
int A[MAX];
multiset<int> all[MAX];
priority_queue<int, vector<int>, greater<int>> upd[MAX];
int N, Q;
void prop(int id) {
	all[id].clear();
	int i;
	for (i = id * B; i < min(N, (id + 1) * B); i++) {
		upd[id].emplace(A[i]);
		A[i] = upd[id].top();
		upd[id].pop();
		all[id].emplace(A[i]);
	}
	while (upd[id].size()) upd[id].pop();
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> N >> Q;
	int i;
	for (i = 0; i < N; i++) cin >> A[i];
	for (i = 0; i < N; i++) all[i / B].insert(A[i]);
	auto f = [&](int l, int r, int x) {
		int i;
		i = l;
		while (i <= r) {
			int b = i / B;
			if ((i % B == 0) && i + B - 1 <= r) {
				//DEBUG("ii" << i << ln);
				upd[b].push(x);
				all[b].insert(x);
				x = *all[b].rbegin();
				all[b].erase(all[b].find(x));
				i += B;
				//DEBUG('x' << x << bb);
			}
			else {
				if (upd[b].size()) prop(b);
				//DEBUG('i' << i << bb << A[i] << bb << x << ln);
				if (A[i] > x) {
					for (auto x : all[b]) DEBUG('x' << x << bb);
					//DEBUG("fuck" << ln);
					for (int i = B * b; i < B * (b + 1); i++) DEBUG(A[i] << bb);
					//DEBUG(ln);
					//DEBUG("asdf" << x << bb << A[i]);
					all[b].insert(x);
					all[b].erase(all[b].find(A[i]));
					swap(A[i], x);
				}
				i++;
				//DEBUG('y' << x << bb);
			}
		}
		return x;
	};
	while (Q--) {
		int l, r, x;
		cin >> l >> r >> x;
		l--;
		r--;
		if (l > r) {
			x = f(l, N - 1, x);
			x = f(0, r, x);
		}
		else x = f(l, r, x);
		cout << x << ln;
	}
}

Compilation message

sushi.cpp: In lambda function:
sushi.cpp:23:20: warning: statement has no effect [-Wunused-value]
   23 | #define DEBUG(...) 1234
      |                    ^~~~
sushi.cpp:65:28: note: in expansion of macro 'DEBUG'
   65 |      for (auto x : all[b]) DEBUG('x' << x << bb);
      |                            ^~~~~
sushi.cpp:65:16: warning: unused variable 'x' [-Wunused-variable]
   65 |      for (auto x : all[b]) DEBUG('x' << x << bb);
      |                ^
sushi.cpp:23:20: warning: statement has no effect [-Wunused-value]
   23 | #define DEBUG(...) 1234
      |                    ^~~~
sushi.cpp:67:48: note: in expansion of macro 'DEBUG'
   67 |      for (int i = B * b; i < B * (b + 1); i++) DEBUG(A[i] << bb);
      |                                                ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 86 ms 84876 KB Output is correct
2 Correct 89 ms 84640 KB Output is correct
3 Correct 88 ms 84820 KB Output is correct
4 Correct 84 ms 84660 KB Output is correct
5 Correct 83 ms 84700 KB Output is correct
6 Correct 87 ms 85072 KB Output is correct
7 Correct 58 ms 84820 KB Output is correct
8 Correct 58 ms 84820 KB Output is correct
9 Correct 83 ms 84820 KB Output is correct
10 Correct 84 ms 84720 KB Output is correct
11 Correct 86 ms 84564 KB Output is correct
12 Correct 92 ms 84564 KB Output is correct
13 Correct 92 ms 85072 KB Output is correct
14 Correct 141 ms 88768 KB Output is correct
15 Correct 151 ms 88144 KB Output is correct
16 Correct 18 ms 80728 KB Output is correct
17 Correct 15 ms 80664 KB Output is correct
18 Correct 17 ms 80596 KB Output is correct
19 Correct 15 ms 80664 KB Output is correct
20 Correct 17 ms 80472 KB Output is correct
21 Correct 16 ms 80636 KB Output is correct
22 Correct 16 ms 80660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1609 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 86 ms 84876 KB Output is correct
2 Correct 89 ms 84640 KB Output is correct
3 Correct 88 ms 84820 KB Output is correct
4 Correct 84 ms 84660 KB Output is correct
5 Correct 83 ms 84700 KB Output is correct
6 Correct 87 ms 85072 KB Output is correct
7 Correct 58 ms 84820 KB Output is correct
8 Correct 58 ms 84820 KB Output is correct
9 Correct 83 ms 84820 KB Output is correct
10 Correct 84 ms 84720 KB Output is correct
11 Correct 86 ms 84564 KB Output is correct
12 Correct 92 ms 84564 KB Output is correct
13 Correct 92 ms 85072 KB Output is correct
14 Correct 141 ms 88768 KB Output is correct
15 Correct 151 ms 88144 KB Output is correct
16 Correct 18 ms 80728 KB Output is correct
17 Correct 15 ms 80664 KB Output is correct
18 Correct 17 ms 80596 KB Output is correct
19 Correct 15 ms 80664 KB Output is correct
20 Correct 17 ms 80472 KB Output is correct
21 Correct 16 ms 80636 KB Output is correct
22 Correct 16 ms 80660 KB Output is correct
23 Runtime error 1609 ms 262144 KB Execution killed with signal 9
24 Halted 0 ms 0 KB -