Submission #338312

# Submission time Handle Problem Language Result Execution time Memory
338312 2020-12-23T01:36:04 Z Kevin_Zhang_TW Editor (BOI15_edi) C++17
0 / 100
3000 ms 9608 KB
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T>
bool chmax(T &val, T nv) {
	return val < nv ? (val = nv, true) : false;
}
template<class T>
bool chmin(T &val, T nv) {
	return nv < val ? (val = nv, true) : false;
}
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void debug(auto L, auto R) { while (L < R) cerr << *L << " \n"[L+1==R], ++L; }
void kout(){ cerr << endl; }
template<class T1, class ...T2> void kout(T1 a, T2 ...e) { cerr << a << ' ', kout(e...); }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 300010;
int n, a[MAX_N], on[MAX_N], res[MAX_N], nxt[MAX_N];
map<int,int> global_cnt;
void putin(int v, int d) {
	if ((global_cnt[v] += d) == 0)
		global_cnt.erase(v);
}
int qry() { return global_cnt.empty() ? 0 :  global_cnt.rbegin()->first; }
int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for (int i = 1;i <= n;++i)
		cin >> a[i];

	for (int i = 1;i <= n;++i) {
		if (a[i] > 0) {
			putin(a[i], 1);
			nxt[i] = -1;
		}
		else {
			int v = -a[i];
			for (int j = i - 1;j > 0;--j) if (on[j] && a[i] < a[j]) {
				nxt[i] = j;
				for (int x = j; x != -1 ;x = nxt[x]) {
					on[x] ^= 1;
					if (a[x] > 0) putin(a[x], on[x] ? 1 : -1);
				}
				break;
			}
		}
		res[i] = qry();
		on[i] = true;
	}
	for (int i = 1;i <= n;++i)
		cout << res[i] << '\n';

}

Compilation message

edi.cpp: In function 'int32_t main()':
edi.cpp:48:8: warning: unused variable 'v' [-Wunused-variable]
   48 |    int v = -a[i];
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 18 ms 504 KB Output is correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 337 ms 8812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 131 ms 8148 KB Output is correct
2 Correct 2989 ms 9608 KB Output is correct
3 Execution timed out 3031 ms 3648 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 18 ms 504 KB Output is correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Halted 0 ms 0 KB -