QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#567940 | #9313. Make Max | psycho_009 | Compile Error | / | / | C++14 | 1.7kb | 2024-09-16 14:45:26 | 2024-09-16 14:45:27 |
Judging History
This is the latest submission verdict.
- [2024-09-18 15:56:24]
- hack成功,自动添加数据
- (/hack/836)
- [2024-09-16 14:45:27]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-09-16 14:45:26]
- Submitted
answer
#include<iostream>
#include<algorithm>
#include <cstring>
#include <queue>
using namespace std;
const int N = 200010, M = 400010;
const LL INF = 9223372036854775808;
typedef long long LL;
int h[M], ne[M], e[M], idx;
int r[N], l[N];
LL stack1[N], q[N];
bool st[N];
int dist[N];
LL n, maxv;
void add(int a, int b) {
e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
}
void spfa() {
queue<int> heap;
memset(st, 0, sizeof st);
memset(dist, 0x3f, sizeof dist);
for (int i = 1; i <= n; i ++ )
if (q[i] == maxv) {
heap.push(i);
dist[i] = 0;
}
while(heap.size()) {
auto t = heap.front();
heap.pop();
st[t] = false;
for (int i = h[t]; i != -1; i = ne[i]) {
int j = e[i];
if (dist[j] > dist[t] + 1) {
dist[j] = dist[t] + 1;
if (!st[j]) {
st[j] = true;
heap.push(j);
}
}
}
}
}
void solve() {
memset(h, -1, sizeof h);
cin >> n;
maxv = 0;
q[0] = INF, q[n + 1] = INF;
for (int i = 1; i <= n; i ++ ) {
cin >> q[i];
maxv = max(maxv, q[i]);
}
int hh = -1;
// 左边第一个的元素
for (int i = 1; i <= n; i ++ ) {
while(hh >= 0 && q[stack1[hh]] <= q[i]) hh --;
r[i] = stack1[hh];
stack1[++ hh] = i;
}
hh = -1;
// 右边第一个比它大
for (int i = n; i > 0; i -- ) {
while (hh >= 0 && q[stack1[hh]] <= q[i]) hh --;
l[i] = stack1[hh];
stack1[++ hh] = i;
}
for (int i = 1; i <= n; i ++ ) {
if (q[i] != maxv) {
int id = q[r[i]] < q[l[i]] ? r[i] : l[i];
add(id, i);
}
}
spfa();
LL res = 0;
for (int i = 1; i <= n; i ++ ) res += dist[i];
cout << res << endl;
}
int main() {
int T;
cin >> T;
while (T -- )
solve();
return 0;
}
Details
answer.code:8:16: warning: integer constant is so large that it is unsigned 8 | const LL INF = 9223372036854775808; | ^~~~~~~~~~~~~~~~~~~ answer.code:8:7: error: ‘LL’ does not name a type 8 | const LL INF = 9223372036854775808; | ^~ answer.code: In function ‘void solve()’: answer.code:57:16: error: ‘INF’ was not declared in this scope 57 | q[0] = INF, q[n + 1] = INF; | ^~~