Submission #199441

# Submission time Handle Problem Language Result Execution time Memory
199441 2020-02-01T12:42:35 Z dennisstar Sushi (JOI16_sushi) C++17
0 / 100
175 ms 51680 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define all(V) (V).begin(), (V).end()
using namespace std;
typedef vector<int> vim;
typedef pair<int, int> pii;

const int sz = 500;

int N, M, Q, X[400010], chk[400010];
vector<pii> B[810]; multiset<int> S[810];

void myassert(bool im) { if (!im) { puts("no"); exit(0); } }

inline void make(int t) {
	B[t].clear(); S[t].clear();
	int ub=min((t+1)*sz, N);
	for (int i=t*sz; i<ub; i++) B[t].eb(X[i], i), chk[i]=1;
	sort(all(B[t])); for (auto &i:B[t]) S[t].em(i.fi);
}

inline void upd(int t) {
	auto it=S[t].begin();
	for (auto &i:B[t]) { i.fi=(*it); X[i.se]=i.fi; ++it; }
}

inline int solve(int t, int p) {
	S[t].em(p);
	p=(*prev(S[t].end())); S[t].erase(prev(S[t].end()));
	return p;
}

int main() {
	scanf("%d %d", &N, &Q); M=(N+sz-1)/sz;
	for (int i=0; i<N; i++) scanf("%d", &X[i]);
	for (int i=0; i<M; i++) make(i);
	for (int i=0; i<N; i++) myassert(chk[i]==1);
	while (Q--) {
		int s, t, p;
		int sb=s/sz, tb=t/sz;
		scanf("%d %d %d", &s, &t, &p); s--; t--;
		upd(sb); upd(tb);
		if (s<=t&&sb==tb) {
			for (int i=s; i<=t; i++) if (X[i]>p) swap(X[i], p);
			make(sb);
			printf("%d\n", p);
			continue;
		}
		int ub=min((sb+1)*sz, N);
		for (int i=s; i<ub; i++) if (X[i]>p) swap(X[i], p);
		for (int i=sb+1; i<(s<t?tb:M); i++) p=solve(i, p);
		if (s>t) for (int i=0; i<tb; i++) p=solve(i, p);
		for (int i=tb*sz; i<=t; i++) if (X[i]>p) swap(X[i], p);
		make(sb); make(tb);
		printf("%d\n", p);
	}
	return 0;
}

Compilation message

sushi.cpp: In function 'int main()':
sushi.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &Q); M=(N+sz-1)/sz;
  ~~~~~^~~~~~~~~~~~~~~~~
sushi.cpp:38:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i=0; i<N; i++) scanf("%d", &X[i]);
                          ~~~~~^~~~~~~~~~~~~
sushi.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &s, &t, &p); s--; t--;
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 175 ms 51680 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -